@@ -262,10 +262,26 @@ func Test_SyncRun(t *testing.T) {
262262 wantStdout : "✓ Synced the \" trunk\" branch from OWNER/REPO to local repository\n " ,
263263 },
264264 {
265- name : "sync remote fork with parent - tty" ,
265+ name : "sync remote fork with parent with new api - tty" ,
266266 tty : true ,
267267 opts : & SyncOptions {
268- DestArg : "OWNER/REPO-FORK" ,
268+ DestArg : "FORKOWNER/REPO-FORK" ,
269+ },
270+ httpStubs : func (reg * httpmock.Registry ) {
271+ reg .Register (
272+ httpmock .GraphQL (`query RepositoryInfo\b` ),
273+ httpmock .StringResponse (`{"data":{"repository":{"defaultBranchRef":{"name": "trunk"}}}}` ))
274+ reg .Register (
275+ httpmock .REST ("POST" , "repos/FORKOWNER/REPO-FORK/merge-upstream" ),
276+ httpmock .StatusStringResponse (200 , `{"base_branch": "OWNER:trunk"}` ))
277+ },
278+ wantStdout : "✓ Synced the \" FORKOWNER:trunk\" branch from \" OWNER:trunk\" \n " ,
279+ },
280+ {
281+ name : "sync remote fork with parent using api fallback - tty" ,
282+ tty : true ,
283+ opts : & SyncOptions {
284+ DestArg : "FORKOWNER/REPO-FORK" ,
269285 },
270286 httpStubs : func (reg * httpmock.Registry ) {
271287 reg .Register (
@@ -274,34 +290,31 @@ func Test_SyncRun(t *testing.T) {
274290 reg .Register (
275291 httpmock .GraphQL (`query RepositoryInfo\b` ),
276292 httpmock .StringResponse (`{"data":{"repository":{"defaultBranchRef":{"name": "trunk"}}}}` ))
293+ reg .Register (
294+ httpmock .REST ("POST" , "repos/FORKOWNER/REPO-FORK/merge-upstream" ),
295+ httpmock .StatusStringResponse (404 , `{}` ))
277296 reg .Register (
278297 httpmock .REST ("GET" , "repos/OWNER/REPO/git/refs/heads/trunk" ),
279298 httpmock .StringResponse (`{"object":{"sha":"0xDEADBEEF"}}` ))
280299 reg .Register (
281- httpmock .REST ("PATCH" , "repos/OWNER /REPO-FORK/git/refs/heads/trunk" ),
300+ httpmock .REST ("PATCH" , "repos/FORKOWNER /REPO-FORK/git/refs/heads/trunk" ),
282301 httpmock .StringResponse (`{}` ))
283302 },
284- wantStdout : "✓ Synced the \" trunk\" branch from OWNER/REPO to OWNER/REPO-FORK \n " ,
303+ wantStdout : "✓ Synced the \" FORKOWNER: trunk\" branch from \" OWNER:trunk \" \n " ,
285304 },
286305 {
287306 name : "sync remote fork with parent - notty" ,
288307 tty : false ,
289308 opts : & SyncOptions {
290- DestArg : "OWNER /REPO-FORK" ,
309+ DestArg : "FORKOWNER /REPO-FORK" ,
291310 },
292311 httpStubs : func (reg * httpmock.Registry ) {
293- reg .Register (
294- httpmock .GraphQL (`query RepositoryFindParent\b` ),
295- httpmock .StringResponse (`{"data":{"repository":{"parent":{"name":"REPO","owner":{"login": "OWNER"}}}}}` ))
296312 reg .Register (
297313 httpmock .GraphQL (`query RepositoryInfo\b` ),
298314 httpmock .StringResponse (`{"data":{"repository":{"defaultBranchRef":{"name": "trunk"}}}}` ))
299315 reg .Register (
300- httpmock .REST ("GET" , "repos/OWNER/REPO/git/refs/heads/trunk" ),
301- httpmock .StringResponse (`{"object":{"sha":"0xDEADBEEF"}}` ))
302- reg .Register (
303- httpmock .REST ("PATCH" , "repos/OWNER/REPO-FORK/git/refs/heads/trunk" ),
304- httpmock .StringResponse (`{}` ))
316+ httpmock .REST ("POST" , "repos/FORKOWNER/REPO-FORK/merge-upstream" ),
317+ httpmock .StatusStringResponse (200 , `{"base_branch": "OWNER:trunk"}` ))
305318 },
306319 wantStdout : "" ,
307320 },
@@ -310,11 +323,15 @@ func Test_SyncRun(t *testing.T) {
310323 tty : true ,
311324 opts : & SyncOptions {
312325 DestArg : "OWNER/REPO" ,
326+ Branch : "trunk" ,
313327 },
314328 httpStubs : func (reg * httpmock.Registry ) {
329+ reg .Register (
330+ httpmock .REST ("POST" , "repos/OWNER/REPO/merge-upstream" ),
331+ httpmock .StatusStringResponse (422 , `{"message": "Validation Failed"}` ))
315332 reg .Register (
316333 httpmock .GraphQL (`query RepositoryFindParent\b` ),
317- httpmock .StringResponse (`{"data":{"repository":{}}}` ))
334+ httpmock .StringResponse (`{"data":{"repository":{"parent":null }}}` ))
318335 },
319336 wantErr : true ,
320337 errMsg : "can't determine source repository for OWNER/REPO because repository is not fork" ,
@@ -325,19 +342,14 @@ func Test_SyncRun(t *testing.T) {
325342 opts : & SyncOptions {
326343 DestArg : "OWNER/REPO" ,
327344 SrcArg : "OWNER2/REPO2" ,
345+ Branch : "trunk" ,
328346 },
329347 httpStubs : func (reg * httpmock.Registry ) {
330348 reg .Register (
331- httpmock .GraphQL (`query RepositoryInfo\b` ),
332- httpmock .StringResponse (`{"data":{"repository":{"defaultBranchRef":{"name": "trunk"}}}}` ))
333- reg .Register (
334- httpmock .REST ("GET" , "repos/OWNER2/REPO2/git/refs/heads/trunk" ),
335- httpmock .StringResponse (`{"object":{"sha":"0xDEADBEEF"}}` ))
336- reg .Register (
337- httpmock .REST ("PATCH" , "repos/OWNER/REPO/git/refs/heads/trunk" ),
338- httpmock .StringResponse (`{}` ))
349+ httpmock .REST ("POST" , "repos/OWNER/REPO/merge-upstream" ),
350+ httpmock .StatusStringResponse (200 , `{"base_branch": "OWNER2:trunk"}` ))
339351 },
340- wantStdout : "✓ Synced the \" trunk\" branch from OWNER2/REPO2 to OWNER/REPO \n " ,
352+ wantStdout : "✓ Synced the \" OWNER: trunk\" branch from \" OWNER2:trunk \" \n " ,
341353 },
342354 {
343355 name : "sync remote fork with parent and specified branch" ,
@@ -348,16 +360,10 @@ func Test_SyncRun(t *testing.T) {
348360 },
349361 httpStubs : func (reg * httpmock.Registry ) {
350362 reg .Register (
351- httpmock .GraphQL (`query RepositoryFindParent\b` ),
352- httpmock .StringResponse (`{"data":{"repository":{"parent":{"name":"REPO","owner":{"login": "OWNER"}}}}}` ))
353- reg .Register (
354- httpmock .REST ("GET" , "repos/OWNER/REPO/git/refs/heads/test" ),
355- httpmock .StringResponse (`{"object":{"sha":"0xDEADBEEF"}}` ))
356- reg .Register (
357- httpmock .REST ("PATCH" , "repos/OWNER/REPO-FORK/git/refs/heads/test" ),
358- httpmock .StringResponse (`{}` ))
363+ httpmock .REST ("POST" , "repos/OWNER/REPO-FORK/merge-upstream" ),
364+ httpmock .StatusStringResponse (200 , `{"base_branch": "OWNER:test"}` ))
359365 },
360- wantStdout : "✓ Synced the \" test\" branch from OWNER/REPO to OWNER/REPO-FORK \n " ,
366+ wantStdout : "✓ Synced the \" OWNER: test\" branch from \" OWNER:test \" \n " ,
361367 },
362368 {
363369 name : "sync remote fork with parent and force specified" ,
@@ -373,14 +379,17 @@ func Test_SyncRun(t *testing.T) {
373379 reg .Register (
374380 httpmock .GraphQL (`query RepositoryInfo\b` ),
375381 httpmock .StringResponse (`{"data":{"repository":{"defaultBranchRef":{"name": "trunk"}}}}` ))
382+ reg .Register (
383+ httpmock .REST ("POST" , "repos/OWNER/REPO-FORK/merge-upstream" ),
384+ httpmock .StatusStringResponse (409 , `{"message": "Merge conflict"}` ))
376385 reg .Register (
377386 httpmock .REST ("GET" , "repos/OWNER/REPO/git/refs/heads/trunk" ),
378387 httpmock .StringResponse (`{"object":{"sha":"0xDEADBEEF"}}` ))
379388 reg .Register (
380389 httpmock .REST ("PATCH" , "repos/OWNER/REPO-FORK/git/refs/heads/trunk" ),
381390 httpmock .StringResponse (`{}` ))
382391 },
383- wantStdout : "✓ Synced the \" trunk\" branch from OWNER/REPO to OWNER/REPO-FORK \n " ,
392+ wantStdout : "✓ Synced the \" OWNER: trunk\" branch from \" OWNER:trunk \" \n " ,
384393 },
385394 {
386395 name : "sync remote fork with parent and not fast forward merge" ,
@@ -395,6 +404,9 @@ func Test_SyncRun(t *testing.T) {
395404 reg .Register (
396405 httpmock .GraphQL (`query RepositoryInfo\b` ),
397406 httpmock .StringResponse (`{"data":{"repository":{"defaultBranchRef":{"name": "trunk"}}}}` ))
407+ reg .Register (
408+ httpmock .REST ("POST" , "repos/OWNER/REPO-FORK/merge-upstream" ),
409+ httpmock .StatusStringResponse (409 , `{"message": "Merge conflict"}` ))
398410 reg .Register (
399411 httpmock .REST ("GET" , "repos/OWNER/REPO/git/refs/heads/trunk" ),
400412 httpmock .StringResponse (`{"object":{"sha":"0xDEADBEEF"}}` ))
@@ -454,11 +466,11 @@ func Test_SyncRun(t *testing.T) {
454466 defer reg .Verify (t )
455467 err := syncRun (tt .opts )
456468 if tt .wantErr {
457- assert .Error (t , err )
458- assert .Equal (t , tt .errMsg , err .Error ())
469+ assert .EqualError (t , err , tt .errMsg )
459470 return
471+ } else if err != nil {
472+ t .Fatalf ("syncRun() unexpected error: %v" , err )
460473 }
461- assert .NoError (t , err )
462474 assert .Equal (t , tt .wantStdout , stdout .String ())
463475 })
464476 }
0 commit comments