Skip to content

Claude Code • Auto PR on Comment #2683

Claude Code • Auto PR on Comment

Claude Code • Auto PR on Comment #2683

Workflow file for this run

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
- 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: Set environment variables
id: set_env_vars
run: |
echo "ISSUE_NUMBER=${{ github.event.issue.number }}" >> $GITHUB_ENV
echo "LATEST_VERSION=${{ vars.DOC_FIXING_AGENT_LATEST_VERSION }}" >> $GITHUB_ENV
# Then checkout the repositories in separate directories
- name: Checkout source repository (product-is)
uses: actions/checkout@v4
with:
repository: ${{ github.repository }}
token: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }}
path: product-is
fetch-depth: 0
- name: Checkout target repository (docs-is)
uses: actions/checkout@v4
with:
repository: wso2/docs-is
token: ${{ secrets.DOC_FIXING_AGENT_GITHUB_TOKEN }}
path: docs-is
fetch-depth: 0
# Set working directory paths explicitly
- name: Set repository paths
run: |
echo "PRODUCT_IS_PATH=$GITHUB_WORKSPACE/product-is" >> $GITHUB_ENV
echo "DOCS_IS_PATH=$GITHUB_WORKSPACE/docs-is" >> $GITHUB_ENV
# Configure git globally in the main workspace first
- name: Configure git globally
run: |
git config --global user.name "${{ secrets.DOC_FIXING_AGENT_GIT_USER_NAME }}"
git config --global user.email "${{ secrets.DOC_FIXING_AGENT_GIT_USER_EMAIL }}"
cd $GITHUB_WORKSPACE
- 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 LATEST_VERSION="${{ vars.DOC_FIXING_AGENT_LATEST_VERSION }}"
export GIT_USER_NAME="${{ secrets.DOC_FIXING_AGENT_GIT_USER_NAME }}"
export GIT_USER_EMAIL="${{ secrets.DOC_FIXING_AGENT_GIT_USER_EMAIL }}"
export PRODUCT_IS_PATH="$PRODUCT_IS_PATH"
export DOCS_IS_PATH="$DOCS_IS_PATH"
# Process the system prompt with variable substitution
cd $PRODUCT_IS_PATH
pwd
SYSTEM_PROMPT=$(envsubst < .github/claude/system_prompt.txt)
# Save to GitHub env
echo "SYSTEM_PROMPT<<EOF" >> $GITHUB_ENV
echo "$SYSTEM_PROMPT" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Run Claude
id: run_claude
uses: anthropics/claude-code-action@v1
env:
ISSUE_NUMBER: ${{ github.event.issue.number }}
LATEST_VERSION: ${{ vars.DOC_FIXING_AGENT_LATEST_VERSION }}
PRODUCT_IS_PATH: ${{ github.workspace }}/product-is
DOCS_IS_PATH: ${{ github.workspace }}/docs-is
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(*),Bash(git:*),Bash(mkdocs:*),Bash(python3:*),Bash(pip3:*),WebFetch,WebSearch,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: |
# Switch to product-is directory
cd $PRODUCT_IS_PATH
# Get the next queued issue from the product-is repository
ISSUE_JSON=$(gh issue list --repo ${{ github.repository }} --label "AI-Agent/Queued" --state open --json number,createdAt --limit 100 \
| jq '[.[]] | sort_by(.createdAt) | .[0]')
echo "Checking for next queued issue in ${{ github.repository }}..."
if [ "$ISSUE_JSON" = "null" ] || [ -z "$ISSUE_JSON" ]; then
echo "No queued issues found."
echo "next_issue_number=" >> $GITHUB_OUTPUT
exit 0
fi
NEXT_ISSUE_NUMBER=$(echo "$ISSUE_JSON" | jq -r .number)
echo "Found next queued issue: #$NEXT_ISSUE_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: |
# Switch to product-is directory
cd $PRODUCT_IS_PATH
ISSUE=${{ steps.get_next_queued.outputs.next_issue_number }}
echo "Processing next issue: #$ISSUE in ${{ github.repository }}"
# Remove AI-Agent/Queued, add AI-Agent/In-Progress
gh issue edit $ISSUE --repo ${{ github.repository }} --remove-label "AI-Agent/Queued"
gh issue edit $ISSUE --repo ${{ github.repository }} --add-label "AI-Agent/In-Progress"
# Add trigger comment for Claude
gh issue comment $ISSUE --repo ${{ github.repository }} --body "@wso2-engineering-bot create a PR for this issue following repo conventions"
echo "Successfully updated labels and triggered Claude for issue #$ISSUE"