Skip to content

Commit

Permalink
Use mergeRequest.head_pipeline instead of mergeRequest.pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
pepakriz committed Mar 24, 2024
1 parent 812ba9b commit 474cdfa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
1 change: 0 additions & 1 deletion server/src/GitlabApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ export interface MergeRequestInfo extends MergeRequest {
base_sha: string;
head_sha: string;
};
pipeline: MergeRequestPipeline | null;
head_pipeline: MergeRequestPipeline | null;
diverged_commits_count: number;
rebase_in_progress: boolean;
Expand Down
18 changes: 3 additions & 15 deletions server/src/MergeRequestAcceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,18 +315,6 @@ export const acceptMergeRequest = async (
};
}

if (
mergeRequestInfo.pipeline !== null &&
startingOrInProgressPipelineStatuses.includes(mergeRequestInfo.pipeline.status)
) {
return {
kind: AcceptMergeRequestResultKind.PipelineInProgress,
mergeRequestInfo,
user,
pipeline: mergeRequestInfo.pipeline,
};
}

// the latest pipeline is incomplete / has failed
if (
mergeRequestInfo.head_pipeline !== null &&
Expand Down Expand Up @@ -446,7 +434,7 @@ const resolveCurrentPipeline = async (
user: User,
mergeRequestInfo: MergeRequestInfo,
): Promise<MergeRequestPipeline | null | false> => {
let currentPipeline: MergeRequestPipeline | null = mergeRequestInfo.pipeline;
let currentPipeline: MergeRequestPipeline | null = mergeRequestInfo.head_pipeline;

if (currentPipeline === null || currentPipeline.sha !== mergeRequestInfo.sha) {
const pipelines = await gitlabApi.getMergeRequestPipelines(
Expand All @@ -460,7 +448,7 @@ const resolveCurrentPipeline = async (

if (currentPipelineCandidate === undefined) {
const message =
mergeRequestInfo.pipeline === null
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);
Expand Down Expand Up @@ -638,7 +626,7 @@ export const runAcceptingMergeRequest = async (
kind: AcceptMergeRequestResultKind.InvalidPipeline,
mergeRequestInfo,
user,
pipeline: mergeRequestInfo.pipeline,
pipeline: mergeRequestInfo.head_pipeline,
};
}

Expand Down
10 changes: 5 additions & 5 deletions server/src/PipelineCanceller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ export const tryCancelPipeline = async (
mergeRequestInfo: MergeRequestInfo,
user: User,
): Promise<void> => {
if (mergeRequestInfo.pipeline === null) {
if (mergeRequestInfo.head_pipeline === null) {
return;
}

if (
mergeRequestInfo.pipeline.status !== PipelineStatus.Running &&
mergeRequestInfo.pipeline.status !== PipelineStatus.Pending
mergeRequestInfo.head_pipeline.status !== PipelineStatus.Running &&
mergeRequestInfo.head_pipeline.status !== PipelineStatus.Pending
) {
return;
}

const mergeRequestPipeline = await gitlabApi.getPipeline(
mergeRequestInfo.project_id,
mergeRequestInfo.pipeline.id,
mergeRequestInfo.head_pipeline.id,
);
if (mergeRequestPipeline.user.id !== user.id) {
return;
}

await gitlabApi.cancelPipeline(mergeRequestInfo.project_id, mergeRequestInfo.pipeline.id);
await gitlabApi.cancelPipeline(mergeRequestInfo.project_id, mergeRequestInfo.head_pipeline.id);
};

0 comments on commit 474cdfa

Please sign in to comment.