Skip to content

Commit 7e167ae

Browse files
Fix test mode to not send Slack notifications
- Make SLACK_WEBHOOK_URL optional in test mode - Prevent test mode from actually sending to Slack (displays payload only) - Update documentation with example notification format - Test mode now only requires ANTHROPIC_API_KEY as documented Fixes issue where test mode was sending actual Slack notifications Co-authored-by: paolomainardi <8747+paolomainardi@users.noreply.github.com>
1 parent 1fa6c1b commit 7e167ae

2 files changed

Lines changed: 30 additions & 19 deletions

File tree

docs/SLACK_NOTIFICATION_EXAMPLES.md

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,17 +148,35 @@ python3 src/slack-notify/notify-slack-on-merge.py --test
148148
```
149149

150150
The test mode will:
151-
1. Use a sample changelog diff (no git required)
152-
2. Call Claude API to analyze the diff
153-
3. Generate a notification message
154-
4. Display the Slack payload (without sending)
151+
1. Use sample changelog diffs (no git required)
152+
2. Call Claude API to analyze each diff
153+
3. Generate notification messages
154+
4. Display the Slack payload that would be sent (without actually sending)
155155

156156
This allows you to:
157157
- Test the Claude AI integration
158158
- Verify message generation
159159
- Validate Slack payload structure
160160
- All without needing `SLACK_WEBHOOK_URL` or git history
161161

162+
## Example Notification
163+
164+
When significant features are detected, the notification appears in Slack like this:
165+
166+
```
167+
🚀 New Sparkdock Release
168+
169+
This release brings significant infrastructure improvements and expanded development environment options:
170+
171+
• Automated Slack notifications for feature releases - development team announcements are now streamlined through automated notifications for significant changes merged to the master branch
172+
173+
• Lima container environment with Docker Desktop replacement support - developers now have a lightweight alternative to Docker Desktop that reduces resource consumption while maintaining full container functionality
174+
175+
• New shell enhancement system with eza, starship, and fzf integration - enhanced command-line productivity through modern tools including better file listings, an improved prompt, and powerful fuzzy finding capabilities
176+
177+
Commit: abc1234 by sparkfabrik
178+
```
179+
162180
## Customizing Messages
163181

164182
To adjust the notification style or content, edit the prompt in `src/slack-notify/prompts/analyze-changelog.txt`:

src/slack-notify/notify-slack-on-merge.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@
9090
]
9191

9292

93-
def check_env():
93+
def check_env(require_slack=True):
9494
"""Check required environment variables. Exits if missing."""
9595
missing = []
9696
if not os.environ.get("ANTHROPIC_API_KEY"):
9797
missing.append("ANTHROPIC_API_KEY")
98-
if not os.environ.get("SLACK_WEBHOOK_URL"):
98+
if require_slack and not os.environ.get("SLACK_WEBHOOK_URL"):
9999
missing.append("SLACK_WEBHOOK_URL")
100100

101101
if missing:
@@ -254,17 +254,10 @@ def run_test(test, commit_sha, commit_url, author):
254254
if DEBUG:
255255
print(f"\nGenerated message:\n---\n{message}\n---\n")
256256
payload = create_slack_payload(message, commit_url, commit_sha, author)
257-
if DEBUG:
258-
print(f"Slack payload:\n{json.dumps(payload, indent=2)}\n")
259-
260-
print(f"{YELLOW}Sending Slack notification...{NC}")
261-
try:
262-
if send_slack(payload):
263-
print(f"{GREEN}✅ Slack notification sent{NC}\n")
264-
else:
265-
print(f"{RED}✗ Failed to send Slack notification{NC}\n")
266-
except Exception as e:
267-
print(f"{RED}✗ Slack error: {e}{NC}\n")
257+
258+
print(f"{YELLOW}Test mode: Notification would be sent. Payload below for verification:{NC}")
259+
print(json.dumps(payload, indent=2))
260+
print()
268261

269262
# Validate result
270263
expected = test.get("expected")
@@ -362,11 +355,11 @@ def production_mode(changelog_file, commit_sha, commit_url, author):
362355

363356
def main():
364357
"""Main entry point."""
365-
check_env()
366-
367358
if len(sys.argv) == 2 and sys.argv[1] == "--test":
359+
check_env(require_slack=False)
368360
test_mode()
369361
elif len(sys.argv) == 5:
362+
check_env(require_slack=True)
370363
production_mode(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4])
371364
else:
372365
print(__doc__)

0 commit comments

Comments
 (0)