mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-25 21:49:39 +00:00
Add AI PR Description Action
This commit is contained in:
54
.github/workflows/pr-description.yml
vendored
Normal file
54
.github/workflows/pr-description.yml
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
name: 🤖 AI PR Description Generator (with Template)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
types: [opened, edited]
|
||||
|
||||
jobs:
|
||||
generate-description:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install GitHub CLI
|
||||
uses: cli/cli-action@v2
|
||||
|
||||
- name: Fetch PR Commits
|
||||
id: fetch_commits
|
||||
run: |
|
||||
COMMITS=$(gh pr view ${{ github.event.pull_request.number }} --json commits --jq '.commits[].message' | sed 's/^/- /')
|
||||
echo "commits<<EOF" >> $GITHUB_ENV
|
||||
echo "$COMMITS" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Generate PR Description with OpenAI
|
||||
id: generate_description
|
||||
run: |
|
||||
RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \
|
||||
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"model": "gpt-4o",
|
||||
"messages": [{
|
||||
"role": "user",
|
||||
"content": "Given the following commit messages:\n\n'"${commits}"'\n\nFill the following pull request template. Only fill the \"## Description\" section:\n\n<!--\n Thanks for contributing!\n\n Provide a description of your changes below and a general summary in the title.\n-->\n\n## Jira Ticket\n\n[SP-0000](https://syncrow.atlassian.net/browse/SP-0000)\n\n## Description\n\n<!--- Describe your changes in detail -->\n\n## How to Test\n\n<!--- Describe the created APIs / Logic -->"
|
||||
}]
|
||||
}')
|
||||
|
||||
DESCRIPTION=$(echo "$RESPONSE" | jq -r '.choices[0].message.content')
|
||||
echo "description<<EOF" >> $GITHUB_ENV
|
||||
echo "$DESCRIPTION" >> $GITHUB_ENV
|
||||
echo "EOF" >> $GITHUB_ENV
|
||||
env:
|
||||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
|
||||
commits: ${{ env.commits }}
|
||||
|
||||
- name: Update PR Body with AI Description
|
||||
run: |
|
||||
gh pr edit ${{ github.event.pull_request.number }} --body "${{ env.description }}"
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
Reference in New Issue
Block a user