Skip to content
Merged
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
28 changes: 4 additions & 24 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,7 +41,7 @@ jobs:
pull-requests: write
issues: write
steps:
- name: Ensure SDLC labels
- name: Create missing SDLC labels
uses: actions/github-script@v9
with:
script: |
Expand All @@ -60,30 +60,10 @@ jobs:

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,
});
await github.rest.issues.getLabel({ ...context.repo, name: label.name });
} 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,
});
await github.rest.issues.createLabel({ ...context.repo, ...label });
}
}

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
57 changes: 53 additions & 4 deletions test/pull-request-policy.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -689,7 +690,47 @@ 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("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,
)?.[1];
Expand All @@ -700,7 +741,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],
Expand All @@ -710,15 +752,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}`,
);
}
});
Loading