Skip to content

Add generate PR description workflow #4

Add generate PR description workflow

Add generate PR description workflow #4

name: Auto PR Description
on:
pull_request:
types: [opened, edited]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true
jobs:
auto-describe:
runs-on: ubuntu-latest
if: github.event.pull_request.draft == false
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: Checkout code
uses: actions/checkout@v4.1.1
- name: Set up Python
uses: actions/setup-python@v5.0.0
with:
python-version: '3.11'
- name: Install dependencies
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
source $HOME/.cargo/env
uv pip install --system requests openai
- name: Check for previous successful run
id: check_comment
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
COMMENT=$(gh api -X GET "/repos/${{ github.repository }}/issues/${PR_NUMBER}/comments" | jq '.[] | select(.body | contains("Auto PR description generated successfully")) | .id')
if [ -n "$COMMENT" ]; then
echo "Workflow has already run successfully for this PR."
echo "skip=true" >> $GITHUB_OUTPUT
else
echo "skip=false" >> $GITHUB_OUTPUT
fi
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Wait for potential edits
if: steps.check_comment.outputs.skip == 'false'
run: sleep 60 # Wait for 1 min
- name: Generate PR description
if: steps.check_comment.outputs.skip == 'false'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: python scripts/generate_pr_description.py
- name: Add success comment
if: steps.check_comment.outputs.skip == 'false'
run: |
PR_NUMBER="${{ github.event.pull_request.number }}"
gh issue comment ${PR_NUMBER} --body "Auto PR description generated successfully"
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Check for errors
if: failure()
run: |
echo "The PR description generation failed. Please check the logs for more information."