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

Commit 502d6a0

Browse files
committed
Combine mutually exclusive actions
1 parent c04eea7 commit 502d6a0

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
}
@@ -320,7 +315,7 @@ export function process(prInfo: BotResult,
320315
(info.tooManyOwners || info.hasMultiplePackages) ? [] : info.otherOwners,
321316
headCommitAbbrOid));
322317
if (info.hasValidMergeRequest) {
323-
actions.shouldMerge = true;
318+
actions.state = "merge";
324319
actions.projectColumn = "Recently Merged";
325320
} else {
326321
actions.projectColumn = "Waiting for Author to Merge";
@@ -334,7 +329,7 @@ export function process(prInfo: BotResult,
334329
}
335330
}
336331

337-
if (!actions.shouldMerge) {
332+
if (!actions.state) {
338333
if (info.mergeRequestUser) {
339334
post(Comments.WaitUntilMergeIsOK(info.mergeRequestUser, headCommitAbbrOid, urls.workflow));
340335
}
@@ -372,7 +367,7 @@ function makeStaleness(now: Date, author: string, otherOwners: string[]) { // cu
372367
}
373368
if (state === "done") {
374369
if (doneColumn === "CLOSE") {
375-
actions.shouldClose = true;
370+
actions.state = "close";
376371
actions.projectColumn = "REMOVE";
377372
} else {
378373
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)