-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added notification support for discord #157
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not how I would like to see this implemented. Like I told you on the slack, implement this using an interface. Create a general interface for notifier
type Notifer interface {
SendNotification(message) error
}
Create a struct for each provider for the notification like discord, slack and irc and implement this interface for these providers.
type SlackNotificationProvider struct {
WebHookUrl string
}
func NewNotifier(providerType ProviderType) Notifier {
if providerType == ProviderType.Slack
return SlackNotificationProvider{
WebHookUrl: "URL"
}
retun nil
}
func (p *SlackNotificationProvider) SendNotification(messag string) error {
// code to send notification
return nil
}
This is way more elegant than what you are currently trying to do.
Also resolve the conflicts in the pull request. |
- minor changes fixed -added documentation for WebHook URL
@shubhamgupta2956 show me a demo for this in the lab sometime today and get this merged. |
…r slack as well as discord can be called from same function
Removed return statement from SendNotification function so that now it can send notification to discord if it fails to send it to slack
- Spelling correction
|
||
//In the Discord notification provider it was using the same payload which was used for slack. | ||
//By writing "/slack" in the discord WebHookURL, it execute Slack-Compatible Webhook | ||
func NewNotifier(URL string, ProviderType ProviderTypeEnum) Notifier { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Validate URL here
pkg/notify/main.go
Outdated
|
||
func (req *Request) FillReqParams() error { | ||
req.PostPayload = PostPayload{ | ||
Username: "Beast", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put these values in notify/defaults.go and use from there.
_examples/example.config.toml
Outdated
@@ -28,3 +28,8 @@ ssh_key = "/home/vsts/.beast/secret.key" | |||
url = "[email protected]:sdslabs/nonexistent.git" | |||
name = "nonexistent" | |||
branch = "nonexistent" | |||
|
|||
[[webhooks]] | |||
url = "https://discordapp.com/api/webhooks/615970326093758464/Dui7gVZVIaGvdys87I9O2Gn9Bx3ssNkdgkxSf3etEXN0ClxlNYSeTflbJd0obO81a_m1" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actual token kyu hai example toml me?
core/config/config.go
Outdated
@@ -86,8 +86,7 @@ type BeastConfig struct { | |||
AvailableSidecars []string `toml:"available_sidecars"` | |||
GitRemote GitRemote `toml:"remote"` | |||
JWTSecret string `toml:"jwt_secret"` | |||
SlackWebHookURL string `toml:"slack_webhook"` | |||
DiscordWebHookURL string `toml:"discord_webhook"` | |||
Webhooks []Webhook `toml:webhook` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name this NotificationWebhooks
core/config/config.go
Outdated
@@ -216,6 +215,12 @@ func (config *GitRemote) ValidateGitConfig() error { | |||
return nil | |||
} | |||
|
|||
type Webhook struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NotificationWebhook
core/config/config.go
Outdated
type Webhook struct { | ||
URL string `toml:"url"` | ||
ServiceName string `toml:"service_name"` | ||
Status bool `toml:"status"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is meant by Status - true or false. Change the name to something more sensible - Active
core/manager/challenge.go
Outdated
@@ -530,7 +530,7 @@ func StartUndeployChallenge(challengeName string, purge bool) error { | |||
notify.SendNotification(notify.Success, msg) | |||
} | |||
|
|||
log.Infof("Notification for the event sent to slack.") | |||
log.Infof("Notification for the event sent.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove the f
from Infof
pkg/notify/notification_constants.go
Outdated
@@ -15,3 +15,9 @@ const ( | |||
WarningColor NotificationColor = "#FF4500" | |||
SuccessColor NotificationColor = "#32CD32" | |||
) | |||
|
|||
const ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change the file name to constants.go
only, since it is inside the notify
package we dont need the noise of notification
in the name.
pkg/notify/main.go
Outdated
func NewNotifier(URL string, ProviderType ProviderTypeEnum) Notifier { | ||
url, err := url.ParseRequestURI(URL) | ||
if url == nil || err != nil { | ||
fmt.Errorf("Invalid notification webhook URL") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return from here if there is an error.
Use error log for logging error.
core/config/config.go
Outdated
type NotificationWebhook struct { | ||
URL string `toml:"url"` | ||
ServiceName string `toml:"service_name"` | ||
Active bool `toml:"status"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toml should also be active
@@ -28,3 +28,8 @@ ssh_key = "/home/vsts/.beast/secret.key" | |||
url = "[email protected]:sdslabs/nonexistent.git" | |||
name = "nonexistent" | |||
branch = "nonexistent" | |||
|
|||
[[webhooks]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add example for slack too.
Change the field status
to active
Added Disocrd notification support using Slack-Compatible Webhook.
#144