Skip to content

Commit

Permalink
Added PR workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
htahir1 committed Sep 24, 2024
1 parent 479b3c4 commit e110bda
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
32 changes: 30 additions & 2 deletions .github/workflows/generate-pr-description.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ name: Auto PR Description

on:
pull_request:
types: [opened]
types: [opened, edited]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
cancel-in-progress: true

jobs:
Expand All @@ -15,6 +15,7 @@ jobs:
permissions:
contents: read
pull-requests: write
issues: write
steps:
- name: Checkout code
uses: actions/[email protected]
Expand All @@ -30,12 +31,39 @@ jobs:
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 300 # Wait for 5 minutes

- 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: |
Expand Down
4 changes: 3 additions & 1 deletion scripts/generate_pr_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ def generate_pr_description():
data = {'body': updated_description}
requests.patch(api_url, json=data, headers=headers)
print(f"Updated PR description with generated content")
return True
else:
print("PR already has a non-default description. No action taken.")
return False

if __name__ == "__main__":
generate_pr_description()
generate_pr_description()

0 comments on commit e110bda

Please sign in to comment.