Skip to content

Commit 5fe5adf

Browse files
authored
Merge pull request #12 from cipherstash/feat/comment-command
feat: request a Claude review from a team member's comment command
2 parents a3accd7 + 0fc2c42 commit 5fe5adf

82 files changed

Lines changed: 2041 additions & 53 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.github/workflows/claude-review.yml‎

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,17 @@
55
# the calling repository, so the decide job checks out the request decision, request-decision/decision.jq, and the
66
# Python step files in steps/ from this repository at the commit the caller pinned. request-decision/test runs that same
77
# jq file against saved cases, and the unit tests in tests/ run the same step files. The fire job checks out the step
8-
# files the same way and runs the routine call from steps/fire.py.
8+
# files the same way and runs the routine call from steps/fire.py, and the react job checks them out too and runs the
9+
# 👀 reaction from steps/react.py.
910
#
10-
# Kinds of review request handled so far: Ready (a non-draft pull request opened or reopened, or a draft marked ready
11-
# for review). Drafts, bots' pull requests, forks and deleted forks are skipped, and so is a pull request whose author
12-
# is not a team member. A pull request opened by the review agent is reviewed without a membership lookup.
11+
# Kinds of review request handled so far:
12+
# Ready: a non-draft pull request opened or reopened, or a draft marked ready for review. Drafts, bots' pull requests,
13+
# forks and deleted forks are skipped, and so is a pull request whose author is not a team member. A pull request
14+
# opened by the review agent is reviewed without a membership lookup.
15+
# Comment command: a team member's new pull request comment whose first line is `@<review agent> review`, on drafts
16+
# and forks too. The rest of the comment is passed on as instructions, and the comment gets a 👀 reaction once the
17+
# request is sent. Comments by bots and by the review agent are skipped without a lookup, and so are commands on
18+
# closed or merged pull requests.
1319
name: Claude review
1420

1521
on:
@@ -24,7 +30,7 @@ on:
2430
type: string
2531
default: developers
2632
review-agent:
27-
description: The login of the review agent, the account whose pull requests are reviewed without a membership lookup.
33+
description: The login of the review agent, the account mentioned in a comment command, whose pull requests are reviewed without a membership lookup and whose comments never request a review.
2834
type: string
2935
default: cipherstash-agent
3036
secrets:
@@ -185,7 +191,8 @@ jobs:
185191
echo "Claude review: skipped (decision-failed)"
186192
echo "Claude review: skipped (decision-failed)" >>"$GITHUB_STEP_SUMMARY"
187193
188-
# Fires the routine trigger. It holds no permissions and sees only the decision, never the event's free text.
194+
# Fires the routine trigger. It holds no permissions and sees only the decision: the event's free text reaches it only
195+
# as the decision's text, which the send step's json module places in the request body.
189196
fire:
190197
needs: decide
191198
if: fromJSON(needs.decide.outputs.decision).decision == 'fire'
@@ -195,9 +202,14 @@ jobs:
195202
# One request per pull request at a time. A second waits rather than cancelling the first, whose request may already
196203
# have started a session; a third replaces the waiting one. This serialises only the fire request, not the review
197204
# session it starts, so sessions can overlap.
205+
# Every kind of review request puts the pull request's number in the same place, so a Ready request and a comment
206+
# command for one pull request share a group.
198207
concurrency:
199208
group: claude-review-${{ github.repository }}-${{ fromJSON(needs.decide.outputs.decision).pull_request.number }}
200209
cancel-in-progress: false
210+
outputs:
211+
# "true" only when the routine trigger accepted the request.
212+
sent: ${{ steps.send.outputs.sent }}
201213
env:
202214
# Where the checkout step below puts this repository's step files.
203215
WORKFLOW_FILES: ${{ github.workspace }}/.cipherstash-workflows
@@ -240,3 +252,57 @@ jobs:
240252
fi
241253
echo "::error::Could not get the routine call's step file (checkout failed or file missing); no review was requested"
242254
exit 1
255+
256+
# Adds a 👀 reaction to a comment command once its request has been sent, so the requester knows it was received.
257+
# This is the only job that holds a write permission, and it sees only the decision. Reacting to a pull request's
258+
# conversation comment uses the issue-comment reactions endpoint, which GitHub documents as needing "Issues: write".
259+
# The calling job must grant `issues: write`, because a reusable workflow's jobs cannot hold more than their caller.
260+
# The checkout is given no contents permission. This relies on this repository being public, as for the decide and
261+
# fire jobs, which hold no permissions at all; it is to be confirmed by the first live run (#20).
262+
react:
263+
needs: [decide, fire]
264+
if: needs.fire.outputs.sent == 'true' && fromJSON(needs.decide.outputs.decision).react == true
265+
runs-on: ubuntu-latest
266+
timeout-minutes: 5
267+
permissions:
268+
issues: write
269+
env:
270+
# Where the checkout step below puts this repository's step files.
271+
WORKFLOW_FILES: ${{ github.workspace }}/.cipherstash-workflows
272+
steps:
273+
# The reaction's step file, checked out from this repository at the commit the caller pinned, the same way as
274+
# in the decide job: only the steps/ directory, no credentials kept, and skipped if either value is empty.
275+
- name: Check out the step files
276+
id: checkout
277+
if: job.workflow_repository != '' && job.workflow_sha != ''
278+
continue-on-error: true
279+
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
280+
with:
281+
repository: ${{ job.workflow_repository }}
282+
ref: ${{ job.workflow_sha }}
283+
path: .cipherstash-workflows
284+
sparse-checkout: |
285+
/steps/
286+
sparse-checkout-cone-mode: false
287+
persist-credentials: false
288+
289+
- name: React to the comment
290+
id: reaction
291+
# A missing reaction is cosmetic: it shows as a warning, never as a red check.
292+
continue-on-error: true
293+
env:
294+
GITHUB_TOKEN: ${{ github.token }}
295+
DECISION: ${{ needs.decide.outputs.decision }}
296+
CHECKOUT_OUTCOME: ${{ steps.checkout.outcome }}
297+
# The reaction's file, from this repository's checkout. Python's standard library only (3.10 features), so
298+
# nothing is installed; tests/test_react.py runs this file.
299+
STEP_FILE: ${{ env.WORKFLOW_FILES }}/steps/react.py
300+
# Without a successful checkout of the file and the helper module beside it, no reaction is added: the step
301+
# shows a warning and fails, which continue-on-error keeps from turning the check red. The file reports each of
302+
# its own failures, a broken helper module included, as one warning, so its exit status is the step's.
303+
run: |
304+
if [[ "$CHECKOUT_OUTCOME" == success && -f "$STEP_FILE" && -f "${STEP_FILE%/*}/helpers.py" ]]; then
305+
exec python3 "$STEP_FILE"
306+
fi
307+
echo "::warning::Could not get the reaction's step files (checkout failed, or react.py or helpers.py missing); no 👀 reaction was added, but the review was still requested"
308+
exit 1

‎CONTEXT.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ The review request made when a non-draft pull request is opened or reopened, or
1313
_Avoid_: auto review
1414

1515
**Comment command**:
16-
The review request made by a member's comment whose first line starts with `@cipherstash-agent review`; the rest of the comment is the request's instructions.
16+
The review request made by a member's comment whose first line starts, with no leading whitespace, with `@cipherstash-agent review`; the rest of the comment is the request's instructions.
1717
_Avoid_: mention, slash command
1818

1919
**Requested reviewer**:

0 commit comments

Comments
 (0)