mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-08-29 16:59:39 +00:00
62 lines
2.1 KiB
YAML
62 lines
2.1 KiB
YAML
name: 🤖 AI PR Description with HuggingFace Falcon
|
|
|
|
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 and jq
|
|
run: |
|
|
sudo apt-get update
|
|
sudo apt-get install gh jq -y
|
|
|
|
- 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.GH_PERSONAL_TOKEN }}
|
|
|
|
- name: Generate PR Description with HuggingFace Falcon
|
|
run: |
|
|
REQUEST_BODY=$(jq -n \
|
|
--arg inputs "Given the following commit messages:\n\n${commits}\n\nGenerate a clear and professional pull request description." \
|
|
'{ inputs: $inputs }'
|
|
)
|
|
|
|
RESPONSE=$(curl -s https://api-inference.huggingface.co/models/tiiuae/falcon-7b-instruct \
|
|
-H "Authorization: Bearer $HUGGINGFACE_API_KEY" \
|
|
-H "Content-Type: application/json" \
|
|
-d "$REQUEST_BODY")
|
|
|
|
echo "---------- HuggingFace Raw Response ----------"
|
|
echo "$RESPONSE"
|
|
|
|
DESCRIPTION=$(echo "$RESPONSE" | jq -r 'if type=="array" then .[0].generated_text else .error else "Error: Unexpected response" end')
|
|
|
|
echo "---------- Extracted Description ----------"
|
|
echo "$DESCRIPTION"
|
|
|
|
echo "description<<EOF" >> $GITHUB_ENV
|
|
echo "$DESCRIPTION" >> $GITHUB_ENV
|
|
echo "EOF" >> $GITHUB_ENV
|
|
env:
|
|
HUGGINGFACE_API_KEY: ${{ secrets.HUGGINGFACE_API_KEY }}
|
|
commits: ${{ env.commits }}
|
|
|
|
- name: Post AI Generated Description as Comment
|
|
run: |
|
|
gh pr comment ${{ github.event.pull_request.number }} --body "${{ env.description }}"
|
|
env:
|
|
GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
|