@@ -265,29 +265,31 @@ export const acceptMergeRequest = async (gitlabApi: GitlabApi, mergeRequest: Mer
265265
266266 if ( currentPipeline === null || currentPipeline . sha !== mergeRequestInfo . sha ) {
267267 const pipelines = await gitlabApi . getMergeRequestPipelines ( mergeRequestInfo . project_id , mergeRequestInfo . iid ) ;
268- const currentPipelineCandidate = pipelines . find ( ( pipeline ) => pipeline . sha === mergeRequestInfo . sha ) ;
269-
270- if ( currentPipelineCandidate === undefined ) {
271- const message = mergeRequestInfo . pipeline === null
272- ? `[MR][${ mergeRequestInfo . iid } ] Merge request can't be merged. Pipeline does not exist`
273- : `[MR][${ mergeRequestInfo . iid } ] Merge request can't be merged. The latest pipeline is not executed on the latest commit` ;
274- console . log ( message ) ;
275-
276- if ( numberOfPipelineValidationRetries > 0 ) {
277- numberOfPipelineValidationRetries -- ;
278- await Promise . all ( tasks ) ;
279- continue ;
268+ if ( pipelines . length > 0 ) {
269+ const currentPipelineCandidate = pipelines . find ( ( pipeline ) => pipeline . sha === mergeRequestInfo . sha ) ;
270+
271+ if ( currentPipelineCandidate === undefined ) {
272+ const message = mergeRequestInfo . pipeline === null
273+ ? `[MR][${ mergeRequestInfo . iid } ] Merge request can't be merged. Pipeline does not exist`
274+ : `[MR][${ mergeRequestInfo . iid } ] Merge request can't be merged. The latest pipeline is not executed on the latest commit` ;
275+ console . log ( message ) ;
276+
277+ if ( numberOfPipelineValidationRetries > 0 ) {
278+ numberOfPipelineValidationRetries -- ;
279+ await Promise . all ( tasks ) ;
280+ continue ;
281+ }
282+
283+ return {
284+ kind : AcceptMergeRequestResultKind . InvalidPipeline ,
285+ mergeRequestInfo,
286+ user,
287+ pipeline : mergeRequestInfo . pipeline ,
288+ } ;
280289 }
281290
282- return {
283- kind : AcceptMergeRequestResultKind . InvalidPipeline ,
284- mergeRequestInfo,
285- user,
286- pipeline : mergeRequestInfo . pipeline ,
287- } ;
291+ currentPipeline = currentPipelineCandidate ;
288292 }
289-
290- currentPipeline = currentPipelineCandidate ;
291293 }
292294
293295 if ( currentPipeline !== null ) {
0 commit comments