From f0556813ac10020e40e3d1220417c6675275ccdf Mon Sep 17 00:00:00 2001 From: faris Aljohari <83524184+farisaljohari@users.noreply.github.com> Date: Tue, 15 Jul 2025 23:45:16 -0600 Subject: [PATCH] fix: update workflow name and enhance commit message handling in AI PR Description --- .github/workflows/pr-description.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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." }] }')