Skip to content

Commit 8fa454f

Browse files
authored
Handle error after rebase (#11)
1 parent 6615530 commit 8fa454f

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

src/GitlabApi.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ export interface MergeRequestInfo extends MergeRequest {
7575
pipeline: MergeRequestPipeline | null;
7676
diverged_commits_count: number;
7777
rebase_in_progress: boolean;
78+
merge_error: string | null;
7879
}
7980

8081
export interface DiscussionNote {

src/MergeRequestAcceptor.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export enum AcceptMergeRequestResultKind {
1616
ClosedMergeRequest,
1717
ReassignedMergeRequest,
1818
CanNotBeMerged,
19+
RebaseFailed,
1920
FailedPipeline,
2021
Unauthorized,
2122
}
@@ -51,10 +52,16 @@ interface UnauthorizedResponse {
5152
mergeRequestInfo: MergeRequestInfo;
5253
}
5354

55+
interface RebaseFailedResponse {
56+
kind: AcceptMergeRequestResultKind.RebaseFailed;
57+
mergeRequestInfo: MergeRequestInfo;
58+
}
59+
5460
type AcceptMergeRequestResult = SuccessResponse
5561
| ClosedMergeRequestResponse
5662
| ReassignedMergeRequestResponse
5763
| CanNotBeMergedResponse
64+
| RebaseFailedResponse
5865
| FailedPipelineResponse
5966
| UnauthorizedResponse;
6067

@@ -109,9 +116,9 @@ export const acceptMergeRequest = async (gitlabApi: GitlabApi, mergeRequest: Mer
109116
throw new Error(`Unexpected MR status: ${mergeRequestInfo.state}`);
110117
}
111118

112-
if (mergeRequestInfo.merge_status !== MergeStatus.CanBeMerged || mergeRequestInfo.work_in_progress) {
119+
if (mergeRequestInfo.merge_error !== null) {
113120
return {
114-
kind: AcceptMergeRequestResultKind.CanNotBeMerged,
121+
kind: AcceptMergeRequestResultKind.RebaseFailed,
115122
mergeRequestInfo,
116123
};
117124
}
@@ -122,6 +129,13 @@ export const acceptMergeRequest = async (gitlabApi: GitlabApi, mergeRequest: Mer
122129
continue;
123130
}
124131

132+
if (mergeRequestInfo.merge_status !== MergeStatus.CanBeMerged || mergeRequestInfo.work_in_progress) {
133+
return {
134+
kind: AcceptMergeRequestResultKind.CanNotBeMerged,
135+
mergeRequestInfo,
136+
};
137+
}
138+
125139
if (mergeRequestInfo.diverged_commits_count > 0) {
126140
await gitlabApi.updateMergeRequest(mergeRequest.project_id, mergeRequest.iid, {
127141
labels: [...filterBotLabels(mergeRequestInfo.labels), BotLabels.Rebasing].join(','),

src/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,17 @@ const runMergeRequestCheckerLoop = async (user: User) => {
110110
return;
111111
}
112112

113+
if (result.kind === AcceptMergeRequestResultKind.RebaseFailed) {
114+
console.log(`[MR] rebase failed: ${result.mergeRequestInfo.merge_error}, assigning back`);
115+
116+
await Promise.all([
117+
assignToAuthorAndResetLabels(gitlabApi, result.mergeRequestInfo),
118+
sendNote(gitlabApi, mergeRequest, `Merge request can't be merged: ${result.mergeRequestInfo.merge_error}`),
119+
]);
120+
121+
return;
122+
}
123+
113124
if (result.kind === AcceptMergeRequestResultKind.ClosedMergeRequest) {
114125
console.log(`[MR] Merge request is closed, ending`);
115126

0 commit comments

Comments
 (0)