Repository navigation
103 lines (97 loc) · 6.49 KB
/
Copy pathcode-review.yml
File metadata and controls
103 lines (97 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
name: Code review
# Reviews each pull request with NCode Review (NCodeGroup/code-review), which posts as ncode-review[bot]: a "Code review"
# check run, a summary comment with a verdict, and inline threads. Nothing requires it; its findings are advice. It
# reviews a pull request when it opens (drafts included, since that's when its author reviews it) and when it's marked
# ready, unless that commit was already reviewed; pushes in between start nothing. A top-level `/review` comment from
# someone with write access reviews the latest commit on demand; `/review explain F3` says whether a finding still holds,
# and `/review teach <rule>` files a rule as an issue, both on a closed pull request too. A `skip-review` label skips
# the automatic reviews. When a pull request closes, merged or not, the outcomes job only records each posted finding's
# outcome, with no model call. It needs no environment: the app's key is an organization secret, and the code-review
# environment holds none; it only lets Anthropic's federation rule trust the review job.
#
# pull_request_target and issue_comment both run this file from the default branch, so a pull request can't change its
# own review. The engine fetches its code only to read it: nothing from it is built, run or installed.
#
# This file is yours: template updates show their changes to it and leave your copy alone, so a pin you bumped isn't
# moved back. The action is pinned to a release's full commit SHA, with its tag in a comment: never a tag, a branch or
# a floating major, because it receives the organization's keys, and a SHA is the one pin nobody can move. CodeQL's
# extended suite reports any other pin as actions/unpinned-tag. Dependabot's github-actions entry opens each bump and
# updates the SHA and the tag.
# Run tools/Enable-CodeReview.ps1 from a clone of NCodeGroup/code-review once for this repository: it creates the
# code-review environment, which only the default branch can deploy to, and gives the repository access to the
# organization's two secrets.
on:
pull_request_target:
types: [opened, reopened, ready_for_review, closed]
issue_comment:
types: [created]
permissions: {}
jobs:
review:
# The engine checks a comment again (`/review`, `/review explain` or `/review teach`, from a writer, on a pull request
# that isn't from a fork) and stops before any model call when it isn't one. A closed pull request goes to the
# outcomes job below instead, and a plain `/review` on one doesn't run, so it can't cancel or displace the outcomes
# job, which shares its concurrency group. The concurrency group below names no command: it keys on a comment whose
# first line is exactly `/review`.
if: >-
(github.event_name == 'pull_request_target' && github.event.action != 'closed' &&
github.event.pull_request.head.repo.full_name == github.repository &&
github.event.sender.type != 'Bot' && !contains(github.event.pull_request.labels.*.name, 'skip-review')) ||
(github.event_name == 'issue_comment' && github.event.sender.type != 'Bot' && github.event.issue.pull_request &&
startsWith(github.event.comment.body, '/review') &&
(github.event.issue.state == 'open' || startsWith(github.event.comment.body, '/review explain') ||
startsWith(github.event.comment.body, '/review teach')) &&
contains(fromJSON('["OWNER", "MEMBER", "COLLABORATOR"]'), github.event.comment.author_association))
runs-on: ubuntu-latest
# Anthropic's federation rule trusts only jobs in this environment, which only the default branch can deploy to.
environment: code-review
timeout-minutes: 30
# Only a comment whose first line is exactly `/review` joins the pull request's group, where a newer review cancels
# the one in progress. Any other comment, `/review explain` and `/review teach` included, runs in a group of its own
# and never cancels a review. Lines after `/review`, such as an agent's `---` footer, are allowed, so the expression
# accepts `/review` followed by `\n` or `\r\n`. It is the v1.1.2 caller's (ADR-1001 in NCodeGroup/code-review).
concurrency:
group: code-review-${{ github.event_name == 'issue_comment' && !(github.event.comment.body == '/review' || startsWith(github.event.comment.body, format('/review{0}', fromJSON('"\n"'))) || startsWith(github.event.comment.body, format('/review{0}', fromJSON('"\r\n"')))) && format('command-{0}', github.event.comment.id) || github.event.pull_request.number || github.event.issue.number }}
cancel-in-progress: true
permissions:
id-token: write
contents: read
# The issues a pull request closes are context for its intent, and synthesis links a finding to an open issue
# that already tracks it.
issues: read
pull-requests: read
steps:
- name: Check out the default branch for the conventions
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
path: base
persist-credentials: false
- name: Review
# v1.1.2 was published on 2026-11-02, inside the 3-day dependency cooldown: adopted at the maintainer's request.
uses: NCodeGroup/code-review@da82720a1fb582551e8d460ddd277f3cdc8b43f1 # v1.4.2
with:
app-private-key: ${{ secrets.NCODE_REVIEW_APP_PRIVATE_KEY }}
bedrock-api-key: ${{ secrets.AWS_BEARER_TOKEN_BEDROCK }}
outcomes:
# A closed pull request, merged or not, whoever closed it (a merge queue merges as a bot) and whatever its labels:
# records what became of each finding, by rules alone. It makes no model call, so it runs outside the code-review
# environment, without id-token: write, the Bedrock key or a checkout.
if: >-
github.event_name == 'pull_request_target' && github.event.action == 'closed' &&
github.event.pull_request.head.repo.full_name == github.repository
runs-on: ubuntu-latest
timeout-minutes: 10
# The review's group: it waits for a review in progress, so that review's threads are counted, instead of cancelling
# it.
concurrency:
group: code-review-${{ github.event.pull_request.number }}
cancel-in-progress: false
permissions:
contents: read
pull-requests: read
steps:
- name: Record the outcomes
# v1.1.2 was published on 2026-11-02, inside the 3-day dependency cooldown: adopted at the maintainer's request.
uses: NCodeGroup/code-review@da82720a1fb582551e8d460ddd277f3cdc8b43f1 # v1.4.2
with:
app-private-key: ${{ secrets.NCODE_REVIEW_APP_PRIVATE_KEY }}