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

Commit 59a206c

Browse files
committed
Combine mutually exclusive actions
1 parent e3e8f84 commit 59a206c

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

src/compute-pr-actions.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,7 @@ export interface Actions {
5252
projectColumn?: ColumnName | "REMOVE";
5353
labels: LabelName[];
5454
responseComments: Comments.Comment[];
55-
shouldClose: boolean;
56-
shouldMerge: boolean;
55+
state?: "close" | "merge";
5756
shouldUpdateLabels: boolean;
5857
}
5958

@@ -62,8 +61,6 @@ function createDefaultActions(): Actions {
6261
projectColumn: "Other",
6362
labels: [],
6463
responseComments: [],
65-
shouldClose: false,
66-
shouldMerge: false,
6764
shouldUpdateLabels: true,
6865
};
6966
}
@@ -72,8 +69,6 @@ function createEmptyActions(): Actions {
7269
return {
7370
labels: [],
7471
responseComments: [],
75-
shouldClose: false,
76-
shouldMerge: false,
7772
shouldUpdateLabels: false,
7873
};
7974
}
@@ -327,7 +322,7 @@ export function process(prInfo: BotResult,
327322
(info.tooManyOwners || info.hasMultiplePackages) ? [] : info.otherOwners,
328323
headCommitAbbrOid));
329324
if (info.hasValidMergeRequest) {
330-
actions.shouldMerge = true;
325+
actions.state = "merge";
331326
actions.projectColumn = "Recently Merged";
332327
} else {
333328
actions.projectColumn = "Waiting for Author to Merge";
@@ -341,7 +336,7 @@ export function process(prInfo: BotResult,
341336
}
342337
}
343338

344-
if (!actions.shouldMerge) {
339+
if (!actions.state) {
345340
if (info.mergeRequestUser) {
346341
post(Comments.WaitUntilMergeIsOK(info.mergeRequestUser, headCommitAbbrOid, urls.workflow));
347342
}
@@ -371,7 +366,7 @@ function makeStaleness(now: Date, author: string, otherOwners: string[]) { // cu
371366
}
372367
if (state === "done") {
373368
if (doneColumn === "CLOSE") {
374-
actions.shouldClose = true;
369+
actions.state = "close";
375370
actions.projectColumn = "REMOVE";
376371
} else {
377372
actions.projectColumn = doneColumn;

src/execute-pr-actions.ts

Lines changed: 10 additions & 10 deletions
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)