mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-07-08 13:55:14 +02:00
Allow targeted contribution policy runs
This commit is contained in:
@@ -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 }) {
|
async function run({ github, context, core }) {
|
||||||
const { owner, repo } = context.repo;
|
const { owner, repo } = context.repo;
|
||||||
const payloadPr = context.payload.pull_request;
|
const payloadPr = context.payload.pull_request;
|
||||||
@@ -689,14 +706,32 @@ async function run({ github, context, core }) {
|
|||||||
context.eventName === "workflow_dispatch" &&
|
context.eventName === "workflow_dispatch" &&
|
||||||
dryRunInput !== false &&
|
dryRunInput !== false &&
|
||||||
dryRunInput !== "false";
|
dryRunInput !== "false";
|
||||||
|
let pullNumbers;
|
||||||
|
|
||||||
|
if (payloadPr != null) {
|
||||||
|
pullNumbers = [payloadPr.number];
|
||||||
|
} else {
|
||||||
|
pullNumbers = getManualPullRequestNumbers({ context, core });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pullNumbers?.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const pullRequests =
|
const pullRequests =
|
||||||
payloadPr == null
|
pullNumbers == null
|
||||||
? await listOpenPullRequests({ github, owner, repo })
|
? await listOpenPullRequests({ github, owner, repo })
|
||||||
: [payloadPr];
|
: pullNumbers.map((number) => ({ number }));
|
||||||
const results = [];
|
const results = [];
|
||||||
|
|
||||||
if (dryRun) {
|
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) {
|
for (const pr of pullRequests) {
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ name: Contribution Policy
|
|||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
inputs:
|
inputs:
|
||||||
|
pr:
|
||||||
|
description: PR number to check, or "all" for every open PR
|
||||||
|
required: true
|
||||||
|
default: all
|
||||||
|
type: string
|
||||||
dry_run:
|
dry_run:
|
||||||
description: Preview labels and comments without changing PRs
|
description: Preview labels and comments without changing PRs
|
||||||
required: true
|
required: true
|
||||||
|
|||||||
Reference in New Issue
Block a user