mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 07:34:54 +00:00
fix: update workflow name and enhance OpenAI request handling in AI PR Description
This commit is contained in:
21
.github/workflows/pr-description.yml
vendored
21
.github/workflows/pr-description.yml
vendored
@ -1,4 +1,4 @@
|
|||||||
name: 🤖 AI PR Description Commenter (Safe JSON with PAT)
|
name: 🤖 AI PR Description Commenter (100% Safe with jq)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
pull_request:
|
pull_request:
|
||||||
@ -27,20 +27,21 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
|
GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }}
|
||||||
|
|
||||||
- name: Generate PR Description with OpenAI (Safe JSON)
|
- name: Generate PR Description with OpenAI (Safe JSON with jq)
|
||||||
run: |
|
run: |
|
||||||
ESCAPED_COMMITS=$(printf '%s\n' "${commits}" | jq -R . | jq -s -c 'join("\n")')
|
REQUEST_BODY=$(jq -n \
|
||||||
|
--arg model "gpt-4o" \
|
||||||
|
--arg content "Given the following commit messages:\n\n${commits}\n\nGenerate a clear and professional pull request description." \
|
||||||
|
'{
|
||||||
|
model: $model,
|
||||||
|
messages: [{ role: "user", content: $content }]
|
||||||
|
}'
|
||||||
|
)
|
||||||
|
|
||||||
RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \
|
RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \
|
||||||
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
-H "Authorization: Bearer $OPENAI_API_KEY" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d "$REQUEST_BODY")
|
||||||
"model": "gpt-4o",
|
|
||||||
"messages": [{
|
|
||||||
"role": "user",
|
|
||||||
"content": "Given the following commit messages:\n\n'"${ESCAPED_COMMITS}"'\n\nGenerate a clear and professional pull request description."
|
|
||||||
}]
|
|
||||||
}')
|
|
||||||
|
|
||||||
DESCRIPTION=$(echo "$RESPONSE" | jq -r '.choices[0].message.content')
|
DESCRIPTION=$(echo "$RESPONSE" | jq -r '.choices[0].message.content')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user