Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/post-discord.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ jobs:
"${{ inputs.previous_version }}" \
${{ inputs.dry_run == true && '--dry-run' || '--post-discord' }}
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
DISCORD_RELEASE_WEBHOOK: ${{ secrets.DISCORD_RELEASE_WEBHOOK }}
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ jobs:
"$PREV_TAG" \
--post-discord
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
DISCORD_RELEASE_WEBHOOK: ${{ secrets.DISCORD_RELEASE_WEBHOOK }}

- name: Sync main back to dev
Expand Down
31 changes: 18 additions & 13 deletions scripts/rewrite-release-notes.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -95,34 +95,39 @@ ${commitBlocks}`,
};
}

// ─── Claude API ──────────────────────────────────────────────────────────────
// ─── LLM call (protoLabs LiteLLM gateway, OpenAI-compatible) ─────────────────

async function callClaude(userPrompt) {
const apiKey = process.env.ANTHROPIC_API_KEY;
if (!apiKey) throw new Error('ANTHROPIC_API_KEY is not set');
const LLM_BASE_URL =
process.env.OPENAI_BASE_URL || 'https://api.proto-labs.ai/v1';
const LLM_MODEL = process.env.RELEASE_NOTES_MODEL || 'protolabs/fast';

const res = await fetch('https://api.anthropic.com/v1/messages', {
async function callLLM(userPrompt) {
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) throw new Error('OPENAI_API_KEY is not set');

const res = await fetch(`${LLM_BASE_URL}/chat/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': apiKey,
'anthropic-version': '2023-06-01',
Authorization: `Bearer ${apiKey}`,
},
body: JSON.stringify({
model: 'claude-haiku-4-5-20251001',
model: LLM_MODEL,
max_tokens: 1024,
system: SYSTEM_PROMPT,
messages: [{ role: 'user', content: userPrompt }],
messages: [
{ role: 'system', content: SYSTEM_PROMPT },
{ role: 'user', content: userPrompt },
],
}),
});

if (!res.ok) {
const err = await res.text();
throw new Error(`Claude API error ${res.status}: ${err}`);
throw new Error(`LLM API error ${res.status}: ${err}`);
}

const data = await res.json();
return data.content[0].text;
return data.choices?.[0]?.message?.content ?? '';
}
Comment on lines 129 to 131

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

Fail fast when LLM output is empty instead of returning ''.

The current fallback can silently produce blank release notes and still continue to Discord posting. Throw when content is missing/empty so the failure is explicit in CI logs.

Suggested fix
   const data = await res.json();
-  return data.choices?.[0]?.message?.content ?? '';
+  const content = data.choices?.[0]?.message?.content;
+  if (typeof content !== 'string' || content.trim().length === 0) {
+    throw new Error('LLM response did not include non-empty message content');
+  }
+  return content.trim();
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const data = await res.json();
return data.content[0].text;
return data.choices?.[0]?.message?.content ?? '';
}
const data = await res.json();
const content = data.choices?.[0]?.message?.content;
if (typeof content !== 'string' || content.trim().length === 0) {
throw new Error('LLM response did not include non-empty message content');
}
return content.trim();
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/rewrite-release-notes.mjs` around lines 129 - 131, The current code
returns an empty string when the LLM output is missing
(data.choices?.[0]?.message?.content ?? ''), which can let CI continue with
blank release notes; modify the function that awaits res.json() so it checks
data.choices?.[0]?.message?.content into a variable (e.g., content) and if
content is null/undefined/empty, throw an Error with a clear message (including
maybe the raw response or status) instead of returning ''; otherwise return the
content. This ensures the function fails fast and surfaces the failure in
CI/Discord posting flows.


// ─── Discord ──────────────────────────────────────────────────────────────────
Expand Down Expand Up @@ -225,7 +230,7 @@ if (filteredCount === 0) {
process.exit(0);
}

const notes = await callClaude(userPrompt);
const notes = await callLLM(userPrompt);
console.log('\n── Release Notes ──\n');
console.log(notes);

Expand Down
Loading