Add Claude Code workflow
This commit is contained in:
91
.gitea/workflows/claude.yml
Normal file
91
.gitea/workflows/claude.yml
Normal file
@@ -0,0 +1,91 @@
|
||||
name: Claude Code Assistant
|
||||
|
||||
on:
|
||||
issues:
|
||||
types: [opened, labeled]
|
||||
issue_comment:
|
||||
types: [created]
|
||||
|
||||
jobs:
|
||||
claude-code:
|
||||
if: |
|
||||
(github.event_name == 'issues' &&
|
||||
contains(github.event.issue.labels.*.name, 'claude')) ||
|
||||
(github.event_name == 'issue_comment' &&
|
||||
contains(github.event.comment.body, '@claude'))
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Configure Git
|
||||
run: |
|
||||
git config user.name "Claude Bot"
|
||||
git config user.email "claude@localhost"
|
||||
git remote set-url origin http://admin:${{ secrets.GITEA_TOKEN }}@localhost:3000/${{ github.repository }}.git
|
||||
|
||||
- name: Run Claude Code
|
||||
env:
|
||||
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
|
||||
GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }}
|
||||
run: |
|
||||
ISSUE_NUMBER=${{ github.event.issue.number }}
|
||||
REPO=${{ github.repository }}
|
||||
|
||||
# Get issue details
|
||||
ISSUE_TITLE="${{ github.event.issue.title }}"
|
||||
ISSUE_BODY=$(curl -s "http://localhost:3000/api/v1/repos/${REPO}/issues/${ISSUE_NUMBER}" -H "Authorization: token ${GITEA_TOKEN}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('body',''))")
|
||||
|
||||
# Get comment if triggered by comment
|
||||
COMMENT_BODY=""
|
||||
if [ "${{ github.event_name }}" = "issue_comment" ]; then
|
||||
COMMENT_BODY="${{ github.event.comment.body }}"
|
||||
fi
|
||||
|
||||
# Create branch
|
||||
BRANCH="claude/issue-${ISSUE_NUMBER}"
|
||||
git checkout -b "${BRANCH}"
|
||||
|
||||
# Post a "working on it" comment
|
||||
curl -s -X POST "http://localhost:3000/api/v1/repos/${REPO}/issues/${ISSUE_NUMBER}/comments" -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" -d "{"body": "🤖 Claude is working on this issue..."}"
|
||||
|
||||
# Run Claude
|
||||
claude -p "You are working on the repository ${REPO}.
|
||||
A Gitea issue needs your attention:
|
||||
|
||||
Issue #${ISSUE_NUMBER}: ${ISSUE_TITLE}
|
||||
Description: ${ISSUE_BODY}
|
||||
|
||||
Additional context: ${COMMENT_BODY}
|
||||
|
||||
Instructions:
|
||||
1. Read and understand the codebase
|
||||
2. Implement the requested changes
|
||||
3. Make sure the code is correct and complete
|
||||
4. Commit all changes with a descriptive message
|
||||
|
||||
Work in the current directory. The branch is already created." --allowedTools "Bash,Read,Edit,Write,Glob,Grep" --mcp-config /etc/claude/mcp-gitea.json --max-turns 50 --dangerously-skip-permissions --output-format text > /tmp/claude-output.txt 2>&1 || true
|
||||
|
||||
cat /tmp/claude-output.txt
|
||||
|
||||
# Check if there are changes to commit/push
|
||||
if [ -n "" ] || [ "0" -gt 0 ]; then
|
||||
git add -A
|
||||
git diff --cached --quiet || git commit -m "Claude: Address issue #${ISSUE_NUMBER} - ${ISSUE_TITLE}"
|
||||
git push origin "${BRANCH}"
|
||||
|
||||
# Create PR
|
||||
PR_RESPONSE=$(curl -s -X POST "http://localhost:3000/api/v1/repos/${REPO}/pulls" -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" -d "{
|
||||
"title": "Claude: Fix #${ISSUE_NUMBER} - ${ISSUE_TITLE}",
|
||||
"body": "Automated PR by Claude Code for issue #${ISSUE_NUMBER}\n\nCloses #${ISSUE_NUMBER}",
|
||||
"head": "${BRANCH}",
|
||||
"base": "main"
|
||||
}")
|
||||
|
||||
PR_URL=$(echo "${PR_RESPONSE}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('html_url',''))" 2>/dev/null)
|
||||
|
||||
# Comment on issue with PR link
|
||||
curl -s -X POST "http://localhost:3000/api/v1/repos/${REPO}/issues/${ISSUE_NUMBER}/comments" -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" -d "{"body": "✅ Claude has created a pull request: ${PR_URL}"}"
|
||||
else
|
||||
curl -s -X POST "http://localhost:3000/api/v1/repos/${REPO}/issues/${ISSUE_NUMBER}/comments" -H "Authorization: token ${GITEA_TOKEN}" -H "Content-Type: application/json" -d "{"body": "Claude reviewed the issue but made no code changes."}"
|
||||
fi
|
||||
Reference in New Issue
Block a user