diff --git a/.github/workflows/pr-description.yml b/.github/workflows/pr-description.yml index 2de9e86..7460044 100644 --- a/.github/workflows/pr-description.yml +++ b/.github/workflows/pr-description.yml @@ -1,4 +1,4 @@ -name: 🤖 AI PR Description Commenter (With Debug) +name: 🤖 AI PR Description Commenter (Safe JSON with PAT) on: pull_request: @@ -12,10 +12,10 @@ jobs: - name: Checkout Repo uses: actions/checkout@v4 - - name: Install GitHub CLI + - name: Install GitHub CLI and jq run: | sudo apt-get update - sudo apt-get install gh -y + sudo apt-get install gh jq -y - name: Fetch PR Commits id: fetch_commits @@ -27,9 +27,10 @@ jobs: env: GH_TOKEN: ${{ secrets.GH_PERSONAL_TOKEN }} - - name: Generate PR Description with OpenAI - id: generate_description + - name: Generate PR Description with OpenAI (Safe JSON) run: | + ESCAPED_COMMITS=$(printf '%s\n' "${commits}" | jq -R . | jq -s -c 'join("\n")') + RESPONSE=$(curl -s https://api.openai.com/v1/chat/completions \ -H "Authorization: Bearer $OPENAI_API_KEY" \ -H "Content-Type: application/json" \ @@ -37,7 +38,7 @@ jobs: "model": "gpt-4o", "messages": [{ "role": "user", - "content": "Given the following commit messages:\n\n'"${commits}"'\n\nGenerate a clear and professional pull request description." + "content": "Given the following commit messages:\n\n'"${ESCAPED_COMMITS}"'\n\nGenerate a clear and professional pull request description." }] }')