Claude Code • Auto PR on Comment #8285
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Claude Code • Auto PR on Comment | |
| on: | |
| issue_comment: | |
| types: [created] | |
| schedule: | |
| - cron: "0 * * * *" | |
| workflow_dispatch: {} | |
| concurrency: | |
| group: doc-fixing-ai-agent | |
| cancel-in-progress: false | |
| jobs: | |
| get_issue_and_assign: | |
| runs-on: ubuntu-latest | |
| if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| persist-credentials: false | |
| - name: Set up Node.js 24 | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: '24' | |
| - name: Install GitHub CLI | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y gh jq | |
| - name: Get the Oldest Issue with AI-Agent/Queued label | |
| id: get_oldest_queued | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }} | |
| run: | | |
| ISSUE_JSON=$(gh issue list --label "AI-Agent/Queued" --state open --json number,createdAt --limit 100 \ | |
| | jq '[.[]] | sort_by(.createdAt) | .[0]') | |
| if [ "$ISSUE_JSON" = "null" ] || [ -z "$ISSUE_JSON" ]; then | |
| echo "oldest_issue_number=" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| ISSUE_NUMBER=$(echo "$ISSUE_JSON" | jq -r .number) | |
| echo "oldest_issue_number=$ISSUE_NUMBER" >> $GITHUB_OUTPUT | |
| - name: Update labels and trigger Claude | |
| if: steps.get_oldest_queued.outputs.oldest_issue_number != '' | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }} | |
| run: | | |
| ISSUE=${{ steps.get_oldest_queued.outputs.oldest_issue_number }} | |
| # Remove AI-Agent/Queued, add AI-Agent/In-Progress | |
| gh issue edit $ISSUE --remove-label "AI-Agent/Queued" | |
| gh issue edit $ISSUE --add-label "AI-Agent/In-Progress" | |
| # Add trigger comment for Claude | |
| gh issue comment $ISSUE --body "@wso2-engineering-bot create a PR for this issue following repo conventions" | |
| run_claude: | |
| runs-on: ubuntu-latest | |
| if: contains(github.event.comment.body, '@wso2-engineering-bot') | |
| steps: | |
| - name: Checkout original repository | |
| uses: actions/checkout@v5 | |
| with: | |
| repository: ${{ vars.DOC_FIXING_AGENT_REPOSITORY }} | |
| token: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }} | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| - name: Set up Node.js 24 | |
| uses: actions/setup-node@v5 | |
| with: | |
| node-version: '24' | |
| - name: Configure git for commits | |
| env: | |
| GIT_USER_NAME: ${{ secrets.DOC_FIXING_AGENT_GIT_USER_NAME }} | |
| GIT_USER_EMAIL: ${{ secrets.DOC_FIXING_AGENT_GIT_USER_EMAIL }} | |
| run: | | |
| # Show current remotes for debugging | |
| echo "Current remotes:" | |
| git remote -v | |
| # Configure git for commits | |
| git config user.name "$GIT_USER_NAME" | |
| git config user.email "$GIT_USER_EMAIL" | |
| - name: Install security pre-commit hook | |
| run: | | |
| echo "Installing pre-commit hook for path validation..." | |
| # Create hooks directory if it doesn't exist | |
| mkdir -p .git/hooks | |
| # Copy and enable the pre-commit hook | |
| cp ${{ github.workspace }}/.github/scripts/pre-commit-hook.sh .git/hooks/pre-commit | |
| chmod +x .git/hooks/pre-commit | |
| echo "✅ Pre-commit hook installed successfully" | |
| echo "This hook will prevent commits to forbidden paths" | |
| - name: Prepare system prompt with environment variables | |
| id: prepare_prompt | |
| run: | | |
| # Install gettext if not available (for envsubst) | |
| if ! command -v envsubst &> /dev/null; then | |
| sudo apt-get update && sudo apt-get install -y gettext-base | |
| fi | |
| # Export environment variables for substitution | |
| export ISSUE_NUMBER="${{ github.event.issue.number }}" | |
| export REPOSITORY="${{ vars.DOC_FIXING_AGENT_REPOSITORY }}" | |
| export LATEST_VERSION="${{ vars.DOC_FIXING_AGENT_LATEST_VERSION }}" | |
| # Process the system prompt with variable substitution | |
| SYSTEM_PROMPT=$(envsubst < ${{github.workspace}}/.github/claude/system_prompt.txt) | |
| # Save to GitHub env | |
| echo "SYSTEM_PROMPT<<EOF" >> $GITHUB_ENV | |
| echo "$SYSTEM_PROMPT" >> $GITHUB_ENV | |
| echo "EOF" >> $GITHUB_ENV | |
| # Also set these for Claude | |
| echo "ISSUE_NUMBER=$ISSUE_NUMBER" >> $GITHUB_ENV | |
| echo "REPOSITORY=$REPOSITORY" >> $GITHUB_ENV | |
| echo "LATEST_VERSION=$LATEST_VERSION" >> $GITHUB_ENV | |
| - name: Set up Python 3.8 | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: '3.8' | |
| - name: Install documentation dependencies | |
| run: | | |
| cd $GITHUB_WORKSPACE/en | |
| if [ -f requirements.txt ]; then | |
| pip3 install -r requirements.txt | |
| echo "✓ Installed dependencies from requirements.txt" | |
| else | |
| pip3 install mkdocs mkdocs-material | |
| echo "✓ Installed mkdocs and mkdocs-material" | |
| fi | |
| - name: Run Claude | |
| id: run_claude | |
| uses: anthropics/claude-code-action@v1 | |
| env: | |
| ISSUE_NUMBER: ${{ github.event.issue.number }} | |
| REPOSITORY: ${{ vars.DOC_FIXING_AGENT_REPOSITORY }} | |
| with: | |
| anthropic_api_key: ${{ secrets.DOC_FIXING_AGENT_ANTHROPIC_API_KEY }} | |
| github_token: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }} | |
| prompt: ${{ env.SYSTEM_PROMPT }} | |
| trigger_phrase: "@wso2-engineering-bot" | |
| claude_args: | | |
| --allowedTools "Bash(git fetch *),Bash(git checkout *),Bash(git branch *),Bash(git status *),Bash(git diff *),Bash(git add *),Bash(git commit *),Bash(git push *),Bash(git log *),Bash(ls *),Bash(mkdir *),Bash(cp *),Bash(mv *),Bash(mkdocs *),WebFetch,mcp__github__create_pull_request,mcp__github__get_issue,mcp__github__search_pull_requests,mcp__github__list_branches,Edit,Read,Write,mcp__github__update_issue,mcp__github__create_branch,mcp__github__add_issue_comment,mcp__github__get_file_contents" | |
| --model claude-sonnet-4-5-20250929 | |
| - name: Get next queued issue | |
| id: get_next_queued | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }} | |
| run: | | |
| ISSUE_JSON=$(gh issue list --label "AI-Agent/Queued" --state open --json number,createdAt --limit 100 \ | |
| | jq '[.[]] | sort_by(.createdAt) | .[0]') | |
| if [ "$ISSUE_JSON" = "null" ] || [ -z "$ISSUE_JSON" ]; then | |
| echo "next_issue_number=" >> $GITHUB_OUTPUT | |
| exit 0 | |
| fi | |
| NEXT_ISSUE_NUMBER=$(echo "$ISSUE_JSON" | jq -r .number) | |
| echo "next_issue_number=$NEXT_ISSUE_NUMBER" >> $GITHUB_OUTPUT | |
| - name: Exit if no queued issues | |
| if: steps.get_next_queued.outputs.next_issue_number == '' | |
| run: | | |
| echo "No queued issues." | |
| exit 0 | |
| - name: Update labels and trigger Claude | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }} | |
| if: steps.get_next_queued.outputs.next_issue_number != '' | |
| run: | | |
| ISSUE=${{ steps.get_next_queued.outputs.next_issue_number }} | |
| # Remove AI-Agent/Queued, add AI-Agent/In-Progress | |
| gh issue edit $ISSUE --remove-label "AI-Agent/Queued" | |
| gh issue edit $ISSUE --add-label "AI-Agent/In-Progress" | |
| # Add trigger comment for Claude | |
| gh issue comment $ISSUE --body "@wso2-engineering-bot create a PR for this issue following repo conventions" |