@@ -10,6 +10,7 @@ import (
1010 "strings"
1111 "testing"
1212
13+ "github.com/cli/cli/context"
1314 "github.com/cli/cli/git"
1415 "github.com/cli/cli/test"
1516 "github.com/cli/cli/utils"
@@ -131,3 +132,85 @@ Creating pull request for feature into master in OWNER/REPO
131132
132133` )
133134}
135+ func TestPRCreate_cross_repo_same_branch (t * testing.T ) {
136+ ctx := context .NewBlank ()
137+ ctx .SetBranch ("default" )
138+ ctx .SetRemotes (map [string ]string {
139+ "origin" : "OWNER/REPO" ,
140+ "fork" : "MYSELF/REPO" ,
141+ })
142+ initContext = func () context.Context {
143+ return ctx
144+ }
145+ http := initFakeHTTP ()
146+ http .StubResponse (200 , bytes .NewBufferString (`
147+ { "data": { "repo_000": {
148+ "id": "REPOID0",
149+ "name": "REPO",
150+ "owner": {"login": "OWNER"},
151+ "defaultBranchRef": {
152+ "name": "default",
153+ "target": {"oid": "deadbeef"}
154+ },
155+ "viewerPermission": "READ"
156+ },
157+ "repo_001" : {
158+ "parent": {
159+ "id": "REPOID0",
160+ "name": "REPO",
161+ "owner": {"login": "OWNER"},
162+ "defaultBranchRef": {
163+ "name": "default",
164+ "target": {"oid": "deadbeef"}
165+ },
166+ "viewerPermission": "READ"
167+ },
168+ "id": "REPOID1",
169+ "name": "REPO",
170+ "owner": {"login": "MYSELF"},
171+ "defaultBranchRef": {
172+ "name": "default",
173+ "target": {"oid": "deadbeef"}
174+ },
175+ "viewerPermission": "WRITE"
176+ } } }
177+ ` ))
178+ http .StubResponse (200 , bytes .NewBufferString (`
179+ { "data": { "createPullRequest": { "pullRequest": {
180+ "URL": "https://github.com/OWNER/REPO/pull/12"
181+ } } } }
182+ ` ))
183+
184+ origGitCommand := git .GitCommand
185+ git .GitCommand = test .StubExecCommand ("TestPrCreateHelperProcess" , "clean" )
186+ defer func () {
187+ git .GitCommand = origGitCommand
188+ }()
189+
190+ output , err := RunCommand (prCreateCmd , `pr create -t "cross repo" -b "same branch"` )
191+ eq (t , err , nil )
192+
193+ bodyBytes , _ := ioutil .ReadAll (http .Requests [1 ].Body )
194+ reqBody := struct {
195+ Variables struct {
196+ Input struct {
197+ RepositoryID string
198+ Title string
199+ Body string
200+ BaseRefName string
201+ HeadRefName string
202+ }
203+ }
204+ }{}
205+ json .Unmarshal (bodyBytes , & reqBody )
206+
207+ eq (t , reqBody .Variables .Input .RepositoryID , "REPOID0" )
208+ eq (t , reqBody .Variables .Input .Title , "cross repo" )
209+ eq (t , reqBody .Variables .Input .Body , "same branch" )
210+ eq (t , reqBody .Variables .Input .BaseRefName , "default" )
211+ eq (t , reqBody .Variables .Input .HeadRefName , "MYSELF:default" )
212+
213+ eq (t , output .String (), "https://github.com/OWNER/REPO/pull/12\n " )
214+
215+ // goal: only care that gql is formatted properly
216+ }
0 commit comments