Skip to content

๐Ÿคฏ LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

๐Ÿ‘ท build: add PR admission check and stale PR cleanup (#20778)

YuTengjing37f4ac20b89c
diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md
index dbaeebf2527..988c3d18905 100644
--- a/.github/PULL_REQUEST_TEMPLATE.md
+++ b/.github/PULL_REQUEST_TEMPLATE.md
@@ -53,7 +53,12 @@ Contribution source: <!-- Set to AI-assisted, Human-only, or Unknown. Required f
- [ ] Added/updated tests
- [ ] No tests needed
-<!-- Acceptance round for user-visible changes (AGENTS.md โ†’ Acceptance); or state why none is needed -->
+<!--
+Required. Replace `...` below with acceptance evidence: an acceptance round link (AGENTS.md โ†’ Acceptance),
+screenshots or recordings, or the steps you used to verify the change.
+When no acceptance is needed, write `Not needed: <reason>`.
+The PR admission check labels PRs missing these fields as `pr:incomplete`; incomplete PRs are closed after 14 days without activity.
+-->
- Acceptance: ...
diff --git a/.github/scripts/pr-admission-check.cjs b/.github/scripts/pr-admission-check.cjs
new file mode 100644
index 00000000000..cf799852886
--- /dev/null
+++ b/.github/scripts/pr-admission-check.cjs
@@ -0,0 +1,269 @@
+/**
+ * PR admission check: labels and comments on pull requests whose description has no
+ * acceptance evidence, the part of the merge standard (CI passing + Codex review approval +
+ * acceptance evidence) that CI and Codex cannot check themselves.
+ *
+ * Only the evidence is required, not the template's exact layout: many maintainers write
+ * their own `## Acceptance` / `## Verification` sections, and flagging those would bury the
+ * PRs that really lack evidence. Template-only fields (contribution source, test boxes) and
+ * title format are left to review.
+ *
+ * The verdict is deterministic on purpose โ€” no model calls โ€” so contributors get the same
+ * result on every run, and `pr-stale.yml` can close long-incomplete PRs based on the label.
+ *
+ * Usage (inside actions/github-script):
+ * const check = require('<workspace>/.github/scripts/pr-admission-check.cjs');
+ * await check.run({ github, context }); // on PR events
+ * await check.closeIncomplete({ core, dryRun, github, context }); // on a schedule
+ */
+const LABEL = 'pr:incomplete';
+const KEEP_OPEN_LABEL = 'keep-open';
+const INCOMPLETE_CLOSE_DAYS = 14;
+const DAY_MS = 24 * 60 * 60 * 1000;
+const MARKER = '<!-- PR-ADMISSION-CHECK -->';
+const TEMPLATE_URL =
+ 'https://github.com/lobehub/lobehub/blob/canary/.github/PULL_REQUEST_TEMPLATE.md';
+
+const fs = require('node:fs');
+const path = require('node:path');
+
+/** Automation accounts that open PRs without the template (i18n, dependency bumps). */
+const EXEMPT_LOGINS = new Set(['lobehubbot']);
+
+/**
+ * Team members are held to the merge standard in review, not by this check; it targets
+ * outside contributions. `author_association` covers org members and collaborators, but
+ * GitHub reports private org members as `CONTRIBUTOR` in event payloads, so the maintainer
+ * list (also used by `claude-pr-assign.yml`) backs it up.
+ */
+const TEAM_ASSOCIATIONS = new Set(['COLLABORATOR', 'MEMBER', 'OWNER']);
+const MAINTAINERS = new Set(
+ fs
+ .readFileSync(path.join(__dirname, '../maintainers.txt'), 'utf8')
+ .split('\n')
+ .map((line) => line.trim().toLowerCase())
+ .filter(Boolean),
+);
+
+/** Template placeholders and bare opt-outs that carry no evidence or reason. */
+const EMPTY_VALUES = new Set(['', '...', 'โ€ฆ', '-', 'n/a', 'na', 'none', 'todo', 'tbd']);
+
+/** `Acceptance:` field from the template, optionally bold or in a list item. */
+const ACCEPTANCE_FIELD = /^[\t ]*(?:[*-][\t ]*)?(?:\*\*)?acceptance(?:\*\*)?:(.*)$/gim;
+
+/** Free-form sections maintainers use instead of the field, in English or Chinese. */
+const EVIDENCE_HEADING =
+ /^#{1,6}[\t ].*(?:\b(?:acceptance|verification|test(?:s|ing| plan)?|how to test)\b|้ชŒๆ”ถ|้ชŒ่ฏ|ๆต‹่ฏ•).*$/gim;
+
+/** A published acceptance round is evidence wherever it appears. */
+const ACCEPTANCE_LINK = /https:\/\/(?:app\.)?lobehub\.com\/acceptance\/[\w-]+/i;
+
+/**
+ * Drops what GitHub hides when rendering: HTML comments, and everything after an unclosed
+ * `<!--`. Scans by index rather than with a regex replace so no comment opener survives.
+ */
+const stripComments = (text) => {
+ let result = '';
+ let cursor = 0;
+ while (cursor < text.length) {
+ const start = text.indexOf('<!--', cursor);
+ if (start === -1) return result + text.slice(cursor);
+ result += text.slice(cursor, start);
+ const end = text.indexOf('-->', start + 4);
+ if (end === -1) return result;
+ cursor = end + 3;
+ }
+ return result;
+};
+
+/** Unchecked boxes and the template's own test options say nothing about this change. */
+const TEMPLATE_SCAFFOLDING =
+ /^\s*[*-]\s+\[(?: |x\]\s*(?:tested locally|added\/updated tests|no tests needed)\s*$)/i;
+
+/**
+ * Collapses a value to plain lowercase text without list markers or markdown emphasis.
+ * Template scaffolding and placeholder-only lines (`- TODO`, `...`) are dropped line by line,
+ * so a section made only of placeholders normalizes to an empty string.
+ */
+const normalize = (value) =>
+ value
+ .split('\n')
+ // Subheadings structure a section but are not evidence themselves.
+ .filter((line) => !TEMPLATE_SCAFFOLDING.test(line) && !/^#{1,6}\s/.test(line))
+ .map((line) =>
+ line
+ .replace(/^\s*(?:[*-]\s+)?/, '')
+ .replaceAll(/[*_`]/g, '')
+ .trim()
+ .toLowerCase(),
+ )
+ .filter((line) => !EMPTY_VALUES.has(line))
+ .join(' ');
+
+/**
+ * Text after `index` up to the next heading at `level` or higher, so nested subheadings
+ * (`## Acceptance` โ†’ `### Local browser`) stay inside the section.
+ */
+const sectionAfter = (body, index, level = 6) =>
+ body.slice(index).split(new RegExp(`^#{1,${level}}\\s`, 'm'))[0];
+
+/** Every place the description may hold acceptance evidence, normalized. */
+const readEvidence = (body) => {
+ const values = [];
+ for (const match of body.matchAll(ACCEPTANCE_FIELD)) {
+ const inline = normalize(match[1]);
+ // Evidence may follow on the next lines, e.g. a nested list of screenshots.
+ values.push(inline || normalize(sectionAfter(body, match.index + match[0].length)));
+ }
+ for (const match of body.matchAll(EVIDENCE_HEADING)) {
+ // The template's `Acceptance:` line sits under `#### Test`; it is judged on its own above.
+ const level = match[0].match(/^#+/)[0].length;
+ const section = sectionAfter(body, match.index + match[0].length, level).replaceAll(
+ ACCEPTANCE_FIELD,
+ '',
+ );
+ values.push(normalize(section));
+ }
+ return values;
+};
+
+const isEvidence = (value) => {
+ if (EMPTY_VALUES.has(value)) return false;
+ const optOutReason = value.match(/^not needed:?(.*)$/)?.[1]?.trim();
+ return optOutReason === undefined || !EMPTY_VALUES.has(optOutReason);
+};
+
+/**
+ * Returns the problems found in a PR description, in display order. An empty array means
+ * the PR meets the admission requirements.
+ */
+const findProblems = ({ body = '' }) => {
+ const content = stripComments(body ?? '');
+ if (ACCEPTANCE_LINK.test(content) || readEvidence(content).some(isEvidence)) return [];
+ return [
+ 'Acceptance evidence: fill `Acceptance` with an acceptance round link, screenshots, recordings, or the steps you used to verify the change; or write `Not needed: <reason>`.',
+ ];
+};
+
+const isTeamMember = (pr) =>
+ TEAM_ASSOCIATIONS.has(pr.author_association) || MAINTAINERS.has(pr.user?.login?.toLowerCase());
+
+/**
+ * PRs the check skips: drafts, bots, team members, and PRs from the release flow โ€” weekly
+ * releases and mainโ†’canary syncs (`๐Ÿš€ release:` titles), and hotfix or migration-forward
+ * branches (`hotfix/*`, `release/*`).
+ */
+const isExempt = (pr) =>
+ pr.draft ||
+ pr.user?.type === 'Bot' ||
+ EXEMPT_LOGINS.has(pr.user?.login) ||
+ isTeamMember(pr) ||
+ /^๐Ÿš€\s*release:/u.test(pr.title ?? '') ||
+ /^(?:hotfix|release)\//.test(pr.head?.ref ?? '');
+
+const buildComment = (problems) => `${MARKER}
+๐Ÿ‘‹ Thanks for the PR! Before review, the description needs what the merge standard relies on (CI passing + Codex review approval + acceptance evidence):
+
+${problems.map((problem) => `- [ ] ${problem}`).join('\n')}
+
+See the [pull request template](${TEMPLATE_URL}); an \`## Acceptance\` or \`## Verification\` section works too. This check reruns when you edit the description, and removes the \`${LABEL}\` label once the evidence is there.
+
+PRs that stay \`${LABEL}\` are closed after ${INCOMPLETE_CLOSE_DAYS} days without activity.`;
+
+const CLOSE_COMMENT = `Closing because the description has had no acceptance evidence and no activity for ${INCOMPLETE_CLOSE_DAYS} days. Feel free to reopen after adding it.`;
+
+const run = async ({ github, context }) => {
+ const pr = context.payload.pull_request;
+ if (!pr || isExempt(pr)) return;
+
+ const { owner, repo } = context.repo;
+ const issue_number = pr.number;
+ const problems = findProblems({ body: pr.body });
+
+ const comments = await github.paginate(github.rest.issues.listComments, {
+ issue_number,
+ owner,
+ per_page: 100,
+ repo,
+ });
+ const existing = comments.find((comment) => comment.body?.startsWith(MARKER));
+ const hasLabel = pr.labels?.some((label) => label.name === LABEL);
+
+ if (problems.length > 0) {
+ if (!hasLabel) {
+ await github.rest.issues.addLabels({ issue_number, labels: [LABEL], owner, repo });
+ }
+ const body = buildComment(problems);
+ if (!existing) {
+ await github.rest.issues.createComment({ body, issue_number, owner, repo });
+ } else if (existing.body !== body) {
+ await github.rest.issues.updateComment({ body, comment_id: existing.id, owner, repo });
+ }
+ return;
+ }
+
+ if (hasLabel) {
+ try {
+ await github.rest.issues.removeLabel({ issue_number, name: LABEL, owner, repo });
+ } catch (error) {
+ // Someone removed the label between the event and this run.
+ if (error.status !== 404) throw error;
+ }
+ }
+ if (existing) {
+ await github.rest.issues.deleteComment({ comment_id: existing.id, owner, repo });
+ }
+};
+
+/** Current-state check for a close candidate found by search. */
+const shouldClose = (pr, cutoff) => {
+ const labels = new Set(pr.labels?.map((label) => label.name));
+ return (
+ pr.state === 'open' &&
+ !isExempt(pr) &&
+ labels.has(LABEL) &&
+ !labels.has(KEEP_OPEN_LABEL) &&
+ new Date(pr.updated_at) < cutoff &&
+ findProblems({ body: pr.body }).length > 0
+ );
+};
+
+/**
+ * Closes open PRs still labeled incomplete after the grace period. Runs from `pr-stale.yml`
+ * instead of a second actions/stale pass: actions/stale keeps its scan cursor under one fixed
+ * cache key, so two passes in the same repository skip each other's candidates.
+ */
+const closeIncomplete = async ({ core, dryRun, github, context, now = new Date() }) => {
+ const { owner, repo } = context.repo;
+ const cutoff = new Date(now.getTime() - INCOMPLETE_CLOSE_DAYS * DAY_MS);
+ const q = `repo:${owner}/${repo} is:pr is:open -is:draft label:"${LABEL}" -label:"${KEEP_OPEN_LABEL}" updated:<${cutoff.toISOString().slice(0, 10)}`;
+ const items = await github.paginate(github.rest.search.issuesAndPullRequests, {
+ per_page: 100,
+ q,
+ });
+
+ const closed = [];
+ for (const { number } of items) {
+ // Search results can be stale; re-read the PR so one fixed or exempted since then stays open.
+ const { data: pr } = await github.rest.pulls.get({ owner, pull_number: number, repo });
+ if (!shouldClose(pr, cutoff)) continue;
+
+ closed.push(number);
+ if (dryRun) {
+ core.info(`[dry-run] would close #${number}`);
+ continue;
+ }
+ await github.rest.issues.createComment({
+ body: CLOSE_COMMENT,
+ issue_number: number,
+ owner,
+ repo,
+ });
+ await github.rest.pulls.update({ owner, pull_number: number, repo, state: 'closed' });
+ core.info(`closed #${number}`);
+ }
+
+ return closed;
+};
+
+module.exports = { LABEL, MARKER, closeIncomplete, findProblems, isExempt, run };
diff --git a/.github/scripts/pr-admission-check.test.cjs b/.github/scripts/pr-admission-check.test.cjs
new file mode 100644
index 00000000000..67c2db98180
--- /dev/null
+++ b/.github/scripts/pr-admission-check.test.cjs
@@ -0,0 +1,272 @@
+const assert = require('node:assert/strict');
+const fs = require('node:fs');
+const path = require('node:path');
+const { test } = require('node:test');
+
+const {
+ LABEL,
+ MARKER,
+ closeIncomplete,
+ findProblems,
+ isExempt,
+ run,
+} = require('./pr-admission-check.cjs');
+
+const TEMPLATE = fs.readFileSync(path.join(__dirname, '../PULL_REQUEST_TEMPLATE.md'), 'utf8');
+
+/** The real template with Acceptance filled in, so template drift breaks these tests. */
+const fill = (acceptance = 'https://app.lobehub.com/acceptance/abc') =>
+ TEMPLATE.replace('- Acceptance: ...', `- Acceptance: ${acceptance}`);
+
+const passes = (body) => findProblems({ body }).length === 0;
+
+test('accepts the template with acceptance evidence', () => {
+ assert.equal(passes(fill()), true);
+});
+
+test('flags the untouched template and an empty body', () => {
+ assert.equal(passes(TEMPLATE), false);
+ assert.equal(passes(null), false);
+ assert.equal(passes(''), false);
+});
+
+test('ignores evidence that only appears inside HTML comments', () => {
+ assert.equal(passes(fill('<!-- https://example.com/after.png -->')), false);
+ // GitHub hides everything after an unclosed comment, so that text is not evidence either.
+ assert.equal(passes(fill('<!-- https://example.com/after.png')), false);
+ assert.equal(passes(fill('<!<!---- --> https://example.com/after.png')), true);
+});
+
+test('requires a reason when acceptance is opted out', () => {
+ for (const acceptance of ['N/A', 'none', 'Not needed:', '`...`', '**TBD**']) {
+ assert.equal(passes(fill(acceptance)), false, acceptance);
+ }
+ assert.equal(passes(fill('Not needed: CI config only')), true);
+});
+
+test('accepts acceptance evidence on the following lines', () => {
+ assert.equal(passes(fill('\n - ![after](https://example.com/after.png)')), true);
+});
+
+test('accepts free-form evidence sections maintainers write instead of the template', () => {
+ assert.equal(
+ passes('## What\n\nStuff.\n\n## Acceptance\n\nCI trigger only, no product change.'),
+ true,
+ );
+ assert.equal(passes('### Verification\n\n- `bun run check` passes\n\n### Notes\n'), true);
+ assert.equal(passes('## Test plan\n- open the page and click save'), true);
+ assert.equal(passes('**Acceptance:** https://app.lobehub.com/acceptance/abc'), true);
+});
+
+test('accepts Chinese headings, test sections, and acceptance links anywhere', () => {
+ assert.equal(passes('## ้ชŒๆ”ถ\n\n้กต้ขๅˆทๆ–ฐๅŽๆŽ’ๅบๆญฃ็กฎ'), true);
+ assert.equal(passes('## ๆต‹่ฏ•\n\n- ๆ–ฐๅขžๅ•ๆต‹่ฆ†็›–ๅ›ž้€€ๅˆ†ๆ”ฏ'), true);
+ assert.equal(passes('## Tests\n\n- added a regression test'), true);
+ assert.equal(passes('See https://lobehub.com/acceptance/1b0501e6-11f4 for the round.'), true);
+ assert.equal(
+ passes(
+ TEMPLATE.replace('- [ ] Tested locally', '- [x] Verified pricing against the model card'),
+ ),
+ true,
+ );
+});
+
+test('keeps nested subheadings inside an evidence section', () => {
+ assert.equal(
+ passes(
+ '## Acceptance\n### Local browser\n- Saved settings; refresh kept the value.\n## Notes\n',
+ ),
+ true,
+ );
+});
+
+test('rejects sections made only of placeholder lines', () => {
+ assert.equal(passes('## Acceptance\n### Local browser\n- TODO\n- TBD\n'), false);
+ assert.equal(passes('## Acceptance\n### Local browser\n### Desktop\n'), false);
+ assert.equal(passes('## Verification\n- TODO\n- TBD\n\n## Notes\nsomething'), false);
+ assert.equal(passes('## Acceptance\n...\n...\n'), false);
+});
+
+test('rejects evidence sections that hold only scaffolding', () => {
+ assert.equal(passes(TEMPLATE.replace('- [ ] Tested locally', '- [x] Tested locally')), false);
+ assert.equal(passes('## Verification\n\n- [ ] Tested locally\n\n## Notes\nsomething'), false);
+ assert.equal(passes('## Acceptance\n\nN/A\n\n## Notes\nsomething'), false);
+});
+
+test('exempts drafts, bots, team members, and release PRs', () => {
+ const base = {
+ draft: false,
+ head: { ref: 'feat/x' },
+ title: '๐Ÿ› fix: x',
+ user: { login: 'someone' },
+ };
+ assert.equal(isExempt(base), false);
+ assert.equal(isExempt({ ...base, author_association: 'FIRST_TIME_CONTRIBUTOR' }), false);
+ assert.equal(isExempt({ ...base, author_association: 'CONTRIBUTOR' }), false);
+ assert.equal(isExempt({ ...base, author_association: 'MEMBER' }), true);
+ assert.equal(isExempt({ ...base, author_association: 'OWNER' }), true);
+ // Private org members arrive as CONTRIBUTOR; the maintainer list still recognizes them.
+ assert.equal(
+ isExempt({ ...base, author_association: 'CONTRIBUTOR', user: { login: 'TJX666' } }),
+ true,
+ );
+ assert.equal(isExempt({ ...base, title: '๐Ÿš€ release: 20261007' }), true);
+ assert.equal(isExempt({ ...base, title: '๐Ÿš€ release: sync main branch to canary' }), true);
+ assert.equal(isExempt({ ...base, head: { ref: 'release/db-migration-0152-forward' } }), true);
+ assert.equal(isExempt({ ...base, draft: true }), true);
+ assert.equal(isExempt({ ...base, user: { login: 'renovate[bot]', type: 'Bot' } }), true);
+ assert.equal(isExempt({ ...base, user: { login: 'lobehubbot', type: 'User' } }), true);
+ assert.equal(isExempt({ ...base, title: '๐Ÿš€ release: v2.1.0' }), true);
+ assert.equal(isExempt({ ...base, head: { ref: 'hotfix/v2.1.1' } }), true);
+});
+
+const fakeGithub = ({ comments = [], pulls = {} } = {}) => {
+ const calls = [];
+ const queries = [];
+ const record = (name) => async (params) => {
+ calls.push([name, params]);
+ return {};
+ };
+ return {
+ calls,
+ paginate: async (method, params) => {
+ queries.push(params);
+ return comments;
+ },
+ queries,
+ rest: {
+ pulls: {
+ get: async ({ pull_number }) => ({ data: pulls[pull_number] }),
+ update: record('pullsUpdate'),
+ },
+ search: { issuesAndPullRequests: record('search') },
+ issues: {
+ addLabels: record('addLabels'),
+ createComment: record('createComment'),
+ deleteComment: record('deleteComment'),
+ listComments: record('listComments'),
+ removeLabel: record('removeLabel'),
+ updateComment: record('updateComment'),
+ },
+ },
+ };
+};
+
+const contextFor = (pr) => ({
+ payload: {
+ pull_request: {
+ draft: false,
+ head: { ref: 'feat/x' },
+ labels: [],
+ number: 7,
+ title: '๐Ÿ› fix: x',
+ user: { login: 'someone', type: 'User' },
+ ...pr,
+ },
+ },
+ repo: { owner: 'lobehub', repo: 'lobehub' },
+});
+
+const callNames = (github) => github.calls.map(([name]) => name);
+
+test('labels and comments on an incomplete PR', async () => {
+ const github = fakeGithub();
+ await run({ context: contextFor({ body: TEMPLATE }), github });
+ assert.deepEqual(callNames(github), ['addLabels', 'createComment']);
+ assert.deepEqual(github.calls[0][1].labels, [LABEL]);
+ assert.ok(github.calls[1][1].body.startsWith(MARKER));
+});
+
+test('updates the existing comment instead of posting another', async () => {
+ const github = fakeGithub({ comments: [{ body: `${MARKER}\nold`, id: 42 }] });
+ await run({ context: contextFor({ body: TEMPLATE, labels: [{ name: LABEL }] }), github });
+ assert.deepEqual(callNames(github), ['updateComment']);
+ assert.equal(github.calls[0][1].comment_id, 42);
+});
+
+test('writes nothing when the label and comment are already current', async () => {
+ const first = fakeGithub();
+ await run({ context: contextFor({ body: TEMPLATE }), github: first });
+ const body = first.calls[1][1].body;
+
+ const github = fakeGithub({ comments: [{ body, id: 42 }] });
+ await run({ context: contextFor({ body: TEMPLATE, labels: [{ name: LABEL }] }), github });
+ assert.deepEqual(callNames(github), []);
+});
+
+test('clears the label and comment once the PR is complete', async () => {
+ const github = fakeGithub({ comments: [{ body: `${MARKER}\nold`, id: 42 }] });
+ await run({ context: contextFor({ body: fill(), labels: [{ name: LABEL }] }), github });
+ assert.deepEqual(callNames(github), ['removeLabel', 'deleteComment']);
+});
+
+test('does nothing for exempt PRs', async () => {
+ const github = fakeGithub();
+ await run({ context: contextFor({ body: TEMPLATE, draft: true }), github });
+ assert.deepEqual(github.calls, []);
+});
+
+const NOW = new Date('2026-10-20T00:00:00Z');
+
+/** A PR that still qualifies for closing at NOW. */
+const candidate = (number, overrides = {}) => ({
+ body: TEMPLATE,
+ draft: false,
+ head: { ref: 'feat/x' },
+ labels: [{ name: LABEL }],
+ number,
+ state: 'open',
+ title: '๐Ÿ› fix: x',
+ updated_at: '2026-09-01T00:00:00Z',
+ user: { login: 'someone', type: 'User' },
+ ...overrides,
+});
+
+const closeWith = (github, dryRun) =>
+ closeIncomplete({
+ context: contextFor({}),
+ core: { info: () => {} },
+ dryRun,
+ github,
+ now: NOW,
+ });
+
+test('closeIncomplete only reports candidates in dry-run mode', async () => {
+ const github = fakeGithub({
+ comments: [{ number: 11 }, { number: 12 }],
+ pulls: { 11: candidate(11), 12: candidate(12) },
+ });
+ assert.deepEqual(await closeWith(github, true), [11, 12]);
+ assert.deepEqual(callNames(github), []);
+
+ const { q } = github.queries[0];
+ assert.match(q, /label:"pr:incomplete"/);
+ assert.match(q, /-label:"keep-open"/);
+ assert.match(q, /-is:draft/);
+ assert.match(q, /updated:<2026-10-06/);
+});
+
+test('closeIncomplete comments and closes candidates', async () => {
+ const github = fakeGithub({ comments: [{ number: 11 }], pulls: { 11: candidate(11) } });
+ assert.deepEqual(await closeWith(github, false), [11]);
+ assert.deepEqual(callNames(github), ['createComment', 'pullsUpdate']);
+ assert.equal(github.calls.at(-1)[1].state, 'closed');
+ assert.equal(github.calls.at(-1)[1].pull_number, 11);
+});
+
+test('closeIncomplete skips PRs that changed after the search', async () => {
+ const changed = {
+ 21: candidate(21, { draft: true }),
+ 22: candidate(22, { labels: [{ name: LABEL }, { name: 'keep-open' }] }),
+ 23: candidate(23, { updated_at: '2026-10-19T00:00:00Z' }),
+ 24: candidate(24, { body: fill() }),
+ 25: candidate(25, { labels: [] }),
+ 26: candidate(26, { state: 'closed' }),
+ };
+ const github = fakeGithub({
+ comments: Object.keys(changed).map((number) => ({ number: Number(number) })),
+ pulls: changed,
+ });
+ assert.deepEqual(await closeWith(github, false), []);
+ assert.deepEqual(callNames(github), []);
+});
diff --git a/.github/workflows/pr-admission-check.yml b/.github/workflows/pr-admission-check.yml
new file mode 100644
index 00000000000..ecf4ed7fa7b
--- /dev/null
+++ b/.github/workflows/pr-admission-check.yml
@@ -0,0 +1,36 @@
+name: PR Admission Check
+
+# Labels PRs whose title or description lacks what the merge standard relies on
+# (see .github/scripts/pr-admission-check.cjs). `pull_request_target` lets the check label
+# and comment on fork PRs; it never checks out or runs PR code โ€” only the base branch's
+# script is loaded, and the title and body are read from the event payload.
+on:
+ pull_request_target:
+ types: [opened, edited, reopened, ready_for_review]
+
+concurrency:
+ group: pr-admission-check-${{ github.event.pull_request.number }}
+ cancel-in-progress: true
+
+permissions:
+ contents: read
+ issues: write
+ pull-requests: write
+
+jobs:
+ check:
+ runs-on: ubuntu-latest
+ timeout-minutes: 5
+ steps:
+ - name: Checkout base branch scripts
+ uses: actions/checkout@v7
+ with:
+ # Cone mode also checks out files directly under .github/, including maintainers.txt.
+ sparse-checkout: .github/scripts
+
+ - name: Check PR description
+ uses: actions/github-script@v8
+ with:
+ script: |
+ const check = require(`${process.env.GITHUB_WORKSPACE}/.github/scripts/pr-admission-check.cjs`);
+ await check.run({ github, context });
diff --git a/.github/workflows/pr-stale.yml b/.github/workflows/pr-stale.yml
new file mode 100644
index 00000000000..82607114516
--- /dev/null
+++ b/.github/workflows/pr-stale.yml
@@ -0,0 +1,61 @@
+name: Close Stale PRs
+
+# Closes PRs nobody is moving forward; issues are left alone.
+# - PRs still labeled `pr:incomplete` by the admission check close after 14 days without
+# activity (the admission comment already announced this), via pr-admission-check.cjs.
+# - Other PRs are marked stale after 30 days without activity and closed 14 days later.
+#
+# Runs in dry-run mode (logs candidates only) until the repository variable
+# PR_STALE_ENABLED is set to `true`, so the first runs can be reviewed before anything closes.
+on:
+ schedule:
+ - cron: '17 3 * * *'
+ workflow_dispatch: {}
+
+concurrency:
+ group: pr-stale
+
+permissions:
+ # actions/stale persists its scan cursor in the Actions cache between runs.
+ actions: write
+ contents: read
+ issues: write
+ pull-requests: write
+
+jobs:
+ stale:
+ runs-on: ubuntu-latest
+ timeout-minutes: 10
+ env:
+ DRY_RUN: ${{ vars.PR_STALE_ENABLED != 'true' }}
+ steps:
+ - name: Checkout scripts
+ uses: actions/checkout@v7
+ with:
+ # Cone mode also checks out files directly under .github/, including maintainers.txt.
+ sparse-checkout: .github/scripts
+
+ - name: Close incomplete PRs
+ uses: actions/github-script@v8
+ with:
+ script: |
+ const check = require(`${process.env.GITHUB_WORKSPACE}/.github/scripts/pr-admission-check.cjs`);
+ await check.closeIncomplete({ context, core, dryRun: process.env.DRY_RUN === 'true', github });
+
+ - name: Close inactive PRs
+ uses: actions/stale@v11
+ with:
+ debug-only: ${{ env.DRY_RUN }}
+ days-before-issue-stale: -1
+ days-before-issue-close: -1
+ days-before-pr-stale: 30
+ days-before-pr-close: 14
+ exempt-pr-labels: keep-open,pr:incomplete
+ exempt-draft-pr: true
+ stale-pr-label: stale
+ stale-pr-message: >-
+ This PR has had no activity for 30 days. It will be closed in 14 days unless it is
+ updated or labeled `keep-open`.
+ close-pr-message: >-
+ Closing after 44 days without activity. Feel free to reopen when you pick it up again.
+ operations-per-run: 200
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 85cbfa0ad58..eec71086b87 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -66,6 +66,7 @@ jobs:
.github/scripts/vercel-ignored-build-step.test.cjs \
.github/scripts/bundle-size-gate.test.cjs \
.github/scripts/size-gate-comment.test.cjs \
+ .github/scripts/pr-admission-check.test.cjs \
.github/scripts/mergeAllowBuilds.test.mjs \
.github/scripts/desktop-core-gate.test.mjs