Skip to content

[SOURCE-193] Add Claude PR review workflow#36896

Open
xopham wants to merge 3 commits into
masterfrom
christoph.hamsen/SOURCE-193/add-claude-review-workflow
Open

[SOURCE-193] Add Claude PR review workflow#36896
xopham wants to merge 3 commits into
masterfrom
christoph.hamsen/SOURCE-193/add-claude-review-workflow

Conversation

@xopham
Copy link
Copy Markdown
Contributor

@xopham xopham commented May 21, 2026

Summary

Brings the read-only Claude review pipeline over from the sandbox repo (DataDog/docs-actions-sandbox-xopham). Comment /review on a PR to have Claude produce a JSON review payload that the post job sanitizes and submits via the GitHub API.

Security model — three-job split

Job Permissions What it does
gate contents: read, pull-requests: read Verifies the commenter has repo write access via collaborators/.../permission; resolves head_sha + base_sha once.
review contents: read, pull-requests: read (no write) Runs Claude with --allowedTools "Read,Glob,Grep" only. PR head lives in __untrusted/, the pinned diff in __untrusted_diff/. Trusted scripts/schemas/style guide come from the default branch.
post contents: read, pull-requests: write Re-validates the JSON via Ajv against .github/schemas/create-review.json, re-scans for GitHub + Anthropic token patterns, submits a single review through pulls.createReview.

Failure cases (token leaks, malformed JSON, missing artifact) produce a failure-shape review comment with a workflow-run link.

Prerequisites

  • CLAUDE_API_KEY repo secret must be set before the workflow can run successfully.

Files added

  • .github/workflows/claude_review.yml
  • .github/scripts/validate_review.js — Ajv shape check
  • .github/scripts/scan_secrets.js — GitHub + Anthropic token-pattern regex list
  • .github/scripts/package.json + package-lock.json — pinned ajv 8.20.0, SHA-512 verified via npm ci
  • .github/scripts/.gitignorenode_modules/ plus a negation that overrides the repo-level package-lock.json exclude (the lockfile is what npm ci uses for integrity)
  • .github/schemas/create-review.json — vendored slice of GitHub's pulls.createReview request body
  • .claude/pr-review.md — review style guide

Test plan

  • Confirm CLAUDE_API_KEY is configured as a repo secret
  • Comment /review on a small docs PR; gate should pass for write-access commenters
  • Confirm the review job runs with Read,Glob,Grep only
  • Confirm the post job submits a single review with the transparency header and inline comments
  • Re-run on a draft/in-progress PR; confirm concurrency cancels the prior run only when both are /review triggers

🤖 Generated with Claude Code

Brings the read-only Claude review pipeline over from the sandbox repo
(DataDog/docs-actions-sandbox-xopham). Comment `/review` on a PR to
trigger Claude to produce a JSON review payload that the post job
sanitizes and submits via the GitHub API.

Three-job security model:
- gate (contents: read, pull-requests: read): verifies the commenter
  has repo write access via the collaborators/.../permission API and
  resolves head_sha/base_sha once.
- review (contents: read, pull-requests: read): runs Claude with
  --allowedTools "Read,Glob,Grep" only and no write capability on
  GitHub. The PR head lives in __untrusted/, the pinned PR diff in
  __untrusted_diff/, and the trusted scripts/schemas/style guide are
  sparse-checked out from the default branch.
- post (contents: read, pull-requests: write): re-validates the JSON
  against .github/schemas/create-review.json (Ajv with SHA-512 pinned
  via npm ci), re-scans for GitHub/Anthropic token patterns, and
  submits a single review through pulls.createReview.

Requires the CLAUDE_API_KEY repo secret. Falls back to a failure-shape
review comment with a workflow-run link if anything fails.

Files added:
- .github/workflows/claude_review.yml
- .github/scripts/validate_review.js (Ajv shape check)
- .github/scripts/scan_secrets.js (GitHub + Anthropic token patterns)
- .github/scripts/package.json + package-lock.json (pinned ajv 8.20.0)
- .github/scripts/.gitignore (node_modules; overrides repo-level
  package-lock.json exclude)
- .github/schemas/create-review.json (vendored slice of GitHub's
  pulls.createReview request body)
- .claude/pr-review.md (review style guide)

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@xopham xopham requested review from a team as code owners May 21, 2026 09:57
@github-actions github-actions Bot added the Github Related to Github configurations label May 21, 2026
@xopham xopham requested a review from KSerrania May 21, 2026 10:01
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8387723671

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread .github/workflows/claude_review.yml Outdated
Comment thread .github/schemas/create-review.json Outdated
Comment thread .github/workflows/claude_review.yml
Copy link
Copy Markdown
Contributor

@KSerrania KSerrania left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Codex comments look accurate to me and should be looked at, otherwise LGTM

Comment thread .github/workflows/claude_review.yml
xopham and others added 2 commits May 21, 2026 13:51
Four changes from PR review:

1. Narrow `.claude/` sparse-checkout to just `pr-review.md`. The repo's
   `.claude/settings.json` enables Claude Code plugins from external
   marketplaces, which can register hooks, MCP servers, and agents that
   would expand the review job's tool surface beyond Read,Glob,Grep.

2. Lock the read-only tool surface from four angles in `claude_args`:
   `--tools "Read,Glob,Grep"` (restricts available set),
   `--allowedTools "Read,Glob,Grep"` (auto-approves them),
   `--permission-mode dontAsk` (blocks permission prompts),
   `--disallowedTools "Bash,Edit,Write,MultiEdit,NotebookEdit"`
   (explicit denial). `--allowedTools` alone only pre-approves; the
   additional flags make the restriction explicit and survive future
   Claude Code default changes.

3. Constrain `side` and `start_side` to LEFT/RIGHT in the review
   schema. Upstream publishes them as plain strings with an example,
   but the runtime API rejects any other value and fails the whole
   review. The enum catches typos like `right` at the schema layer.

4. Add CODEOWNERS entries giving @DataDog/sdlc-security sole ownership
   of the workflow, scripts, and schema. `.claude/pr-review.md` stays
   on the default ownership since it is review instructions, not part
   of the security boundary.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Pinned to commit 20c8abf165d5f85ab3fc970db9498436377dc9d1
(released 2026-05-21, the current latest).

No automated bumper for this in the repo — Dependabot/Renovate aren't
configured. Manual bump.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

@devindford devindford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good from my side of things

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Github Related to Github configurations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants