Skip to content

Conversation

gabrielsoltz
Copy link

@gabrielsoltz gabrielsoltz commented Jul 23, 2025

Hi, this PR fixes and implements the use of the slack_username configuration, which was previously non-functional.

I'm also adding slack_icon_emoji, which sets the emoji for the username. When adding this, I noticed that shoutrrr does not support setting icon_emoji in Slack messages.

Slack expects the icon_emoji to be included in the JSON payload of the POST request, but shoutrrr only supports basic message text and allows the username through a query parameter — it does not permit modifying the JSON payload structure to include icon_emoji.

To fully support both username and emoji, I replaced the shoutrrr.Send() call with a simple http.Post using a custom JSON payload. This provides complete control and ensures compatibility with Slack’s webhook API.

I hope this is okay. If not, I can leave the slack_icon_emoji out of this PR and revert to the shoutrrr implementation, but at least it will make the slack_username work.

Summary by CodeRabbit

  • New Features

    • Added support for customizing the Slack message icon using an emoji when sending notifications.
  • Documentation

    • Updated the example configuration in the README to show how to set a custom emoji icon for Slack notifications.

Copy link

coderabbitai bot commented Jul 23, 2025

Walkthrough

The changes update the Slack provider's message sending logic to use direct HTTP POST requests to Slack's webhook endpoint, replacing the previous use of the shoutrrr library. A new configuration option, slack_icon_emoji, is introduced and documented in the README, allowing users to set a custom emoji icon for Slack messages.

Changes

Files Change Summary
pkg/providers/slack/slack.go Replaced shoutrrr with direct HTTP POST to Slack webhook, added SlackIconEmoji to options, updated imports.
README.md Documented new slack_icon_emoji configuration option in example Slack provider YAML.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant SlackProvider
    participant SlackWebhook

    User->>SlackProvider: Send(message, options)
    SlackProvider->>SlackWebhook: HTTP POST (JSON: text, username, icon_emoji)
    SlackWebhook-->>SlackProvider: HTTP response
    SlackProvider-->>User: Success/Error
Loading

Estimated code review effort

3 (~40 minutes)

Poem

A bunny hopped and sent a note,
With emoji ghosts that gently float.
No shoutrrr pipes, just HTTP,
Direct to Slack, as quick can be!
Now messages wear a cheerful face—
🐰🎉 Code hops ahead with style and grace!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/providers/slack/slack.go (1)

55-92: Consider adding empty URL validation before prefix check.

While the webhook URL prefix validation is good, consider also checking for empty URLs first to provide clearer error messages.

 // Send via webhook with emoji and username
+if pr.SlackWebHookURL == "" {
+    err := errors.Wrap(fmt.Errorf("slack webhook URL is required"),
+        fmt.Sprintf("failed to send slack notification for id: %s ", pr.ID))
+    SlackErr = multierr.Append(SlackErr, err)
+    continue
+}
 if !strings.HasPrefix(pr.SlackWebHookURL, "https://hooks.slack.com/services/") {
     err := errors.Wrap(fmt.Errorf("invalid slack webhook URL"),
         fmt.Sprintf("failed to send slack notification for id: %s ", pr.ID))
     SlackErr = multierr.Append(SlackErr, err)
     continue
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 36f061c and 220a2e5.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • pkg/providers/slack/slack.go (4 hunks)
🔇 Additional comments (2)
pkg/providers/slack/slack.go (1)

32-32: Field addition looks good!

The new SlackIconEmoji field follows the existing naming conventions and structure pattern.

README.md (1)

91-91: Documentation updates are clear and consistent!

The new slack_icon_emoji configuration option is properly documented with a valid example emoji format.

Also applies to: 98-98

Comment on lines +101 to 110
resp, err := http.Post(pr.SlackWebHookURL, "application/json", bytes.NewBuffer(jsonPayload))
if err != nil || resp.StatusCode >= 400 {
if err == nil {
err = fmt.Errorf("received non-success status: %s", resp.Status)
}
err = errors.Wrap(err, fmt.Sprintf("failed to send slack notification for id: %s", pr.ID))
SlackErr = multierr.Append(SlackErr, err)
continue
}
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Critical: Close response body and add request timeout.

The HTTP response body must be closed to prevent resource leaks. Also, consider adding a timeout to prevent hanging requests.

+client := &http.Client{
+    Timeout: 10 * time.Second,
+}
+
-resp, err := http.Post(pr.SlackWebHookURL, "application/json", bytes.NewBuffer(jsonPayload))
+resp, err := client.Post(pr.SlackWebHookURL, "application/json", bytes.NewBuffer(jsonPayload))
+if resp != nil {
+    defer resp.Body.Close()
+}
 if err != nil || resp.StatusCode >= 400 {
     if err == nil {
         err = fmt.Errorf("received non-success status: %s", resp.Status)
     }
     err = errors.Wrap(err, fmt.Sprintf("failed to send slack notification for id: %s", pr.ID))
     SlackErr = multierr.Append(SlackErr, err)
     continue
 }

Don't forget to add the time import at the top of the file.

🤖 Prompt for AI Agents
In pkg/providers/slack/slack.go around lines 101 to 110, the HTTP response body
is not closed, causing potential resource leaks, and the HTTP request lacks a
timeout, risking hanging requests. Fix this by deferring resp.Body.Close()
immediately after the POST request succeeds, and replace http.Post with an
http.Client that has a timeout set (e.g., 10 seconds). Also, add the "time"
package import at the top of the file to support the timeout configuration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant