Skip to content

Commit 1713c27

Browse files
Add Claude Code workflow for AI-assisted PR reviews
Add a GitHub Actions workflow that provides AI-assisted PR reviews and interactive @claude mentions using Claude Code backed by Databricks Model Serving. The workflow dispatches to eng-dev-ecosystem's protected runners (whose IPs are allowlisted by the Databricks account IP ACL) via the DECO workflow trigger GitHub App. Two modes: - Review: automatic on PR open, posts a review comment - Assist: triggered by @claude mentions, can edit code and push Access is restricted to COLLABORATOR/MEMBER/OWNER via author_association allowlists. Co-authored-by: Isaac
1 parent 3f3cc2b commit 1713c27

1 file changed

Lines changed: 135 additions & 0 deletions

File tree

.github/workflows/claude-code.yml

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
name: Claude Code
2+
3+
# AI-assisted PR reviews and interactive @claude mentions.
4+
#
5+
# The actual Claude Code execution runs in eng-dev-ecosystem on
6+
# protected runners whose IPs are allowlisted by the Databricks
7+
# account IP ACL. This workflow is a thin trigger that dispatches
8+
# to eng-dev-ecosystem via the DECO workflow trigger GitHub App.
9+
10+
on:
11+
# Triggers automatic review when a PR is first opened.
12+
pull_request:
13+
types: [opened]
14+
15+
# Enables @claude mentions in PR conversation comments.
16+
# (GitHub fires issue_comment for top-level PR comments.)
17+
issue_comment:
18+
types: [created]
19+
20+
# Enables @claude mentions in inline review comments.
21+
pull_request_review_comment:
22+
types: [created]
23+
24+
jobs:
25+
# Automatic review on PR open. For re-reviews, comment "@claude review".
26+
# Restrict to org members/owners to prevent untrusted users (e.g. external
27+
# fork PRs) from consuming model serving resources. See:
28+
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
29+
review:
30+
if: |
31+
github.event_name == 'pull_request' &&
32+
!github.event.pull_request.head.repo.fork &&
33+
contains(fromJson('["MEMBER","OWNER"]'), github.event.pull_request.author_association)
34+
concurrency:
35+
group: claude-review-${{ github.event.pull_request.number }}
36+
cancel-in-progress: true
37+
runs-on:
38+
group: databricks-deco-testing-runner-group
39+
labels: ubuntu-latest-deco
40+
environment: test-trigger-is
41+
permissions:
42+
contents: read
43+
44+
steps:
45+
- name: Generate GitHub App token
46+
id: token
47+
uses: actions/create-github-app-token@v2
48+
with:
49+
app-id: ${{ secrets.DECO_WORKFLOW_TRIGGER_APP_ID }}
50+
private-key: ${{ secrets.DECO_WORKFLOW_TRIGGER_PRIVATE_KEY }}
51+
owner: databricks-eng
52+
repositories: eng-dev-ecosystem
53+
54+
- name: Trigger Claude Code review
55+
run: |
56+
gh workflow run cli-claude-code.yml \
57+
-R databricks-eng/eng-dev-ecosystem \
58+
--ref main \
59+
-F pull_request_number=${{ github.event.pull_request.number }} \
60+
-F event_type=review
61+
env:
62+
GH_TOKEN: ${{ steps.token.outputs.token }}
63+
64+
# Interactive @claude mentions (PRs only, trusted authors only).
65+
# Restrict to org members/owners to prevent untrusted users from triggering
66+
# Claude with write access to the repo. See:
67+
# https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/
68+
assist:
69+
if: |
70+
github.event.comment.user.type != 'Bot' &&
71+
contains(fromJson('["MEMBER","OWNER"]'), github.event.comment.author_association) &&
72+
(
73+
(github.event_name == 'issue_comment' && github.event.issue.pull_request && contains(github.event.comment.body, '@claude')) ||
74+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude'))
75+
)
76+
runs-on:
77+
group: databricks-deco-testing-runner-group
78+
labels: ubuntu-latest-deco
79+
environment: test-trigger-is
80+
permissions:
81+
contents: read
82+
83+
steps:
84+
- name: Generate GitHub App token
85+
id: token
86+
uses: actions/create-github-app-token@v2
87+
with:
88+
app-id: ${{ secrets.DECO_WORKFLOW_TRIGGER_APP_ID }}
89+
private-key: ${{ secrets.DECO_WORKFLOW_TRIGGER_PRIVATE_KEY }}
90+
owner: databricks-eng
91+
repositories: eng-dev-ecosystem
92+
93+
- name: Determine PR number
94+
id: pr
95+
run: |
96+
if [ -n "$ISSUE_NUMBER" ]; then
97+
echo "number=$ISSUE_NUMBER" >> "$GITHUB_OUTPUT"
98+
else
99+
echo "number=$PR_NUMBER" >> "$GITHUB_OUTPUT"
100+
fi
101+
env:
102+
ISSUE_NUMBER: ${{ github.event.issue.number }}
103+
PR_NUMBER: ${{ github.event.pull_request.number }}
104+
105+
# Skip fork PRs to avoid running Claude against untrusted code.
106+
# Comment events don't expose fork info in the `if` condition,
107+
# so we check via API.
108+
- name: Check if fork PR
109+
id: fork-check
110+
run: |
111+
IS_FORK=$(gh pr view "$PR_NUMBER" --json isCrossRepository --jq '.isCrossRepository')
112+
echo "is_fork=$IS_FORK" >> "$GITHUB_OUTPUT"
113+
env:
114+
PR_NUMBER: ${{ steps.pr.outputs.number }}
115+
GH_TOKEN: ${{ github.token }}
116+
117+
- name: Trigger Claude Code assist
118+
if: steps.fork-check.outputs.is_fork != 'true'
119+
uses: actions/github-script@v7
120+
with:
121+
github-token: ${{ steps.token.outputs.token }}
122+
script: |
123+
await github.rest.actions.createWorkflowDispatch({
124+
owner: 'databricks-eng',
125+
repo: 'eng-dev-ecosystem',
126+
workflow_id: 'cli-claude-code.yml',
127+
ref: 'main',
128+
inputs: {
129+
pull_request_number: '${{ steps.pr.outputs.number }}',
130+
event_type: 'assist',
131+
comment_body: process.env.COMMENT_BODY
132+
}
133+
});
134+
env:
135+
COMMENT_BODY: ${{ github.event.comment.body }}

0 commit comments

Comments
 (0)