Skip to content
This repository was archived by the owner on Jul 1, 2024. It is now read-only.

Commit 858a194

Browse files
committed
Combine mutually exclusive actions
1 parent fbd480b commit 858a194

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

Diff for: src/compute-pr-actions.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ export interface Actions {
5252
targetColumn?: ColumnName;
5353
labels: LabelName[];
5454
responseComments: Comments.Comment[];
55-
shouldClose: boolean;
56-
shouldMerge: boolean;
55+
state?: "close" | "merge";
5756
shouldUpdateLabels: boolean;
5857
shouldUpdateProjectColumn: boolean;
5958
shouldRemoveFromActiveColumns: boolean;
@@ -64,8 +63,6 @@ function createDefaultActions(): Actions {
6463
targetColumn: "Other",
6564
labels: [],
6665
responseComments: [],
67-
shouldClose: false,
68-
shouldMerge: false,
6966
shouldUpdateLabels: true,
7067
shouldUpdateProjectColumn: true,
7168
shouldRemoveFromActiveColumns: false,
@@ -76,8 +73,6 @@ function createEmptyActions(): Actions {
7673
return {
7774
labels: [],
7875
responseComments: [],
79-
shouldClose: false,
80-
shouldMerge: false,
8176
shouldUpdateLabels: false,
8277
shouldUpdateProjectColumn: false,
8378
shouldRemoveFromActiveColumns: false,
@@ -334,7 +329,7 @@ export function process(prInfo: BotResult,
334329
(info.tooManyOwners || info.hasMultiplePackages) ? [] : info.otherOwners,
335330
headCommitAbbrOid));
336331
if (info.hasValidMergeRequest) {
337-
context.shouldMerge = true;
332+
context.state = "merge";
338333
context.targetColumn = "Recently Merged";
339334
} else {
340335
context.targetColumn = "Waiting for Author to Merge";
@@ -348,7 +343,7 @@ export function process(prInfo: BotResult,
348343
}
349344
}
350345

351-
if (!context.shouldMerge) {
346+
if (!context.state) {
352347
if (info.mergeRequestUser) {
353348
post(Comments.WaitUntilMergeIsOK(info.mergeRequestUser, headCommitAbbrOid, urls.workflow));
354349
}
@@ -385,7 +380,7 @@ function makeStaleness(now: Date, author: string, otherOwners: string[]) { // cu
385380
}
386381
if (state === "done") {
387382
if (doneColumn === "CLOSE") {
388-
context.shouldClose = true;
383+
context.state = "close";
389384
context.shouldRemoveFromActiveColumns = true;
390385
} else {
391386
context.targetColumn = doneColumn;

Diff for: src/execute-pr-actions.ts

+10-10
Original file line numberDiff line numberDiff line change
@@ -101,20 +101,20 @@ function getMutationsForCommentRemovals(actions: Actions, botComments: ParsedCom
101101
});
102102
}
103103

104-
function getMutationsForChangingPRState(actions: Actions, pr: PR_repository_pullRequest) {
105-
return [
106-
actions.shouldMerge
107-
? createMutation<schema.MergePullRequestInput>("mergePullRequest", {
104+
function* getMutationsForChangingPRState(actions: Actions, pr: PR_repository_pullRequest) {
105+
switch (actions.state) {
106+
case "close":
107+
yield createMutation<schema.ClosePullRequestInput>("closePullRequest", { pullRequestId: pr.id });
108+
break;
109+
case "merge":
110+
yield createMutation<schema.MergePullRequestInput>("mergePullRequest", {
108111
commitHeadline: `🤖 Merge PR #${pr.number} ${pr.title} by @${pr.author?.login ?? "(ghost)"}`,
109112
expectedHeadOid: pr.headRefOid,
110113
mergeMethod: "SQUASH",
111114
pullRequestId: pr.id,
112-
})
113-
: null,
114-
actions.shouldClose
115-
? createMutation<schema.ClosePullRequestInput>("closePullRequest", { pullRequestId: pr.id })
116-
: null
117-
];
115+
});
116+
break;
117+
}
118118
}
119119

120120
async function getProjectBoardColumnIdByName(name: string): Promise<string> {

0 commit comments

Comments
 (0)