From 8724260eb4ba392cef881cebdf3269a98b83b78b Mon Sep 17 00:00:00 2001 From: Gregory Schier Date: Tue, 30 Jun 2026 14:25:41 -0700 Subject: [PATCH] Allow targeted contribution policy runs --- .github/scripts/check-contribution-policy.js | 41 ++++++++++++++++++-- .github/workflows/contribution-policy.yml | 5 +++ 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/.github/scripts/check-contribution-policy.js b/.github/scripts/check-contribution-policy.js index ac368101..46e893d1 100644 --- a/.github/scripts/check-contribution-policy.js +++ b/.github/scripts/check-contribution-policy.js @@ -681,6 +681,23 @@ async function listOpenPullRequests({ github, owner, repo }) { }); } +function getManualPullRequestNumbers({ context, core }) { + const value = String(context.payload.inputs?.pr || "all").trim(); + + if (value.toLowerCase() === "all") { + return null; + } + + const pullNumber = Number(value); + + if (!Number.isInteger(pullNumber) || pullNumber <= 0) { + core.setFailed('The "pr" input must be "all" or a positive PR number.'); + return []; + } + + return [pullNumber]; +} + async function run({ github, context, core }) { const { owner, repo } = context.repo; const payloadPr = context.payload.pull_request; @@ -689,14 +706,32 @@ async function run({ github, context, core }) { context.eventName === "workflow_dispatch" && dryRunInput !== false && dryRunInput !== "false"; + let pullNumbers; + + if (payloadPr != null) { + pullNumbers = [payloadPr.number]; + } else { + pullNumbers = getManualPullRequestNumbers({ context, core }); + } + + if (pullNumbers?.length === 0) { + return; + } + const pullRequests = - payloadPr == null + pullNumbers == null ? await listOpenPullRequests({ github, owner, repo }) - : [payloadPr]; + : pullNumbers.map((number) => ({ number })); const results = []; if (dryRun) { - core.notice("Running contribution policy in dry-run mode."); + core.notice( + `Running contribution policy in dry-run mode for ${ + pullNumbers == null + ? "all open PRs" + : pullNumbers.map((number) => `#${number}`).join(", ") + }.`, + ); } for (const pr of pullRequests) { diff --git a/.github/workflows/contribution-policy.yml b/.github/workflows/contribution-policy.yml index d68a43c5..c75d74bc 100644 --- a/.github/workflows/contribution-policy.yml +++ b/.github/workflows/contribution-policy.yml @@ -3,6 +3,11 @@ name: Contribution Policy on: workflow_dispatch: inputs: + pr: + description: PR number to check, or "all" for every open PR + required: true + default: all + type: string dry_run: description: Preview labels and comments without changing PRs required: true