-
Notifications
You must be signed in to change notification settings - Fork 1
78 lines (73 loc) · 3.09 KB
/
Copy pathclaude-code.yml
File metadata and controls
78 lines (73 loc) · 3.09 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
name: Claude Code
on:
workflow_dispatch:
issue_comment:
types: [created]
pull_request_review_comment:
types: [created]
issues:
types: [opened, assigned]
pull_request_review:
types: [submitted]
jobs:
claude:
if: |
(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 == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude'))) ||
(github.event_name == 'issues' && github.event.action == 'assigned' && github.event.assignee.login == 'claude[bot]')
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
actions: read
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 1
- name: Set up global Claude config
env:
GH_TOKEN: ${{ secrets.CROSS_REPO_PAT }}
run: |
mkdir -p ~/.claude
gh api repos/drewster99/dev-ops/contents/claude-rules/base.md \
--jq '.content' | base64 -d > ~/.claude/CLAUDE.md
echo "" >> ~/.claude/CLAUDE.md
gh api repos/drewster99/dev-ops/contents/claude-rules/ci.md \
--jq '.content' | base64 -d >> ~/.claude/CLAUDE.md
- name: Run Claude Code
id: claude
uses: anthropics/claude-code-action@v1
with:
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
additional_permissions: |
actions: read
- name: Auto-create PR if Claude pushed a branch
if: github.event_name == 'issues' || (github.event_name == 'issue_comment' && !github.event.issue.pull_request)
env:
GH_TOKEN: ${{ github.token }}
ISSUE_NUMBER: ${{ github.event.issue.number }}
run: |
git fetch origin --no-tags
BRANCH=$(git branch -r --list "origin/claude/issue-${ISSUE_NUMBER}-*" | head -1 | xargs)
if [ -z "$BRANCH" ]; then
echo "No Claude branch found for issue #${ISSUE_NUMBER}, skipping PR creation."
exit 0
fi
LOCAL_BRANCH="${BRANCH#origin/}"
EXISTING_PR=$(gh pr list --head "$LOCAL_BRANCH" --json number --jq '.[0].number' 2>/dev/null)
if [ -n "$EXISTING_PR" ]; then
echo "PR #${EXISTING_PR} already exists for branch ${LOCAL_BRANCH}."
exit 0
fi
echo "Creating PR from ${LOCAL_BRANCH} for issue #${ISSUE_NUMBER}..."
PR_BODY=$(printf 'Resolves #%s\n\nAuto-generated by Claude Code from issue #%s.' "$ISSUE_NUMBER" "$ISSUE_NUMBER")
gh pr create \
--head "$LOCAL_BRANCH" \
--title "$(gh issue view "$ISSUE_NUMBER" --json title --jq .title)" \
--body "$PR_BODY" \
|| echo "PR creation failed -- Claude may not have pushed commits."