Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 8 additions & 4 deletions .github/scripts/native-queue-policy.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
// This is an owned evidence gate, not a publisher of another App's statuses.
const ACTIONS_APP_ID = 15368;
const DCO_APP_ID = 1861;
// The PR-side events the gate may run on. `pull_request_target` is blocked by
// default on public repositories from 2026-12-02, so the plain `pull_request`
// event is accepted beside it.
const PR_EVENTS = ['pull_request', 'pull_request_target'];
const POLICY_CHECKS = {
gate: ['docker.yml', ['push', 'pull_request']],
DCO: null,
Expand All @@ -22,7 +26,7 @@ const SHA = /^[a-f0-9]{40}$/;
const BLOCKED_LABEL = /^(hold|needs-human|release-in-progress|do-not-merge(?:\/.*)?)$/i;
const MAX_QUEUE_PAGES = 10;
const POLICY_CHECK_NAME = 'native-queue-policy';
const POLICY_CHECK_SOURCE = ['native-queue-policy.yml', ['pull_request_target']];
const POLICY_CHECK_SOURCE = ['native-queue-policy.yml', PR_EVENTS];
// Decision B on #17030: a v5→v6 forward-merge opened by v6-topup.yml carries
// commits that already passed v5's DCO gate, and probot DCO cannot be repaired
// PR-side. Only that exact shape may substitute prow's `dco` status.
Expand Down Expand Up @@ -339,7 +343,7 @@ async function evaluate(args) {
// A labeled/unlabeled event only matters when the label is one assertEligible
// reads (BLOCKED_LABEL); every other flip cannot change the verdict.
function isCosmeticLabelFlip({ eventName, payload }) {
return eventName === 'pull_request_target' &&
return PR_EVENTS.includes(eventName) &&
['labeled', 'unlabeled'].includes(payload.action) &&
typeof payload.label?.name === 'string' &&
!BLOCKED_LABEL.test(payload.label.name);
Expand Down Expand Up @@ -391,7 +395,7 @@ async function replayLastVerdict({ github, context, currentCheckRunId }) {

async function evaluateOnce({ github, context }) {
const repo = context.repo;
if (context.eventName === 'pull_request_target') {
if (PR_EVENTS.includes(context.eventName)) {
const event = context.payload.pull_request;
const { data: pr } = await github.rest.pulls.get({ ...repo, pull_number: event.number });
// Post-merge label/comment edits re-fire this event; a closed PR has nothing to gate.
Expand Down Expand Up @@ -443,7 +447,7 @@ async function evaluateOnce({ github, context }) {
module.exports = {
ACTIONS_APP_ID, DCO_APP_ID, POLICY_CHECKS, BUILD_CHECKS,
PendingEvidence, membersForGroup, assertEligible, evidenceForHead, closedNoop, evaluate,
isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict, BLOCKED_LABEL,
isTransientAPIError, isCosmeticLabelFlip, replayLastVerdict, BLOCKED_LABEL, PR_EVENTS,
ProviderUnavailable, ProviderVerdict, PROVIDER_VERDICT_NOTE, FORWARD_MERGE, PROW,
DCO_ENUMERATION_SUMMARY_PREFIX, DCO_ENUMERATION_SUMMARY_FALLBACK,
DCO_PROVIDER_UNAVAILABLE_TEXT, DCO_PROVIDER_RUNBOOK,
Expand Down
16 changes: 13 additions & 3 deletions .github/scripts/native-queue-policy.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,12 @@ test('PR-target admission consumes policy providers without group APIs', async (
assert.equal(f.state.seen.length, 0);
});

test('open PR on the plain pull_request event is evaluated, not rejected as unsupported', async () => {
const f = fixture('pull_request');
assert.match(await evaluate(f), /five existing policy providers/);
assert.equal(f.state.queueReads, 0);
});

test('closed PR on pull_request_target passes as a no-op and skips evidence lookup', async () => {
const f = fixture('pull_request_target');
f.state.prs[0].state = 'closed';
Expand Down Expand Up @@ -422,8 +428,9 @@ test('open PR with moved head still fails closed on pull_request_target', async
});

test('untrusted events and workflow provenance are rejected', async () => {
const f = fixture('pull_request');
await assert.rejects(evaluate(f), /Unsupported/);
for (const eventName of ['push', 'workflow_dispatch', 'issue_comment', 'workflow_run']) {
await assert.rejects(evaluate(fixture(eventName)), /Unsupported/);
}
const g = fixture();
g.state.badWorkflow = '.github/workflows/untrusted.yml';
await assert.rejects(evaluate(g), /Unexpected workflow/);
Expand Down Expand Up @@ -527,6 +534,8 @@ test('isCosmeticLabelFlip is true only for unread labels on label events', () =>
assert.equal(isCosmeticLabelFlip(ctx('pull_request_target', 'synchronize', 'size/L')), false);
assert.equal(isCosmeticLabelFlip(ctx('merge_group', 'checks_requested')), false);
assert.equal(isCosmeticLabelFlip(ctx('pull_request_target', 'labeled')), false);
assert.equal(isCosmeticLabelFlip(ctx('pull_request', 'labeled', 'size/L')), true);
assert.equal(isCosmeticLabelFlip(ctx('pull_request', 'labeled', 'hold')), false);
});

function replayFixture(priorRuns, labels = [], workflowOverride = {}) {
Expand Down Expand Up @@ -646,7 +655,8 @@ test('replay rejects a same-named success run from another workflow', async () =
const run = { id: 7, status: 'completed', conclusion: 'success' };
for (const override of [
{ path: '.github/workflows/forged.yml' },
{ event: 'pull_request' },
{ event: 'workflow_dispatch' },
{ event: 'push' },
{ head_sha: sha(99) },
{ check_suite_id: 1 },
]) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed the `native-queue-policy` check failing with `Unsupported policy event` on PRs whose head carries v5's newer workflow, such as the v5 to v6 top-up (#19100). v5 moved the gate from `pull_request_target` to plain `pull_request` (GitHub blocks `pull_request_target` by default on public repositories from 2026-12-02), but the workflow runs the script from the base branch, so v6's script rejected the event. The v6 script now accepts both events.
Loading