@@ -39,17 +39,23 @@ func testGit(t *testing.T, u *url.URL) {
39
39
40
40
u .Path = baseAPITestContext .GitPath ()
41
41
42
+ forkedUserCtx := NewAPITestContext (t , "user4" , "repo1" )
43
+
42
44
t .Run ("HTTP" , func (t * testing.T ) {
43
45
PrintCurrentTest (t )
46
+ ensureAnonymousClone (t , u )
44
47
httpContext := baseAPITestContext
45
48
httpContext .Reponame = "repo-tmp-17"
49
+ forkedUserCtx .Reponame = httpContext .Reponame
46
50
47
51
dstPath , err := ioutil .TempDir ("" , httpContext .Reponame )
48
52
assert .NoError (t , err )
49
53
defer os .RemoveAll (dstPath )
50
54
51
- t .Run ("CreateRepo" , doAPICreateRepository (httpContext , false ))
52
- ensureAnonymousClone (t , u )
55
+ t .Run ("CreateRepoInDifferentUser" , doAPICreateRepository (forkedUserCtx , false ))
56
+ t .Run ("AddUserAsCollaborator" , doAPIAddCollaborator (forkedUserCtx , httpContext .Username , models .AccessModeRead ))
57
+
58
+ t .Run ("ForkFromDifferentUser" , doAPIForkRepository (httpContext , forkedUserCtx .Username ))
53
59
54
60
u .Path = httpContext .GitPath ()
55
61
u .User = url .UserPassword (username , userPassword )
@@ -62,12 +68,23 @@ func testGit(t *testing.T, u *url.URL) {
62
68
mediaTest (t , & httpContext , little , big , littleLFS , bigLFS )
63
69
64
70
t .Run ("BranchProtectMerge" , doBranchProtectPRMerge (& httpContext , dstPath ))
71
+ t .Run ("MergeFork" , func (t * testing.T ) {
72
+ t .Run ("CreatePRAndMerge" , doMergeFork (httpContext , forkedUserCtx , "master" , httpContext .Username + ":master" ))
73
+ t .Run ("DeleteRepository" , doAPIDeleteRepository (httpContext ))
74
+ rawTest (t , & forkedUserCtx , little , big , littleLFS , bigLFS )
75
+ mediaTest (t , & forkedUserCtx , little , big , littleLFS , bigLFS )
76
+ })
65
77
})
66
78
t .Run ("SSH" , func (t * testing.T ) {
67
79
PrintCurrentTest (t )
68
80
sshContext := baseAPITestContext
69
81
sshContext .Reponame = "repo-tmp-18"
70
82
keyname := "my-testing-key"
83
+ forkedUserCtx .Reponame = sshContext .Reponame
84
+ t .Run ("CreateRepoInDifferentUser" , doAPICreateRepository (forkedUserCtx , false ))
85
+ t .Run ("AddUserAsCollaborator" , doAPIAddCollaborator (forkedUserCtx , sshContext .Username , models .AccessModeRead ))
86
+ t .Run ("ForkFromDifferentUser" , doAPIForkRepository (sshContext , forkedUserCtx .Username ))
87
+
71
88
//Setup key the user ssh key
72
89
withKeyFile (t , keyname , func (keyFile string ) {
73
90
t .Run ("CreateUserKey" , doAPICreateUserKey (sshContext , "test-key" , keyFile ))
@@ -81,8 +98,6 @@ func testGit(t *testing.T, u *url.URL) {
81
98
assert .NoError (t , err )
82
99
defer os .RemoveAll (dstPath )
83
100
84
- t .Run ("CreateRepo" , doAPICreateRepository (sshContext , false ))
85
-
86
101
t .Run ("Clone" , doGitClone (dstPath , sshURL ))
87
102
88
103
little , big := standardCommitAndPushTest (t , dstPath )
@@ -91,8 +106,13 @@ func testGit(t *testing.T, u *url.URL) {
91
106
mediaTest (t , & sshContext , little , big , littleLFS , bigLFS )
92
107
93
108
t .Run ("BranchProtectMerge" , doBranchProtectPRMerge (& sshContext , dstPath ))
109
+ t .Run ("MergeFork" , func (t * testing.T ) {
110
+ t .Run ("CreatePRAndMerge" , doMergeFork (sshContext , forkedUserCtx , "master" , sshContext .Username + ":master" ))
111
+ t .Run ("DeleteRepository" , doAPIDeleteRepository (sshContext ))
112
+ rawTest (t , & forkedUserCtx , little , big , littleLFS , bigLFS )
113
+ mediaTest (t , & forkedUserCtx , little , big , littleLFS , bigLFS )
114
+ })
94
115
})
95
-
96
116
})
97
117
}
98
118
@@ -341,3 +361,16 @@ func doProtectBranch(ctx APITestContext, branch string, userToWhitelist string)
341
361
assert .EqualValues (t , "success%3DBranch%2Bprotection%2Bfor%2Bbranch%2B%2527" + url .QueryEscape (branch )+ "%2527%2Bhas%2Bbeen%2Bupdated." , flashCookie .Value )
342
362
}
343
363
}
364
+
365
+ func doMergeFork (ctx , baseCtx APITestContext , baseBranch , headBranch string ) func (t * testing.T ) {
366
+ return func (t * testing.T ) {
367
+ var pr api.PullRequest
368
+ var err error
369
+ t .Run ("CreatePullRequest" , func (t * testing.T ) {
370
+ pr , err = doAPICreatePullRequest (ctx , baseCtx .Username , baseCtx .Reponame , baseBranch , headBranch )(t )
371
+ assert .NoError (t , err )
372
+ })
373
+ t .Run ("MergePR" , doAPIMergePullRequest (baseCtx , baseCtx .Username , baseCtx .Reponame , pr .Index ))
374
+
375
+ }
376
+ }
0 commit comments