Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions packages/mergebot/src/_tests/zero-edited-files.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { join } from "path";

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a fixture test of an existing PR like this if possible

import { process } from "../compute-pr-actions";
import { deriveStateForPR, PRQueryResponse } from "../pr-info";
import { readJsonSync } from "../util/util";

describe("zero edited files", () => {
it("closes open PRs immediately", async () => {
const responsePath = join(__dirname, "fixtures", "43136", "_response.json");
const response: PRQueryResponse = readJsonSync(responsePath);
const original = response.data.repository?.pullRequest;
if (!original) throw new Error("Missing pull request in fixture");

const prInfo = {
...original,
changedFiles: 0,
files: { ...original.files, nodes: [] },
} as typeof original;

const derived = await deriveStateForPR(
prInfo,
async () => {
throw new Error("fetchFile should not be called");
},
async () => {
throw new Error("getDownloads should not be called");
},
new Date("2026-01-01T00:00:00.000Z"),
);

expect(derived).toMatchObject({
type: "remove",
message: "PR has no edited files",
shouldClose: true,
});

const actions = process(derived);
expect(actions).toMatchObject({
projectColumn: "*REMOVE*",
shouldClose: true,
shouldUpdateLabels: false,
});
expect(actions.responseComments).toEqual([]);
});
});
1 change: 1 addition & 0 deletions packages/mergebot/src/compute-pr-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ export function process(prInfo: BotResult, extendedCallback: (info: ExtendedPrIn
return {
...createEmptyActions(),
projectColumn: prInfo.isDraft ? "Needs Author Action" : "*REMOVE*",
shouldClose: !!prInfo.shouldClose,
};
}

Expand Down
6 changes: 4 additions & 2 deletions packages/mergebot/src/pr-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ interface BotEnsureRemovedFromProject {
readonly now: Date;
readonly message: string;
readonly isDraft: boolean;
readonly shouldClose?: boolean;
}

export interface PackageInfo {
Expand Down Expand Up @@ -216,6 +217,7 @@ export async function deriveStateForPR(

if (prInfo.isDraft) return botEnsureRemovedFromProject("PR is a draft");
if (prInfo.state !== "OPEN") return botEnsureRemovedFromProject("PR is not active");
if (prInfo.changedFiles === 0) return botEnsureRemovedFromProject("PR has no edited files", true);

const headCommit = getHeadCommit(prInfo);
// eslint-disable-next-line eqeqeq
Expand Down Expand Up @@ -316,8 +318,8 @@ export async function deriveStateForPR(
return { type: "error", now, message, author: prInfo.author?.login };
}

function botEnsureRemovedFromProject(message: string): BotEnsureRemovedFromProject {
return { type: "remove", now, message, isDraft: prInfo.isDraft };
function botEnsureRemovedFromProject(message: string, shouldClose = false): BotEnsureRemovedFromProject {
return { type: "remove", now, message, isDraft: prInfo.isDraft, shouldClose };
}
}

Expand Down