@@ -513,7 +513,9 @@ export const runAcceptingMergeRequest = async (
513513
514514 if ( mergeRequestInfo . diverged_commits_count > 0 ) {
515515 if ( ! mergeRequestInfo . rebase_in_progress && mergeRequestInfo . merge_error !== null ) {
516- console . log ( `[MR][${ mergeRequestInfo . iid } ] Merge error after rebase` ) ;
516+ console . log (
517+ `[MR][${ mergeRequestInfo . iid } ] Merge error after rebase: ${ mergeRequestInfo . merge_error } ` ,
518+ ) ;
517519 return {
518520 kind : AcceptMergeRequestResultKind . CanNotBeMerged ,
519521 mergeRequestInfo,
@@ -620,8 +622,11 @@ export const runAcceptingMergeRequest = async (
620622 } ;
621623 }
622624
623- const currentPipeline = await resolveCurrentPipeline ( gitlabApi , user , mergeRequestInfo ) ;
624- if ( currentPipeline === false ) {
625+ const currentPipeline : MergeRequestPipeline | null = mergeRequestInfo . head_pipeline ;
626+ if ( currentPipeline === null ) {
627+ console . log (
628+ `[MR][${ mergeRequestInfo . iid } ] Merge request can't be merged. Pipeline does not exist` ,
629+ ) ;
625630 return {
626631 kind : AcceptMergeRequestResultKind . InvalidPipeline ,
627632 mergeRequestInfo,
@@ -630,78 +635,74 @@ export const runAcceptingMergeRequest = async (
630635 } ;
631636 }
632637
633- if ( currentPipeline !== null ) {
634- if ( startingOrInProgressPipelineStatuses . includes ( currentPipeline . status ) ) {
635- if ( ! containsLabel ( mergeRequestInfo . labels , BotLabels . WaitingForPipeline ) ) {
636- await setBotLabels ( gitlabApi , mergeRequestInfo , [
637- BotLabels . Accepting ,
638- BotLabels . WaitingForPipeline ,
639- ] ) ;
640- }
641-
642- console . log (
643- `[MR][${ mergeRequestInfo . iid } ] Waiting for CI. Current status: ${ currentPipeline . status } ` ,
644- ) ;
645- job . updateStatus ( JobStatus . WAITING_FOR_CI ) ;
646- return ;
638+ if ( startingOrInProgressPipelineStatuses . includes ( currentPipeline . status ) ) {
639+ if ( ! containsLabel ( mergeRequestInfo . labels , BotLabels . WaitingForPipeline ) ) {
640+ await setBotLabels ( gitlabApi , mergeRequestInfo , [
641+ BotLabels . Accepting ,
642+ BotLabels . WaitingForPipeline ,
643+ ] ) ;
647644 }
648645
649- if ( currentPipeline . status === PipelineStatus . Failed ) {
646+ console . log (
647+ `[MR][${ mergeRequestInfo . iid } ] Waiting for CI. Current status: ${ currentPipeline . status } ` ,
648+ ) ;
649+ job . updateStatus ( JobStatus . WAITING_FOR_CI ) ;
650+ return ;
651+ }
652+
653+ if ( currentPipeline . status === PipelineStatus . Failed ) {
654+ return {
655+ kind : AcceptMergeRequestResultKind . FailedPipeline ,
656+ mergeRequestInfo,
657+ user,
658+ pipeline : currentPipeline ,
659+ } ;
660+ }
661+
662+ if ( [ PipelineStatus . Manual , PipelineStatus . Canceled ] . includes ( currentPipeline . status ) ) {
663+ if ( ! config . AUTORUN_MANUAL_BLOCKING_JOBS ) {
650664 return {
651- kind : AcceptMergeRequestResultKind . FailedPipeline ,
665+ kind : AcceptMergeRequestResultKind . WaitingPipeline ,
652666 mergeRequestInfo,
653667 user,
654668 pipeline : currentPipeline ,
655669 } ;
656670 }
657671
658- if ( [ PipelineStatus . Manual , PipelineStatus . Canceled ] . includes ( currentPipeline . status ) ) {
659- if ( ! config . AUTORUN_MANUAL_BLOCKING_JOBS ) {
660- return {
661- kind : AcceptMergeRequestResultKind . WaitingPipeline ,
662- mergeRequestInfo,
663- user,
664- pipeline : currentPipeline ,
665- } ;
666- }
672+ const jobs = uniqueNamedJobsByDate (
673+ await gitlabApi . getPipelineJobs ( mergeRequestInfo . project_id , currentPipeline . id ) ,
674+ ) ;
667675
668- const jobs = uniqueNamedJobsByDate (
669- await gitlabApi . getPipelineJobs ( mergeRequestInfo . project_id , currentPipeline . id ) ,
670- ) ;
676+ const manualJobsToRun = jobs . filter (
677+ ( job ) => PipelineJobStatus . Manual === job . status && ! job . allow_failure ,
678+ ) ;
679+ const canceledJobsToRun = jobs . filter (
680+ ( job ) => PipelineJobStatus . Canceled === job . status && ! job . allow_failure ,
681+ ) ;
671682
672- const manualJobsToRun = jobs . filter (
673- ( job ) => PipelineJobStatus . Manual === job . status && ! job . allow_failure ,
683+ if ( manualJobsToRun . length > 0 || canceledJobsToRun . length > 0 ) {
684+ console . log (
685+ `[MR][${ mergeRequestInfo . iid } ] there are some blocking manual or canceled. triggering again` ,
674686 ) ;
675- const canceledJobsToRun = jobs . filter (
676- ( job ) => PipelineJobStatus . Canceled === job . status && ! job . allow_failure ,
687+ job . updateStatus ( JobStatus . WAITING_FOR_CI ) ;
688+ await Promise . all (
689+ manualJobsToRun . map ( ( job ) => gitlabApi . runJob ( mergeRequestInfo . project_id , job . id ) ) ,
677690 ) ;
678-
679- if ( manualJobsToRun . length > 0 || canceledJobsToRun . length > 0 ) {
680- console . log (
681- `[MR][${ mergeRequestInfo . iid } ] there are some blocking manual or canceled. triggering again` ,
682- ) ;
683- job . updateStatus ( JobStatus . WAITING_FOR_CI ) ;
684- await Promise . all (
685- manualJobsToRun . map ( ( job ) =>
686- gitlabApi . runJob ( mergeRequestInfo . project_id , job . id ) ,
687- ) ,
688- ) ;
689- await Promise . all (
690- canceledJobsToRun . map ( ( job ) =>
691- gitlabApi . retryJob ( mergeRequestInfo . project_id , job . id ) ,
692- ) ,
693- ) ;
694- return ;
695- }
691+ await Promise . all (
692+ canceledJobsToRun . map ( ( job ) =>
693+ gitlabApi . retryJob ( mergeRequestInfo . project_id , job . id ) ,
694+ ) ,
695+ ) ;
696+ return ;
696697 }
698+ }
697699
698- if (
699- currentPipeline . status !== PipelineStatus . Success &&
700- currentPipeline . status !== PipelineStatus . Skipped &&
701- currentPipeline . status !== PipelineStatus . Created
702- ) {
703- throw new Error ( `Unexpected pipeline status: ${ currentPipeline . status } ` ) ;
704- }
700+ if (
701+ currentPipeline . status !== PipelineStatus . Success &&
702+ currentPipeline . status !== PipelineStatus . Skipped &&
703+ currentPipeline . status !== PipelineStatus . Created
704+ ) {
705+ throw new Error ( `Unexpected pipeline status: ${ currentPipeline . status } ` ) ;
705706 }
706707
707708 if ( containsLabel ( mergeRequestInfo . labels , BotLabels . WaitingForPipeline ) ) {
0 commit comments