Skip to content

Commit 0eac9e5

Browse files
committed
feat(context-ledger): add helpful API key missing comment
- Check for missing ANTHROPIC_API_KEY before running - Post helpful setup comment on PRs when API key is missing - Skip changelog generation gracefully with API_KEY_MISSING status - Provide clear instructions for getting and setting up the API key
1 parent f84fbb1 commit 0eac9e5

File tree

2 files changed

+59
-1
lines changed

2 files changed

+59
-1
lines changed

.github/workflows/changelog.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,4 @@ jobs:
5050
version_increment: ${{ inputs.version_increment || 'auto' }}
5151
auto_commit: ${{ github.event_name != 'pull_request' }}
5252
create_pr_suggestions: ${{ github.event_name == 'pull_request' }}
53+
continue-on-error: true # Allow PR to succeed even if API key is missing

action.yml

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,57 @@ runs:
327327
console.log('✅ Changelog already in PR diff');
328328
}
329329
330-
- name: Generate changelog with Claude
330+
- name: Check for API key
331331
if: steps.check-suggestions.outputs.should_skip != 'true'
332+
id: check-api-key
333+
shell: bash
334+
run: |
335+
if [ -z "${{ inputs.anthropic_api_key }}" ]; then
336+
echo "api_key_missing=true" >> $GITHUB_OUTPUT
337+
echo "⚠️ ANTHROPIC_API_KEY is missing"
338+
else
339+
echo "api_key_missing=false" >> $GITHUB_OUTPUT
340+
echo "✅ ANTHROPIC_API_KEY is present"
341+
fi
342+
343+
- name: Comment about missing API key
344+
if: steps.check-suggestions.outputs.should_skip != 'true' && steps.check-api-key.outputs.api_key_missing == 'true' && github.event_name == 'pull_request'
345+
uses: actions/github-script@v7
346+
with:
347+
github-token: ${{ inputs.github_token }}
348+
script: |
349+
const message = `## 🔑 Context Ledger Setup Required
350+
351+
Hi! I'm Context Ledger, an AI-powered changelog generator. I'd love to help maintain your changelog, but I need an API key to get started.
352+
353+
### To enable automatic changelog generation:
354+
355+
1. **Get an Anthropic API key**: Sign up at https://console.anthropic.com/
356+
2. **Add it to your repository secrets**:
357+
- Go to your repository Settings → Secrets and variables → Actions
358+
- Click "New repository secret"
359+
- Name: \`ANTHROPIC_API_KEY\`
360+
- Value: Your API key from Anthropic
361+
3. **Re-run this workflow** or push a new commit
362+
363+
### What I'll do once set up:
364+
- 📝 Analyze your code changes with AI
365+
- 🎯 Generate relevant changelog entries
366+
- 💡 Suggest them as PR comments (like this one!)
367+
- 🚀 Keep your documentation in sync automatically
368+
369+
---
370+
*This comment was generated by [Context Ledger](https://github.com/lukemun/context-ledger)*`;
371+
372+
github.rest.issues.createComment({
373+
issue_number: context.issue.number,
374+
owner: context.repo.owner,
375+
repo: context.repo.repo,
376+
body: message
377+
});
378+
379+
- name: Generate changelog with Claude
380+
if: steps.check-suggestions.outputs.should_skip != 'true' && steps.check-api-key.outputs.api_key_missing != 'true'
332381
id: generate-changelog
333382
shell: bash
334383
env:
@@ -587,12 +636,20 @@ runs:
587636
run: |
588637
# Set outputs based on what happened
589638
SHOULD_SKIP="${{ steps.check-suggestions.outputs.should_skip }}"
639+
API_KEY_MISSING="${{ steps.check-api-key.outputs.api_key_missing }}"
640+
590641
if [ "$SHOULD_SKIP" == "true" ]; then
591642
echo "status=SKIPPED" >> $GITHUB_OUTPUT
592643
echo "changelog_updated=false" >> $GITHUB_OUTPUT
593644
echo "has_changes=false" >> $GITHUB_OUTPUT
594645
echo "changelog_content=" >> $GITHUB_OUTPUT
595646
echo "version_generated=" >> $GITHUB_OUTPUT
647+
elif [ "$API_KEY_MISSING" == "true" ]; then
648+
echo "status=API_KEY_MISSING" >> $GITHUB_OUTPUT
649+
echo "changelog_updated=false" >> $GITHUB_OUTPUT
650+
echo "has_changes=false" >> $GITHUB_OUTPUT
651+
echo "changelog_content=" >> $GITHUB_OUTPUT
652+
echo "version_generated=" >> $GITHUB_OUTPUT
596653
else
597654
STATUS="${{ steps.check-status.outputs.status }}"
598655
if [ -z "$STATUS" ]; then

0 commit comments

Comments
 (0)