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
18 changes: 15 additions & 3 deletions .github/workflows/claude.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,21 @@ jobs:
claude:
if: |
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude'))
(
github.event_name == 'issue_comment' &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association) &&
contains(github.event.comment.body, '@claude')
) ||
(
github.event_name == 'pull_request_review_comment' &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association) &&
contains(github.event.comment.body, '@claude')
) ||
(
github.event_name == 'pull_request_review' &&
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.review.author_association) &&
contains(github.event.review.body, '@claude')
)
runs-on:
- self-hosted
- linux
Expand Down
25 changes: 25 additions & 0 deletions test/workflow.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,31 @@ describe("CI workflow", () => {
expect(workflow.jobs["ci-gate"]["runs-on"]).toEqual(shellSafePublicRunner);
});

test("restricts Claude comment triggers to trusted repository actors", () => {
const workflow = YAML.parse(
fs.readFileSync(path.resolve(".github/workflows/claude.yml"), "utf8")
) as {
jobs: Record<string, Record<string, unknown>>;
};

const claudeJob = workflow.jobs.claude;
const condition = String(claudeJob.if);

expect(claudeJob["runs-on"]).toEqual(shellSafePublicRunner);
expect(condition).toContain("github.event_name == 'workflow_dispatch'");
expect(condition).toContain(
"contains(fromJSON('[\"OWNER\",\"MEMBER\",\"COLLABORATOR\"]'), github.event.comment.author_association)"
);
expect(condition).toContain(
"contains(fromJSON('[\"OWNER\",\"MEMBER\",\"COLLABORATOR\"]'), github.event.review.author_association)"
);
expect(condition).toContain("contains(github.event.comment.body, '@claude')");
expect(condition).toContain("contains(github.event.review.body, '@claude')");
expect(condition).not.toContain("FIRST_TIME_CONTRIBUTOR");
expect(condition).not.toContain("CONTRIBUTOR");
expect(condition).not.toContain("NONE");
});

test("renders the Linux Docker contract on shell-safe self-hosted Linux", () => {
const workflow = YAML.parse(
fs.readFileSync(path.resolve(".github/workflows/ci.yml"), "utf8")
Expand Down
Loading