@@ -60,26 +60,50 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo string, toSel
60
60
return resp
61
61
}
62
62
63
- func testPullCreateDirectly (t * testing.T , session * TestSession , baseRepoOwner , baseRepoName , baseBranch , headRepoOwner , headRepoName , headBranch , title string ) * httptest.ResponseRecorder {
64
- headCompare := headBranch
65
- if headRepoOwner != "" {
66
- if headRepoName != "" {
67
- headCompare = fmt .Sprintf ("%s/%s:%s" , headRepoOwner , headRepoName , headBranch )
63
+ type createPullRequestOptions struct {
64
+ BaseRepoOwner string
65
+ BaseRepoName string
66
+ BaseBranch string
67
+ HeadRepoOwner string
68
+ HeadRepoName string
69
+ HeadBranch string
70
+ Title string
71
+ ReviewerIDs string // comma-separated list of user IDs
72
+ }
73
+
74
+ func (opts createPullRequestOptions ) IsValid () bool {
75
+ return opts .BaseRepoOwner != "" && opts .BaseRepoName != "" && opts .BaseBranch != "" &&
76
+ opts .HeadBranch != "" && opts .Title != ""
77
+ }
78
+
79
+ func testPullCreateDirectly (t * testing.T , session * TestSession , opts createPullRequestOptions ) * httptest.ResponseRecorder {
80
+ if ! opts .IsValid () {
81
+ t .Fatal ("Invalid pull request options" )
82
+ }
83
+
84
+ headCompare := opts .HeadBranch
85
+ if opts .HeadRepoOwner != "" {
86
+ if opts .HeadRepoName != "" {
87
+ headCompare = fmt .Sprintf ("%s/%s:%s" , opts .HeadRepoOwner , opts .HeadRepoName , opts .HeadBranch )
68
88
} else {
69
- headCompare = fmt .Sprintf ("%s:%s" , headRepoOwner , headBranch )
89
+ headCompare = fmt .Sprintf ("%s:%s" , opts . HeadRepoOwner , opts . HeadBranch )
70
90
}
71
91
}
72
- req := NewRequest (t , "GET" , fmt .Sprintf ("/%s/%s/compare/%s...%s" , baseRepoOwner , baseRepoName , baseBranch , headCompare ))
92
+ req := NewRequest (t , "GET" , fmt .Sprintf ("/%s/%s/compare/%s...%s" , opts . BaseRepoOwner , opts . BaseRepoName , opts . BaseBranch , headCompare ))
73
93
resp := session .MakeRequest (t , req , http .StatusOK )
74
94
75
95
// Submit the form for creating the pull
76
96
htmlDoc := NewHTMLParser (t , resp .Body )
77
97
link , exists := htmlDoc .doc .Find ("form.ui.form" ).Attr ("action" )
78
98
assert .True (t , exists , "The template has changed" )
79
- req = NewRequestWithValues ( t , "POST" , link , map [string ]string {
99
+ params := map [string ]string {
80
100
"_csrf" : htmlDoc .GetCSRF (),
81
- "title" : title ,
82
- })
101
+ "title" : opts .Title ,
102
+ }
103
+ if opts .ReviewerIDs != "" {
104
+ params ["reviewer_ids" ] = opts .ReviewerIDs
105
+ }
106
+ req = NewRequestWithValues (t , "POST" , link , params )
83
107
resp = session .MakeRequest (t , req , http .StatusOK )
84
108
return resp
85
109
}
@@ -246,7 +270,15 @@ func TestPullCreatePrFromBaseToFork(t *testing.T) {
246
270
testEditFile (t , sessionBase , "user2" , "repo1" , "master" , "README.md" , "Hello, World (Edited)\n " )
247
271
248
272
// Create a PR
249
- resp := testPullCreateDirectly (t , sessionFork , "user1" , "repo1" , "master" , "user2" , "repo1" , "master" , "This is a pull title" )
273
+ resp := testPullCreateDirectly (t , sessionFork , createPullRequestOptions {
274
+ BaseRepoOwner : "user1" ,
275
+ BaseRepoName : "repo1" ,
276
+ BaseBranch : "master" ,
277
+ HeadRepoOwner : "user2" ,
278
+ HeadRepoName : "repo1" ,
279
+ HeadBranch : "master" ,
280
+ Title : "This is a pull title" ,
281
+ })
250
282
// check the redirected URL
251
283
url := test .RedirectURL (resp )
252
284
assert .Regexp (t , "^/user1/repo1/pulls/[0-9]*$" , url )
0 commit comments