Skip to content

Commit

Permalink
New project board: 2 small followups (#1032)
Browse files Browse the repository at this point in the history
  • Loading branch information
sandersn authored Jul 11, 2024
1 parent a07da6b commit e68e1b2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/mergebot/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ To create fixtures of a current PR:

```sh
# To create a fixture for PR 43161
pnpm run create-fixture -- 43161
pnpm run create-fixture 43161
```

Then you can work against these fixtures offline with:
Expand Down
21 changes: 9 additions & 12 deletions packages/mergebot/src/functions/pr-trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@ import { httpLog, shouldRunRequest } from "../util/verify";
import type {
CheckSuiteEvent,
IssueCommentEvent,
ProjectCardEvent,
ProjectsV2ItemEvent,
PullRequestEvent,
PullRequestReviewEvent,
} from "@octokit/webhooks-types";
import { runQueryToGetPRForCardId } from "../queries/card-id-to-pr-query";

app.http("PR-Trigger", { methods: ["GET", "POST"], authLevel: "anonymous", handler: httpTrigger });
const eventNames = [
"check_suite.completed",
"issue_comment.created",
"issue_comment.deleted",
"issue_comment.edited",
"project_card.moved",
"projects_v2_item.edited",
"pull_request.closed",
"pull_request.edited",
"pull_request.opened",
Expand All @@ -36,7 +37,7 @@ const eventNames = [
type PrEvent =
| { name: "check_suite"; payload: CheckSuiteEvent }
| { name: "issue_comment"; payload: IssueCommentEvent }
| { name: "project_card"; payload: ProjectCardEvent }
| { name: "projects_v2_item"; payload: ProjectsV2ItemEvent }
| { name: "pull_request"; payload: PullRequestEvent }
| { name: "pull_request_review"; payload: PullRequestReviewEvent };

Expand Down Expand Up @@ -120,15 +121,11 @@ const prFromEvent = async (event: PrEvent) => {
return prFromCheckSuiteEvent(event.payload);
case "issue_comment":
return event.payload.issue;
// "Parse" project_card.content_url according to repository.pulls_url
case "project_card": {
const url = event.payload.project_card.content_url;
return url
? { number: +url.replace(/^.*\//, "") }
: new IgnoredBecause(
`Couldn't find PR number since content_url is missing: ${JSON.stringify(event.payload.project_card)}`,
);
}
case "projects_v2_item":
const pr = await runQueryToGetPRForCardId(event.payload.projects_v2_item.node_id);
return pr
? { number: pr.number }
: new IgnoredBecause(`Could not find PR for card_id: ${event.payload.projects_v2_item.node_id}`);
case "pull_request":
return event.payload.pull_request;
case "pull_request_review":
Expand Down
21 changes: 10 additions & 11 deletions packages/mergebot/src/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,8 @@ const start = async function () {
//
console.log("Cleaning up cards");
const { columns, id: projectId } = await getProjectBoardCards();
const deleteObject = async (id: string, shoulda?: string) => {
if (shoulda) {
// don't automatically delete these, eg, PRs that were created
// during the scan would end up here.
return console.log(` Should delete "${id}" (${shoulda})`);
}
const deleteObject = async (id: string) => {
console.log(` Deleting card ${id}`);
const mutation = createMutation<schema.DeleteProjectV2ItemInput>("deleteProjectV2Item", { projectId, itemId: id });
await client.mutate(mutation);
};
Expand All @@ -150,15 +146,18 @@ const start = async function () {
// Handle other columns
for (const [name, cards] of columns) {
if (name === "Recently Merged") continue;
const ids = cards.map((c) => c.id).filter((c) => !cardIDs.includes(c));
const ids = cards.map((c) => c.id).filter((id) => !cardIDs.includes(id));
if (ids.length === 0) continue;
console.log(`Cleaning up closed PRs in "${name}"`);
for (const id of ids) {
const info = await runQueryToGetPRForCardId(id);
await deleteObject(
id,
info === undefined ? "???" : info.state === "CLOSED" || info.state === "MERGED" ? undefined : "#" + info.number,
);
if (!info) {
// don't automatically delete these, eg, PRs that were created
// during the scan would end up here.
console.log(` Should delete "${id}" (PR #???)`);
} else if (info.state !== "OPEN") {
await deleteObject(id);
}
}
}
if (failures.length) {
Expand Down

0 comments on commit e68e1b2

Please sign in to comment.