fix: update workflow name and enhance OpenAI request handling in AI PR Description

This commit is contained in:
faris Aljohari
2025-07-15 23:47:45 -06:00
parent f0556813ac
commit d62e620828

View File

@ -1,4 +1,4 @@
name: 🤖 AI PR Description Commenter (Safe JSON with PAT)
name: 🤖 AI PR Description Commenter (100% Safe with jq)
on:
pull_request:
@ -27,20 +27,21 @@ jobs:
env:
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: |
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 \
-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'"${ESCAPED_COMMITS}"'\n\nGenerate a clear and professional pull request description."
}]
}')
-d "$REQUEST_BODY")
DESCRIPTION=$(echo "$RESPONSE" | jq -r '.choices[0].message.content')