Skip to content

Commit

Permalink
Try to resolve problem with manual job triggering (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
pepakriz authored Mar 24, 2024
1 parent 49c63d8 commit 9841839
Showing 1 changed file with 2 additions and 36 deletions.
38 changes: 2 additions & 36 deletions server/src/MergeRequestAcceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,40 +430,6 @@ export const acceptMergeRequest = async (
};
};

const resolveCurrentPipeline = async (
gitlabApi: GitlabApi,
user: User,
mergeRequestInfo: MergeRequestInfo,
): Promise<MergeRequestPipeline | null | false> => {
let currentPipeline: MergeRequestPipeline | null = mergeRequestInfo.head_pipeline;

if (currentPipeline === null || currentPipeline.sha !== mergeRequestInfo.sha) {
const pipelines = await gitlabApi.getMergeRequestPipelines(
mergeRequestInfo.project_id,
mergeRequestInfo.iid,
);
if (pipelines.length > 0) {
const currentPipelineCandidate = pipelines.find(
(pipeline) => pipeline.sha === mergeRequestInfo.sha,
);

if (currentPipelineCandidate === undefined) {
const message =
mergeRequestInfo.head_pipeline === null
? `[MR][${mergeRequestInfo.iid}] Merge request can't be merged. Pipeline does not exist`
: `[MR][${mergeRequestInfo.iid}] Merge request can't be merged. The latest pipeline is not executed on the latest commit`;
console.log(message);

return false;
}

currentPipeline = currentPipelineCandidate;
}
}

return currentPipeline;
};

export const runAcceptingMergeRequest = async (
job: Job,
gitlabApi: GitlabApi,
Expand Down Expand Up @@ -552,8 +518,8 @@ export const runAcceptingMergeRequest = async (
...state,
checkManualJobs: false,
}));
const currentPipeline = await resolveCurrentPipeline(gitlabApi, user, mergeRequestInfo);
if (currentPipeline !== null && currentPipeline !== false) {
const currentPipeline = mergeRequestInfo.head_pipeline;
if (currentPipeline !== null) {
const jobs = uniqueNamedJobsByDate(
await gitlabApi.getPipelineJobs(mergeRequestInfo.project_id, currentPipeline.id),
);
Expand Down

0 comments on commit 9841839

Please sign in to comment.