From 79046e77e1449ea4b77f9f5ae81e7c647aca2672 Mon Sep 17 00:00:00 2001 From: Simple Analytics Agent <343555763+simpleanalytics-agent@users.noreply.github.com> Date: Wed, 18 Nov 2026 16:38:57 +0100 Subject: [PATCH 1/2] Skip pull requests from forks and stop rewriting the SDLC labels Pull requests from forks get a read-only token and no secrets, so the label step failed with a 403 and Claude could not classify them. The labels already exist, and adding a label creates it when missing. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/pull-request.yml | 48 +----------------------------- README.md | 2 ++ test/pull-request-policy.test.mjs | 16 +++++++--- 3 files changed, 15 insertions(+), 51 deletions(-) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index ea7b6c5..58f4e71 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -31,7 +31,7 @@ jobs: sdlc-label: runs-on: ubuntu-latest if: >- - ${{ !github.event.pull_request.draft && github.event_name == 'pull_request' && (contains(fromJson('["opened", "reopened", "synchronize", "ready_for_review"]'), github.event.action) || (github.event.action == 'labeled' && github.event.label.name == 'change: needs review')) }} + ${{ !github.event.pull_request.draft && github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository && (contains(fromJson('["opened", "reopened", "synchronize", "ready_for_review"]'), github.event.action) || (github.event.action == 'labeled' && github.event.label.name == 'change: needs review')) }} concurrency: group: sdlc-label-${{ github.repository }}-${{ github.event.pull_request.number }} cancel-in-progress: false @@ -41,52 +41,6 @@ jobs: pull-requests: write issues: write steps: - - name: Ensure SDLC labels - uses: actions/github-script@v9 - with: - script: | - const labels = [ - { - name: 'change: needs review', - color: 'b60205', - description: 'Significant or emergency change affecting security, data protection, or stability', - }, - { - name: 'change: routine', - color: 'fbca04', - description: 'Routine or ordinary change that needs at most one human or AI-assisted review', - }, - ]; - - for (const label of labels) { - try { - await github.rest.issues.getLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - name: label.name, - }); - - await github.rest.issues.updateLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - name: label.name, - new_name: label.name, - color: label.color, - description: label.description, - }); - } catch (error) { - if (error.status !== 404) throw error; - - await github.rest.issues.createLabel({ - owner: context.repo.owner, - repo: context.repo.repo, - name: label.name, - color: label.color, - description: label.description, - }); - } - } - - name: Prepare SDLC classification id: classification uses: actions/github-script@v9 diff --git a/README.md b/README.md index 0285a48..0380e99 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,8 @@ On the first run, Claude reads the full PR diff and returns `change: routine` or Draft PRs are skipped until they are ready for review. When a PR gets `change: needs review`, from Claude or by hand, the workflow requests a human reviewer. +PRs from forks are skipped, because GitHub gives their workflows a read-only token and no secrets. Label them by hand and request a reviewer yourself when one needs review. + The prompt maps the four release risk levels of the Software Release and Deployment Procedure onto the two labels and includes notes per repository. Add a note to the prompt when a repository needs specific guidance. Set `internal_app: true` for an internal app without a repository note, so changes that do not touch personal data or security stay `change: routine`. The workflow defaults to `claude-haiku-5-5`; override it with `claude_model`. diff --git a/test/pull-request-policy.test.mjs b/test/pull-request-policy.test.mjs index 7d4d31d..55ef972 100644 --- a/test/pull-request-policy.test.mjs +++ b/test/pull-request-policy.test.mjs @@ -689,7 +689,7 @@ test("a failed reviewer request remains visible as a workflow failure", async () assert.deepEqual(state.mutations, []); }); -test("manual needs-review labels and ready drafts trigger the shared job", () => { +test("manual needs-review labels and ready drafts trigger the shared job, but forks do not", () => { const expression = workflow.match( /^ if: >-\n \$\{\{ (.+) \}\}$/m, )?.[1]; @@ -700,7 +700,8 @@ test("manual needs-review labels and ready drafts trigger the shared job", () => "fromJson", `return (${expression});`, ); - for (const [action, label, draft, expected] of [ + const repository = "simpleanalytics/example"; + for (const [action, label, draft, expected, headRepository = repository] of [ ["opened", undefined, false, true], ["reopened", undefined, false, true], ["synchronize", undefined, false, true], @@ -710,15 +711,22 @@ test("manual needs-review labels and ready drafts trigger the shared job", () => ["labeled", "bug", false, false], ["labeled", needsReview, true, false], ["closed", undefined, false, false], + ["opened", undefined, false, false, "contributor/example"], + ["labeled", needsReview, false, false, "contributor/example"], ]) { const github = { event_name: "pull_request", - event: { action, label: { name: label }, pull_request: { draft } }, + repository, + event: { + action, + label: { name: label }, + pull_request: { draft, head: { repo: { full_name: headRepository } } }, + }, }; assert.equal( shouldRun(github, (values, value) => values.includes(value), JSON.parse), expected, - `${action}: ${label}, draft=${draft}`, + `${action}: ${label}, draft=${draft}, head=${headRepository}`, ); } }); From b8d74b0016ae42683d6b342b42032120edccef26 Mon Sep 17 00:00:00 2001 From: Simple Analytics Agent <343555763+simpleanalytics-agent@users.noreply.github.com> Date: Wed, 18 Nov 2026 17:12:26 +0100 Subject: [PATCH 2/2] Create the SDLC labels when a repository does not have them yet Existing labels keep their color and description, so the step only reads them and needs no write access when the labels exist. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/pull-request.yml | 26 +++++++++++++++++++ test/pull-request-policy.test.mjs | 41 ++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 58f4e71..f354d24 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -41,6 +41,32 @@ jobs: pull-requests: write issues: write steps: + - name: Create missing SDLC labels + uses: actions/github-script@v9 + with: + script: | + const labels = [ + { + name: 'change: needs review', + color: 'b60205', + description: 'Significant or emergency change affecting security, data protection, or stability', + }, + { + name: 'change: routine', + color: 'fbca04', + description: 'Routine or ordinary change that needs at most one human or AI-assisted review', + }, + ]; + + for (const label of labels) { + try { + await github.rest.issues.getLabel({ ...context.repo, name: label.name }); + } catch (error) { + if (error.status !== 404) throw error; + await github.rest.issues.createLabel({ ...context.repo, ...label }); + } + } + - name: Prepare SDLC classification id: classification uses: actions/github-script@v9 diff --git a/test/pull-request-policy.test.mjs b/test/pull-request-policy.test.mjs index 55ef972..b1c672d 100644 --- a/test/pull-request-policy.test.mjs +++ b/test/pull-request-policy.test.mjs @@ -107,6 +107,7 @@ function githubScriptFor(stepName) { } const prepareClassification = githubScriptFor("Prepare SDLC classification"); +const createMissingLabels = githubScriptFor("Create missing SDLC labels"); const finalizeLabel = githubScriptFor("Finalize SDLC label"); const requestReview = githubScriptFor("Request human review"); const routine = "change: routine"; @@ -689,6 +690,46 @@ test("a failed reviewer request remains visible as a workflow failure", async () assert.deepEqual(state.mutations, []); }); +test("missing SDLC labels are created and existing labels stay as they are", async () => { + const created = []; + const github = { + rest: { + issues: { + async getLabel({ name }) { + if (name === needsReview) return { data: { name } }; + throw Object.assign(new Error("Not Found"), { status: 404 }); + }, + async createLabel(label) { + created.push(label); + }, + }, + }, + }; + const context = { repo: { owner: "simpleanalytics", repo: "dashboard" } }; + await createMissingLabels(github, context); + assert.deepEqual(created, [ + { + owner: "simpleanalytics", + repo: "dashboard", + name: routine, + color: "fbca04", + description: + "Routine or ordinary change that needs at most one human or AI-assisted review", + }, + ]); + + github.rest.issues.getLabel = async () => { + throw Object.assign(new Error("Resource not accessible by integration"), { + status: 403, + }); + }; + await assert.rejects( + createMissingLabels(github, context), + /Resource not accessible/, + ); + assert.equal(created.length, 1); +}); + test("manual needs-review labels and ready drafts trigger the shared job, but forks do not", () => { const expression = workflow.match( /^ if: >-\n \$\{\{ (.+) \}\}$/m,