@@ -374,56 +374,94 @@ layer("GitLabPullRequestCli.layer", (it) => {
374374 } ) ,
375375 ) ;
376376
377- it . effect ( "merges immediately rather than leaving auto-merge armed" , ( ) =>
378- Effect . gen ( function * ( ) {
379- mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( "" ) ) ) ;
380- const cli = yield * GitLabPullRequestCli . GitLabPullRequestCli ;
381-
382- yield * cli . runMergeRequestAction ( {
383- cwd : "/w" ,
384- repository : "acme/web" ,
385- number : 7 ,
386- action : "merge" ,
387- mergeMethod : "squash" ,
388- } ) ;
389-
390- expect ( argsOfCall ( 0 ) ) . toEqual ( [
391- "mr" ,
392- "merge" ,
393- "7" ,
394- "--repo" ,
395- "acme/web" ,
396- "--auto-merge=false" ,
397- "--yes" ,
398- "--squash" ,
399- ] ) ;
400- } ) ,
377+ it . effect . each ( [
378+ { action : "merge" , autoMerge : "false" } ,
379+ { action : "enable-auto-merge" , autoMerge : "true" } ,
380+ ] as const ) (
381+ "$action succeeds on a project requiring the current source SHA" ,
382+ ( { action, autoMerge } ) =>
383+ Effect . gen ( function * ( ) {
384+ const cli = yield * GitLabPullRequestCli . GitLabPullRequestCli ;
385+
386+ for ( const headSha of [ "first-head" , "updated-head" ] ) {
387+ mockedExecute . mockImplementation ( ( { cwd, args } ) => {
388+ if ( args [ 0 ] === "api" ) {
389+ return Effect . succeed (
390+ output (
391+ mergeRequestJson ( {
392+ diff_refs : { base_sha : "base" , head_sha : headSha , start_sha : "start" } ,
393+ } ) ,
394+ ) ,
395+ ) ;
396+ }
397+ if ( args [ args . indexOf ( "--sha" ) + 1 ] !== headSha ) {
398+ return Effect . fail (
399+ new GitLabCli . GitLabCliCommandError ( {
400+ operation : "execute" ,
401+ command : "glab" ,
402+ cwd,
403+ cause : new Error ( "SHA must match the current source branch HEAD" ) ,
404+ } ) ,
405+ ) ;
406+ }
407+ return Effect . succeed ( output ( "" ) ) ;
408+ } ) ;
409+
410+ yield * cli . runMergeRequestAction ( {
411+ cwd : "/w" ,
412+ repository : "acme/web" ,
413+ number : 7 ,
414+ action,
415+ mergeMethod : "squash" ,
416+ } ) ;
417+
418+ expect ( mockedExecute . mock . calls . slice ( - 2 ) . map ( ( [ input ] ) => input . args ) ) . toEqual ( [
419+ [ "api" , "projects/acme%2Fweb/merge_requests/7" ] ,
420+ [
421+ "mr" ,
422+ "merge" ,
423+ "7" ,
424+ "--repo" ,
425+ "acme/web" ,
426+ `--auto-merge=${ autoMerge } ` ,
427+ "--yes" ,
428+ "--squash" ,
429+ "--sha" ,
430+ headSha ,
431+ ] ,
432+ ] ) ;
433+ }
434+ expect ( mockedExecute ) . toHaveBeenCalledTimes ( 4 ) ;
435+ } ) ,
401436 ) ;
402437
403- it . effect ( "arms auto-merge with the same strategy a merge would have used" , ( ) =>
404- Effect . gen ( function * ( ) {
405- mockedExecute . mockReturnValueOnce ( Effect . succeed ( output ( "" ) ) ) ;
406- const cli = yield * GitLabPullRequestCli . GitLabPullRequestCli ;
407-
408- yield * cli . runMergeRequestAction ( {
409- cwd : "/w" ,
410- repository : "acme/web" ,
411- number : 7 ,
412- action : "enable-auto-merge" ,
413- mergeMethod : "squash" ,
414- } ) ;
438+ it . effect . each ( [ "merge" , "enable-auto-merge" ] as const ) (
439+ "does not run %s when GitLab has no diff revisions" ,
440+ ( action ) =>
441+ Effect . gen ( function * ( ) {
442+ mockedExecute . mockReturnValue (
443+ Effect . succeed ( output ( mergeRequestJson ( { diff_refs : null } ) ) ) ,
444+ ) ;
445+ const cli = yield * GitLabPullRequestCli . GitLabPullRequestCli ;
446+
447+ const result = yield * Effect . result (
448+ cli . runMergeRequestAction ( {
449+ cwd : "/w" ,
450+ repository : "acme/web" ,
451+ number : 7 ,
452+ action,
453+ mergeMethod : "squash" ,
454+ } ) ,
455+ ) ;
415456
416- expect ( argsOfCall ( 0 ) ) . toEqual ( [
417- "mr" ,
418- "merge" ,
419- "7" ,
420- "--repo" ,
421- "acme/web" ,
422- "--auto-merge=true" ,
423- "--yes" ,
424- "--squash" ,
425- ] ) ;
426- } ) ,
457+ expect ( mockedExecute . mock . calls . map ( ( [ input ] ) => input . args ) ) . toEqual ( [
458+ [ "api" , "projects/acme%2Fweb/merge_requests/7" ] ,
459+ ] ) ;
460+ expect ( result ) . toMatchObject ( {
461+ _tag : "Failure" ,
462+ failure : { _tag : "GitLabDiffRefsUnavailableError" } ,
463+ } ) ;
464+ } ) ,
427465 ) ;
428466
429467 it . effect ( "cancels an armed auto-merge through the API glab has no flag for" , ( ) =>
0 commit comments