deno/.github/workflows/ai_pr_generation.yml

123 lines
5.9 KiB
YAML

name: AI PR Generation
on:
issues:
types: [labeled]
workflow_dispatch:
inputs:
issue_number:
description: 'Issue number or URL to work on'
required: true
type: string
jobs:
generate-pr:
if: github.event_name == 'workflow_dispatch' || github.event.label.name == 'ai:generate-pr'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
issues: write
id-token: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get issue details
id: issue
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then
# Extract issue number from input (handles both URLs and plain numbers)
ISSUE_INPUT="${{ inputs.issue_number }}"
ISSUE_NUM=$(echo "$ISSUE_INPUT" | grep -oE '[0-9]+$' || echo "$ISSUE_INPUT")
# Fetch issue details
ISSUE_JSON=$(gh issue view "$ISSUE_NUM" --json number,title,body,author --repo ${{ github.repository }})
echo "number=$(echo "$ISSUE_JSON" | jq -r '.number')" >> $GITHUB_OUTPUT
echo "title=$(echo "$ISSUE_JSON" | jq -r '.title')" >> $GITHUB_OUTPUT
echo "author=$(echo "$ISSUE_JSON" | jq -r '.author.login')" >> $GITHUB_OUTPUT
# Handle multiline body by base64 encoding
echo "body=$(echo "$ISSUE_JSON" | jq -r '.body' | base64 -w 0)" >> $GITHUB_OUTPUT
else
# Use event data for label trigger
echo "number=${{ github.event.issue.number }}" >> $GITHUB_OUTPUT
echo "title=${{ github.event.issue.title }}" >> $GITHUB_OUTPUT
echo "author=${{ github.event.issue.user.login }}" >> $GITHUB_OUTPUT
echo "body=$(echo '${{ github.event.issue.body }}' | base64 -w 0)" >> $GITHUB_OUTPUT
fi
- name: Decode issue body
id: decoded
run: |
echo "body<<EOF" >> $GITHUB_OUTPUT
echo "${{ steps.issue.outputs.body }}" | base64 -d >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- uses: anthropics/claude-code-action@v1
with:
timeout-minutes: 60
github_token: ${{ secrets.DENOBOT_PAT }}
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
prompt: |
REPO: ${{ github.repository }}
ISSUE NUMBER: ${{ steps.issue.outputs.number }}
TITLE: ${{ steps.issue.outputs.title }}
BODY: ${{ steps.decoded.outputs.body }}
AUTHOR: ${{ steps.issue.outputs.author }}
You have been assigned to work on fixing this issue. Your goal is to:
1. **FIRST: Check for specific implementation instructions**: Before doing anything else, fetch all comments on this issue using:
`gh issue view ${{ steps.issue.outputs.number }} --comments`
Look for any comments that contain the "**AI PR instruction**" banner. These comments contain specific
implementation guidance from maintainers that MUST take precedence over all other context.
If you find such comments:
- Follow the instructions in those comments EXACTLY
- Use them as your primary guide for the implementation
- The issue description and body provide context, but the AI PR instruction comments contain
the authoritative implementation approach you should follow
2. **Understand the issue thoroughly**: Read the issue description, analyze what's being reported or requested.
3. **Investigate the codebase**: Find the relevant files and code sections that need to be modified to address the issue.
4. **Implement a fix or feature**: Make the necessary code changes to resolve the issue. Ensure your changes:
- Are minimal and focused on the issue at hand
- Follow the existing code style and patterns in the repository
- Don't introduce new bugs or regressions
- Include appropriate error handling
5. **Test your changes**: If applicable, run relevant tests to verify your fix works:
- Run existing tests that might be affected: `cargo test` or specific test commands
- Verify the fix manually if possible
- If tests fail, debug and fix them
6. **Create a pull request**: Once your changes are ready:
- Create a new branch with a descriptive name (e.g., `fix-issue-${{ steps.issue.outputs.number }}`)
- Commit your changes with a clear commit message
- Push the branch and create a PR with:
- Title that references the issue: "Fix #${{ steps.issue.outputs.number }}: [brief description]"
- Description explaining what was changed and why
- Reference to the original issue
7. **Comment on the issue**: After creating the PR, add a comment to issue #${{ steps.issue.outputs.number }} with:
- A link to the PR you created
- A brief summary of the changes made
- Include this banner: "_This PR was autogenerated and may require review and adjustments._"
Important notes:
- If the issue is unclear or lacks information, add a comment requesting clarification instead of creating a PR
- If you determine the issue is a duplicate or already fixed, comment on the issue explaining this
- Focus on quality over speed - it's better to ask for clarification than to create a broken PR
- Make sure to use `gh pr create` for creating the pull request
- Use `gh issue comment` to add comments to the issue
You have access to the full repository and can use git, cargo, and gh CLI commands.
claude_args: |
--dangerously-skip-permissions --allowed-tools "*"