Skip to content

Conversation

@mehdiMj-ir
Copy link
Contributor

@mehdiMj-ir mehdiMj-ir commented Apr 16, 2025

Summary

Support for custom Slack title via configuration #927

Fixes #927

Checklist

  • Tested and/or added tests to validate that the changes work as intended, if applicable.
  • Updated documentation in README.md, if applicable.

@github-actions github-actions bot added the feature New feature or request label Apr 16, 2025
@mehdiMj-ir
Copy link
Contributor Author

Could you please review this pull request? If it suits your application, feel free to merge it into the main codebase or alternatively, write your own version if preferred.
I currently run two instances of this app: one for internal requests and another for external ones. I'd like to customize the title.

Copy link
Owner

@TwiN TwiN left a comment

Choose a reason for hiding this comment

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

Can you revert all indentation changes?

@mehdiMj-ir
Copy link
Contributor Author

I'm sorry I overlooked the indentation and didn't follow your workflow preference of using tabs instead of spaces.

Copy link
Owner

@TwiN TwiN left a comment

Choose a reason for hiding this comment

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

Code looks fine, but can you add a test?

@TwiN
Copy link
Owner

TwiN commented Sep 20, 2025

@mehdiMj-ir fyi it's not my workflow preference, it's what gofmt does.

Tbf I care more about consistency than specific preferences

@mehdiMj-ir
Copy link
Contributor Author

TBH, I'm a sysAdmin, not a programmer 😅
I really love your project because it lets me document and organize our URLs on our GitLab.
It's great that you're so consistent with your work, it’s already shaping up to be an excellent product.
I'll add a test and follow up with you soon.

@mehdiMj-ir
Copy link
Contributor Author

I am indeed sorry, I am not a programmer. I tried chatGPT but it's not like your code and it have a hard coded url

Go test code.
func TestAlertProvider_WithCustomTitle(t *testing.T) {
	provider := Provider{
		Title:      "🚨 Custom Title 🚨",
		WebhookURL: "https://hooks.slack.com/test-webhook",
	}
	alert := &alert.Alert{
		Description: "Service is DOWN",
	}
	endpoint := &core.Endpoint{
		Name: "my-service",
	}
	result := &core.Result{
		Success: false,
	}
	body, err := provider.buildRequestBody(alert, endpoint, result)
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	if !strings.Contains(body, provider.Title) {
		t.Errorf("expected body to contain custom title %q, got: %s", provider.Title, body)
	}
}

func TestAlertProvider_DefaultTitleWhenEmpty(t *testing.T) {
	provider := Provider{
		WebhookURL: "https://hooks.slack.com/test-webhook",
		// Title left empty
	}
	alert := &alert.Alert{
		Description: "Service is DOWN",
	}
	endpoint := &core.Endpoint{
		Name: "my-service",
	}
	result := &core.Result{
		Success: false,
	}
	body, err := provider.buildRequestBody(alert, endpoint, result)
	if err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
	// Default title should fallback to endpoint name
	if !strings.Contains(body, "my-service") {
		t.Errorf("expected body to contain default title %q, got: %s", "my-service", body)
	}
}
Once again, I am sorry.

@mehdiMj-ir mehdiMj-ir closed this Sep 20, 2025
@TwiN
Copy link
Owner

TwiN commented Sep 20, 2025

@mehdiMj-ir There's no need to be sorry, don't worry.

Re-open your PR, I'll add the tests myself when I have a moment 🙂

@mehdiMj-ir mehdiMj-ir reopened this Sep 20, 2025
@TwiN TwiN changed the title feat: add custom slack title fix(alerting): Support custom slack title Sep 20, 2025
@TwiN TwiN merged commit e6576e9 into TwiN:master Sep 21, 2025
2 checks passed
@TwiN TwiN added area/alerting Related to alerting bug Something isn't working and removed feature New feature or request labels Sep 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/alerting Related to alerting bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support different icon/emoji in alerting title depending on the kind of message + title templating

2 participants