Add build links to Slack notifications
This commit is contained in:
parent
2838997eb1
commit
6cfecc13d9
1 changed files with 16 additions and 11 deletions
|
@ -3,15 +3,14 @@ package notify
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"path"
|
||||||
//"github.com/drone/drone/pkg/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
slackEndpoint = "https://%s.slack.com/services/hooks/incoming-webhook?token=%s"
|
slackEndpoint = "https://%s.slack.com/services/hooks/incoming-webhook?token=%s"
|
||||||
slackStartedMessage = "*Building* %s, commit %s, author %s"
|
slackStartedMessage = "*Building* %s, commit <%s|%s>, author %s"
|
||||||
slackSuccessMessage = "*Success* %s, commit %s, author %s"
|
slackSuccessMessage = "*Success* %s, commit <%s|%s>, author %s"
|
||||||
slackFailureMessage = "*Failed* %s, commit %s, author %s"
|
slackFailureMessage = "*Failed* %s, commit <%s|%s>, author %s"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Slack struct {
|
type Slack struct {
|
||||||
|
@ -37,19 +36,25 @@ func (s *Slack) Send(context *Context) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getBuildUrl(context *Context) string {
|
||||||
|
return context.Host + path.Join("/", context.Repo.Slug, "commit", context.Commit.Hash)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getMessage(context *Context, message string) string {
|
||||||
|
url := getBuildUrl(context)
|
||||||
|
return fmt.Sprintf(message, context.Repo.Name, url, context.Commit.HashShort(), context.Commit.Author)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Slack) sendStarted(context *Context) error {
|
func (s *Slack) sendStarted(context *Context) error {
|
||||||
msg := fmt.Sprintf(slackStartedMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
|
return s.send(getMessage(context, slackStartedMessage))
|
||||||
return s.send(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Slack) sendSuccess(context *Context) error {
|
func (s *Slack) sendSuccess(context *Context) error {
|
||||||
msg := fmt.Sprintf(slackSuccessMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
|
return s.send(getMessage(context, slackSuccessMessage))
|
||||||
return s.send(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Slack) sendFailure(context *Context) error {
|
func (s *Slack) sendFailure(context *Context) error {
|
||||||
msg := fmt.Sprintf(slackFailureMessage, context.Repo.Name, context.Commit.HashShort(), context.Commit.Author)
|
return s.send(getMessage(context, slackFailureMessage))
|
||||||
return s.send(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// helper function to send HTTP requests
|
// helper function to send HTTP requests
|
||||||
|
|
Loading…
Reference in a new issue