Allow targeted contribution policy runs

This commit is contained in:
Gregory Schier
2026-06-30 14:25:41 -07:00
parent f32e9f7704
commit 8724260eb4
2 changed files with 43 additions and 3 deletions
+38 -3
View File
@@ -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) {
@@ -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