mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-23 00:00:33 +00:00
0c8caa050f
* add flow for aider review * add aider conventions, use ubicloud, ignore files * better if * use cursor rules * restrict to aider prs * fix
171 lines
6.7 KiB
YAML
171 lines
6.7 KiB
YAML
name: Aider Auto-fix PR Review Change Requests
|
|
|
|
on:
|
|
pull_request_review:
|
|
types: [submitted]
|
|
|
|
jobs:
|
|
auto-fix-review:
|
|
if: github.event.review.state == 'changes_requested' && contains(github.event.pull_request.title, '[Aider PR]')
|
|
runs-on: ubicloud-standard-8
|
|
permissions:
|
|
contents: write
|
|
pull-requests: write
|
|
env:
|
|
GEMINI_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
|
|
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
|
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
WINDMILL_TOKEN: ${{ secrets.WINDMILL_TOKEN }}
|
|
|
|
steps:
|
|
- name: Harden Runner
|
|
uses: step-security/harden-runner@v2
|
|
with:
|
|
egress-policy: audit
|
|
|
|
- name: Check out code
|
|
uses: actions/checkout@v4
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Configure Git User
|
|
run: |
|
|
git config --global user.name "github-actions[bot]"
|
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
|
|
- name: Checkout PR Branch
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
run: |
|
|
echo "PR review trigger: Checking out PR branch..."
|
|
PR_NUMBER=${{ github.event.pull_request.number }}
|
|
PR_HEAD_REF=$(gh pr view $PR_NUMBER --json headRefName -q .headRefName --repo $GITHUB_REPOSITORY)
|
|
if [[ -z "$PR_HEAD_REF" || "$PR_HEAD_REF" == "null" ]]; then
|
|
echo "::error::Could not determine PR head branch for PR #$PR_NUMBER via gh CLI."
|
|
exit 1
|
|
fi
|
|
echo "Checking out PR head branch: $PR_HEAD_REF for PR #$PR_NUMBER"
|
|
git fetch origin "refs/heads/${PR_HEAD_REF}:refs/remotes/origin/${PR_HEAD_REF}" --no-tags
|
|
git checkout "$PR_HEAD_REF"
|
|
echo "Successfully checked out branch $(git rev-parse --abbrev-ref HEAD)"
|
|
|
|
- name: Set up Python
|
|
uses: actions/setup-python@v5
|
|
with:
|
|
python-version: "3.12"
|
|
|
|
- name: Install Aider and Dependencies
|
|
run: |
|
|
python -m pip install aider-install; aider-install
|
|
pip install -U google-generativeai
|
|
sudo apt-get update && sudo apt-get install -y jq
|
|
|
|
- name: Generate Prompt from Review
|
|
id: generate_prompt
|
|
shell: bash
|
|
run: |
|
|
mkdir -p .github/aider
|
|
PROMPT_FILE_PATH=".github/aider/review-prompt.txt"
|
|
|
|
# Get PR review body
|
|
REVIEW_BODY="${{ github.event.review.body }}"
|
|
PR_NUMBER="${{ github.event.pull_request.number }}"
|
|
|
|
# Get PR description for context NOT USED FOR NOW
|
|
# PR_DETAILS=$(gh pr view $PR_NUMBER --json title,body --repo $GITHUB_REPOSITORY)
|
|
# PR_TITLE=$(echo "$PR_DETAILS" | jq -r .title)
|
|
# PR_BODY=$(echo "$PR_DETAILS" | jq -r .body)
|
|
|
|
# Get all PR review comments
|
|
REVIEW_COMMENTS=$(gh pr view $PR_NUMBER --json reviews -q '.reviews[] | select(.state == "CHANGES_REQUESTED") | .body' --repo $GITHUB_REPOSITORY)
|
|
REVIEW_BODY_Q=$(printf '%q' "$REVIEW_BODY")
|
|
|
|
# Update query to get review comments from all review types, not just "CHANGES_REQUESTED"
|
|
ALL_REVIEW_COMMENTS=$(gh api \
|
|
-H "Accept: application/vnd.github+json" \
|
|
-H "X-GitHub-Api-Version: 2022-11-28" \
|
|
/repos/$GITHUB_REPOSITORY/pulls/$PR_NUMBER/comments \
|
|
| jq '[.[] | {diff_hunk: .diff_hunk, path: .path, body: .body}]')
|
|
|
|
BASE_PROMPT="Fix the following issues in the PR based on the review feedback. The review body is prepended with REVIEW. The review comments are prepended with REVIEW_COMMENTS. The review body and comments are separated by a blank line."
|
|
printf "%s\nREVIEW:\n%s\nREVIEW_COMMENTS:\n%s" \
|
|
"$BASE_PROMPT" "$REVIEW_BODY_Q" "$ALL_REVIEW_COMMENTS" > "$PROMPT_FILE_PATH"
|
|
echo "PROMPT_FILE_PATH=$PROMPT_FILE_PATH" >> $GITHUB_OUTPUT
|
|
|
|
- name: Run Aider with review prompt
|
|
run: |
|
|
aider \
|
|
--read .cursor/rules/rust-best-practices.mdc \
|
|
--read .cursor/rules/svelte5-best-practices.mdc \
|
|
--model gemini/gemini-2.5-pro-preview-05-06 \
|
|
--message-file .github/aider/review-prompt.txt \
|
|
--yes \
|
|
--no-check-update \
|
|
--auto-commits \
|
|
--no-analytics \
|
|
--no-gitignore \
|
|
| tee .github/aider/aider-output.txt || true
|
|
echo "Aider command completed. Output saved to .github/aider/aider-output.txt"
|
|
# Check if there are any changes to commit
|
|
if [[ -z "$(git status --porcelain)" ]]; then
|
|
echo "No changes detected after running Aider."
|
|
exit 0
|
|
fi
|
|
|
|
- name: Clean up prompt file
|
|
if: always()
|
|
run: rm -f .github/aider/review-prompt.txt
|
|
|
|
- name: Commit and Push Changes
|
|
id: commit_and_push
|
|
if: ${{ success() }}
|
|
run: |
|
|
CURRENT_BRANCH_NAME=$(git rev-parse --abbrev-ref HEAD)
|
|
echo "Attempting to push changes to PR branch $CURRENT_BRANCH_NAME for PR #${{ github.event.pull_request.number }}"
|
|
|
|
# Pull latest changes to avoid rejection due to non-fast-forward
|
|
git pull origin $CURRENT_BRANCH_NAME
|
|
|
|
if git push origin $CURRENT_BRANCH_NAME; then
|
|
echo "Push to $CURRENT_BRANCH_NAME successful."
|
|
echo "CHANGES_APPLIED=true" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "::warning::Push to PR branch $CURRENT_BRANCH_NAME failed."
|
|
echo "CHANGES_APPLIED=false" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Comment on PR
|
|
if: success()
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
|
PR_NUM: ${{ github.event.pull_request.number }}
|
|
run: |
|
|
# Create comment body in a temporary file to avoid command line length limits
|
|
if [[ "${{ steps.commit_and_push.outputs.CHANGES_APPLIED }}" == "true" ]]; then
|
|
cat > /tmp/pr-comment.md << EOL
|
|
🤖 I've automatically addressed the feedback based on the review.
|
|
|
|
## Aider Output
|
|
\`\`\`
|
|
$(cat .github/aider/aider-output.txt || echo 'No output available')
|
|
\`\`\`
|
|
|
|
Please review the changes and let me know if further adjustments are needed.
|
|
EOL
|
|
else
|
|
cat > /tmp/pr-comment.md << EOL
|
|
🤖 I attempted to address the review feedback, but no modifications were made.
|
|
|
|
## Aider Output
|
|
\`\`\`
|
|
$(cat .github/aider/aider-output.txt || echo 'No output available')
|
|
\`\`\`
|
|
|
|
Please review the output and provide additional guidance if needed.
|
|
EOL
|
|
fi
|
|
|
|
# Use the file for comment body
|
|
gh pr comment $PR_NUM --body-file /tmp/pr-comment.md
|