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

Commit

Permalink
Combine mutually exclusive actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jablko committed Jan 21, 2021
1 parent fbd480b commit 858a194
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 19 deletions.
13 changes: 4 additions & 9 deletions src/compute-pr-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ export interface Actions {
targetColumn?: ColumnName;
labels: LabelName[];
responseComments: Comments.Comment[];
shouldClose: boolean;
shouldMerge: boolean;
state?: "close" | "merge";
shouldUpdateLabels: boolean;
shouldUpdateProjectColumn: boolean;
shouldRemoveFromActiveColumns: boolean;
Expand All @@ -64,8 +63,6 @@ function createDefaultActions(): Actions {
targetColumn: "Other",
labels: [],
responseComments: [],
shouldClose: false,
shouldMerge: false,
shouldUpdateLabels: true,
shouldUpdateProjectColumn: true,
shouldRemoveFromActiveColumns: false,
Expand All @@ -76,8 +73,6 @@ function createEmptyActions(): Actions {
return {
labels: [],
responseComments: [],
shouldClose: false,
shouldMerge: false,
shouldUpdateLabels: false,
shouldUpdateProjectColumn: false,
shouldRemoveFromActiveColumns: false,
Expand Down Expand Up @@ -334,7 +329,7 @@ export function process(prInfo: BotResult,
(info.tooManyOwners || info.hasMultiplePackages) ? [] : info.otherOwners,
headCommitAbbrOid));
if (info.hasValidMergeRequest) {
context.shouldMerge = true;
context.state = "merge";
context.targetColumn = "Recently Merged";
} else {
context.targetColumn = "Waiting for Author to Merge";
Expand All @@ -348,7 +343,7 @@ export function process(prInfo: BotResult,
}
}

if (!context.shouldMerge) {
if (!context.state) {
if (info.mergeRequestUser) {
post(Comments.WaitUntilMergeIsOK(info.mergeRequestUser, headCommitAbbrOid, urls.workflow));
}
Expand Down Expand Up @@ -385,7 +380,7 @@ function makeStaleness(now: Date, author: string, otherOwners: string[]) { // cu
}
if (state === "done") {
if (doneColumn === "CLOSE") {
context.shouldClose = true;
context.state = "close";
context.shouldRemoveFromActiveColumns = true;
} else {
context.targetColumn = doneColumn;
Expand Down
20 changes: 10 additions & 10 deletions src/execute-pr-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,20 +101,20 @@ function getMutationsForCommentRemovals(actions: Actions, botComments: ParsedCom
});
}

function getMutationsForChangingPRState(actions: Actions, pr: PR_repository_pullRequest) {
return [
actions.shouldMerge
? createMutation<schema.MergePullRequestInput>("mergePullRequest", {
function* getMutationsForChangingPRState(actions: Actions, pr: PR_repository_pullRequest) {
switch (actions.state) {
case "close":
yield createMutation<schema.ClosePullRequestInput>("closePullRequest", { pullRequestId: pr.id });
break;
case "merge":
yield createMutation<schema.MergePullRequestInput>("mergePullRequest", {
commitHeadline: `🤖 Merge PR #${pr.number} ${pr.title} by @${pr.author?.login ?? "(ghost)"}`,
expectedHeadOid: pr.headRefOid,
mergeMethod: "SQUASH",
pullRequestId: pr.id,
})
: null,
actions.shouldClose
? createMutation<schema.ClosePullRequestInput>("closePullRequest", { pullRequestId: pr.id })
: null
];
});
break;
}
}

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

0 comments on commit 858a194

Please sign in to comment.