Skip to content

Commit f643a5d

Browse files
committed
Address PR comments
1 parent 45ef125 commit f643a5d

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

.github/workflows/ai-issues-auto-reply.yml

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
ai_autoreply:
2121
runs-on: ubuntu-latest
2222
steps:
23-
- name: Checkout
23+
- name: Checkout
2424
uses: actions/checkout@v4
2525

2626
- name: Decide whether to reply
@@ -62,7 +62,7 @@ jobs:
6262
(c.user?.login === 'github-actions[bot]' || c.user?.type === 'Bot') &&
6363
(c.body || '').includes('<!-- AI-autoreply -->')
6464
);
65-
if (priorAI || labels.includes('AI-replied')) {
65+
if (priorAI || labels.includes('ai-replied')) {
6666
core.setOutput('should','false'); return;
6767
}
6868
@@ -83,28 +83,39 @@ jobs:
8383
REPO="${{ github.repository }}"
8484
8585
# System & user prompts tuned for triage; keep it short and safe.
86-
SYSTEM_PROMPT=$'You are a cautious, concise triage assistant for '"$REPO"$'.\\
87-
Goals: Greet the user; summarize in 1-2 sentences; \\
88-
use communication guidelines defined in: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-objc/dev/.clinerules/06-Customer-communication-guidelines.md'
89-
90-
USER_PROMPT=$'New issue at: '"$ISSUE_URL"$'\\nTitle: '"$ISSUE_TITLE"$'\\n\\nBody:\\n'"$ISSUE_BODY"$
86+
SYSTEM_PROMPT=$(printf 'You are a cautious, concise triage assistant for %s.\nGoals: Greet the user; summarize in 1-2 sentences;\nuse communication guidelines defined in: https://raw.githubusercontent.com/AzureAD/microsoft-authentication-library-for-objc/dev/.clinerules/06-Customer-communication-guidelines.md' "$REPO")
87+
88+
USER_PROMPT=$(printf 'New issue at: %s\nTitle: %s\n\nBody:\n%s' "$ISSUE_URL" "$ISSUE_TITLE" "$ISSUE_BODY")
9189
9290
REQ=$(jq -n --arg m "$GH_MODELS_MODEL" \
93-
--arg sys "$SYSTEM_PROMPT" \
94-
--arg user "$USER_PROMPT" \
91+
--arg sys "$SYSTEM_PROMPT" \
92+
--arg user "$USER_PROMPT" \
9593
'{model:$m, messages:[{role:"system",content:$sys},{role:"user",content:$user}], temperature:0.4}')
9694
9795
# Call GitHub Models Chat Completions API
98-
RESP=$(curl -sSL -X POST \
96+
HTTP_CODE=$(curl -sSL -X POST -w "%{http_code}" -o response.json \
9997
-H "Accept: application/vnd.github+json" \
10098
-H "Authorization: Bearer $GH_MODELS_TOKEN" \
10199
-H "X-GitHub-Api-Version: 2022-11-28" \
102100
-H "Content-Type: application/json" \
103101
https://models.github.ai/inference/chat/completions \
104102
-d "$REQ")
105103
104+
if [[ "$HTTP_CODE" -lt 200 || "$HTTP_CODE" -ge 300 ]]; then
105+
echo "::error::API request failed with status $HTTP_CODE"
106+
cat response.json
107+
exit 1
108+
fi
109+
110+
# Check for JSON error field
111+
if jq -e '.error' response.json >/dev/null 2>&1; then
112+
echo "::error::API returned JSON error"
113+
cat response.json
114+
exit 1
115+
fi
116+
106117
# Extract text
107-
AI=$(printf '%s' "$RESP" | jq -r '.choices[0].message.content // ""')
118+
AI=$(jq -r '.choices[0].message.content // ""' response.json)
108119
109120
# Set multi-line output for next step
110121
{
@@ -121,7 +132,7 @@ jobs:
121132
with:
122133
script: |
123134
const core = require('@actions/core');
124-
const body = core.getInput('text') || `${{ steps.ai.outputs.text }}` || '';
135+
const body = `${{ steps.ai.outputs.text }}` || '';
125136
const finalBody = `${body.trim()}
126137
127138
<!-- AI-autoreply -->
@@ -145,7 +156,7 @@ jobs:
145156
owner: context.repo.owner,
146157
repo: context.repo.repo,
147158
issue_number: context.payload.issue.number,
148-
labels: ['AI-replied']
159+
labels: ['ai-replied']
149160
});
150161
} catch (e) {
151162
core.warning('Could not add AI-replied label (create it first).');

0 commit comments

Comments
 (0)