From 3c3276867930df5aa20051648bbf48e04a0baffb Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 9 Mar 2026 19:02:37 +0000 Subject: [PATCH] Add Claude Code automation workflow --- .gitea/workflows/claude.yml | 81 +++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 .gitea/workflows/claude.yml diff --git a/.gitea/workflows/claude.yml b/.gitea/workflows/claude.yml new file mode 100644 index 0000000..bc4b94f --- /dev/null +++ b/.gitea/workflows/claude.yml @@ -0,0 +1,81 @@ +name: Claude Code Assistant + +on: + issues: + types: [opened, labeled] + issue_comment: + types: [created] + +jobs: + claude-code: + if: >- + (github.event_name == 'issues' && + contains(toJSON(github.event.issue.labels), 'claude')) || + (github.event_name == 'issue_comment' && + contains(github.event.comment.body, '@claude')) + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Run Claude on Issue + env: + ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} + GIT_TOKEN: ${{ secrets.GIT_TOKEN }} + run: | + # Configure git for Claude to use + git config user.name "Claude Bot" + git config user.email "claude@localhost" + git remote set-url origin "http://admin:${GIT_TOKEN}@localhost:3000/${{ github.repository }}.git" + + # Extract issue info + ISSUE_NUMBER="${{ github.event.issue.number }}" + ISSUE_TITLE="${{ github.event.issue.title }}" + REPO="${{ github.repository }}" + + # Fetch issue body via API + ISSUE_BODY=$(curl -s "http://localhost:3000/api/v1/repos/${REPO}/issues/${ISSUE_NUMBER}" \ + -H "Authorization: token ${GIT_TOKEN}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('body',''))") + + # Get comment body if triggered by comment + COMMENT_BODY="" + if [ "${{ github.event_name }}" = "issue_comment" ]; then + COMMENT_ID="${{ github.event.comment.id }}" + COMMENT_BODY=$(curl -s "http://localhost:3000/api/v1/repos/${REPO}/issues/comments/${COMMENT_ID}" \ + -H "Authorization: token ${GIT_TOKEN}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('body',''))") + fi + + # Create working branch + BRANCH="claude/issue-${ISSUE_NUMBER}" + git checkout -b "${BRANCH}" + + # Post status comment + curl -s -X POST "http://localhost:3000/api/v1/repos/${REPO}/issues/${ISSUE_NUMBER}/comments" \ + -H "Authorization: token ${GIT_TOKEN}" \ + -H "Content-Type: application/json" \ + -d "{\"body\": \"Claude is working on this issue...\"}" + + # Run Claude Code - it handles everything: code changes, commits, push, and PR creation + claude -p "You are working on the repository ${REPO} (Gitea instance at http://localhost:3000). + 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. Commit your changes with a descriptive message + 4. Push branch ${BRANCH} to origin + 5. Create a pull request targeting main that references issue #${ISSUE_NUMBER} + 6. Comment on issue #${ISSUE_NUMBER} with a link to the PR + + Git is configured. You are on branch ${BRANCH}. Work in the current directory. + Use git commands to push, and curl to the Gitea API for PR creation. + Gitea API token is available as env var GIT_TOKEN." \ + --allowedTools "Bash,Read,Edit,Write,Glob,Grep" \ + --mcp-config /home/claude-runner/.claude/mcp-gitea.json \ + --max-turns 50 \ + --permission-mode bypassPermissions \ + --output-format text 2>&1 | tee /home/claude-runner/last-claude-output.txt