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 Feb 1, 2021
1 parent aba7ab3 commit 16380ad
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 18 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 {
projectColumn?: ColumnName | "*REMOVE*";
labels: LabelName[];
responseComments: Comments.Comment[];
shouldClose: boolean;
shouldMerge: boolean;
state?: "close" | "merge";
shouldUpdateLabels: boolean;
}

Expand All @@ -62,8 +61,6 @@ function createDefaultActions(): Actions {
projectColumn: "Other",
labels: [],
responseComments: [],
shouldClose: false,
shouldMerge: false,
shouldUpdateLabels: true,
};
}
Expand All @@ -72,8 +69,6 @@ function createEmptyActions(): Actions {
return {
labels: [],
responseComments: [],
shouldClose: false,
shouldMerge: false,
shouldUpdateLabels: false,
};
}
Expand Down Expand Up @@ -327,7 +322,7 @@ export function process(prInfo: BotResult,
(info.tooManyOwners || info.hasMultiplePackages) ? [] : info.otherOwners,
headCommitAbbrOid));
if (info.hasValidMergeRequest) {
actions.shouldMerge = true;
actions.state = "merge";
actions.projectColumn = "Recently Merged";
} else {
actions.projectColumn = "Waiting for Author to Merge";
Expand All @@ -341,7 +336,7 @@ export function process(prInfo: BotResult,
}
}

if (!actions.shouldMerge) {
if (!actions.state) {
if (info.mergeRequestUser) {
post(Comments.WaitUntilMergeIsOK(info.mergeRequestUser, headCommitAbbrOid, urls.workflow));
}
Expand Down Expand Up @@ -371,7 +366,7 @@ function makeStaleness(now: Date, author: string, otherOwners: string[]) { // cu
}
if (state === "done") {
if (doneColumn === "CLOSE") {
actions.shouldClose = true;
actions.state = "close";
actions.projectColumn = "*REMOVE*";
} else {
actions.projectColumn = doneColumn;
Expand Down
17 changes: 8 additions & 9 deletions src/execute-pr-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,18 @@ function getMutationsForCommentRemovals(actions: Actions, botComments: ParsedCom
}

function getMutationsForChangingPRState(actions: Actions, pr: PR_repository_pullRequest) {
return [
actions.shouldMerge
? createMutation<schema.MergePullRequestInput>("mergePullRequest", {
if (!actions.state) return [];
switch (actions.state) {
case "close":
return [createMutation<schema.ClosePullRequestInput>("closePullRequest", { pullRequestId: pr.id })];
case "merge":
return [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,
];
})];
}
}

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

0 comments on commit 16380ad

Please sign in to comment.