Simplify workflow - let Claude handle everything
This commit is contained in:
@@ -22,20 +22,7 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
|
GIT_TOKEN: ${{ secrets.GIT_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
set -x
|
# Configure git for Claude to use
|
||||||
# Only set ANTHROPIC_API_KEY if the secret is configured
|
|
||||||
if [ -n "${{ secrets.ANTHROPIC_API_KEY }}" ]; then
|
|
||||||
export ANTHROPIC_API_KEY="${{ secrets.ANTHROPIC_API_KEY }}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Debug info
|
|
||||||
echo "Running as: $(whoami)"
|
|
||||||
echo "Home: $HOME"
|
|
||||||
echo "Claude version: $(claude --version 2>&1)"
|
|
||||||
echo "Working dir: $(pwd)"
|
|
||||||
ls -la
|
|
||||||
|
|
||||||
# Configure git
|
|
||||||
git config user.name "Claude Bot"
|
git config user.name "Claude Bot"
|
||||||
git config user.email "claude@localhost"
|
git config user.email "claude@localhost"
|
||||||
git remote set-url origin "http://admin:${GIT_TOKEN}@localhost:3000/${{ github.repository }}.git"
|
git remote set-url origin "http://admin:${GIT_TOKEN}@localhost:3000/${{ github.repository }}.git"
|
||||||
@@ -49,9 +36,6 @@ jobs:
|
|||||||
ISSUE_BODY=$(curl -s "http://localhost:3000/api/v1/repos/${REPO}/issues/${ISSUE_NUMBER}" \
|
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',''))")
|
-H "Authorization: token ${GIT_TOKEN}" | python3 -c "import sys,json; print(json.load(sys.stdin).get('body',''))")
|
||||||
|
|
||||||
echo "Issue: #${ISSUE_NUMBER} - ${ISSUE_TITLE}"
|
|
||||||
echo "Body: ${ISSUE_BODY}"
|
|
||||||
|
|
||||||
# Get comment body if triggered by comment
|
# Get comment body if triggered by comment
|
||||||
COMMENT_BODY=""
|
COMMENT_BODY=""
|
||||||
if [ "${{ github.event_name }}" = "issue_comment" ]; then
|
if [ "${{ github.event_name }}" = "issue_comment" ]; then
|
||||||
@@ -70,69 +54,27 @@ jobs:
|
|||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"body\": \"Claude is working on this issue...\"}"
|
-d "{\"body\": \"Claude is working on this issue...\"}"
|
||||||
|
|
||||||
# Run Claude Code
|
# Run Claude Code - it handles everything: code changes, commits, push, and PR creation
|
||||||
CLAUDE_OUTPUT=$(claude -p "You are working on the repository ${REPO}.
|
claude -p "You are working on the repository ${REPO} (Gitea instance at http://localhost:3000).
|
||||||
A Gitea issue needs your attention:
|
A Gitea issue needs your attention:
|
||||||
|
|
||||||
Issue #${ISSUE_NUMBER}: ${ISSUE_TITLE}
|
Issue #${ISSUE_NUMBER}: ${ISSUE_TITLE}
|
||||||
Description: ${ISSUE_BODY}
|
Description: ${ISSUE_BODY}
|
||||||
|
Additional context: ${COMMENT_BODY}
|
||||||
Additional context from comment: ${COMMENT_BODY}
|
|
||||||
|
|
||||||
Instructions:
|
Instructions:
|
||||||
1. Read and understand the codebase structure
|
1. Read and understand the codebase
|
||||||
2. Implement the requested changes carefully
|
2. Implement the requested changes
|
||||||
3. Make sure the code is correct and complete
|
3. Commit your changes with a descriptive message
|
||||||
4. Commit all changes with a descriptive commit 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
|
||||||
|
|
||||||
You are on branch ${BRANCH}. Work in the current directory." \
|
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" \
|
--allowedTools "Bash,Read,Edit,Write,Glob,Grep" \
|
||||||
--mcp-config /home/claude-runner/.claude/mcp-gitea.json \
|
--mcp-config /home/claude-runner/.claude/mcp-gitea.json \
|
||||||
--max-turns 50 \
|
--max-turns 50 \
|
||||||
--permission-mode bypassPermissions \
|
--permission-mode bypassPermissions \
|
||||||
--output-format text 2>&1) || true
|
--output-format text 2>&1 | tee /home/claude-runner/last-claude-output.txt
|
||||||
|
|
||||||
echo "=== CLAUDE OUTPUT START ==="
|
|
||||||
echo "${CLAUDE_OUTPUT}"
|
|
||||||
echo "=== CLAUDE OUTPUT END ==="
|
|
||||||
|
|
||||||
# Also save to a persistent location for debugging
|
|
||||||
echo "${CLAUDE_OUTPUT}" > /home/claude-runner/last-claude-output.txt
|
|
||||||
|
|
||||||
# Stage any remaining unstaged changes
|
|
||||||
git add -A
|
|
||||||
|
|
||||||
echo "=== GIT STATUS ==="
|
|
||||||
git status
|
|
||||||
echo "=== GIT DIFF ==="
|
|
||||||
git diff --cached --stat
|
|
||||||
|
|
||||||
# Check if there are changes
|
|
||||||
if ! git diff --cached --quiet 2>/dev/null; then
|
|
||||||
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 ${GIT_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 || echo "unknown")
|
|
||||||
|
|
||||||
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 has created a pull request: ${PR_URL}\"}"
|
|
||||||
else
|
|
||||||
echo "No changes detected by Claude"
|
|
||||||
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 reviewed the issue but made no code changes.\"}"
|
|
||||||
fi
|
|
||||||
|
|||||||
Reference in New Issue
Block a user