diff --git a/.github/workflows/pr-description.yml b/.github/workflows/pr-description.yml index 7460044..e4514b4 100644 --- a/.github/workflows/pr-description.yml +++ b/.github/workflows/pr-description.yml @@ -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')