summaryrefslogtreecommitdiffstats
path: root/models/webhook_slack.go
diff options
context:
space:
mode:
authorBwko <bouwko@gmail.com>2016-11-24 22:35:47 +0100
committerBwko <bouwko@gmail.com>2016-11-25 07:55:08 +0100
commit33a2ac38301e07ab78cbee07788e80668ca5b6fa (patch)
treec31f2babfc690f17964a5f4c0fa0de7e4e942236 /models/webhook_slack.go
parentece19f4a5e948a1e0fab7a1a0d64f39d5ad8d9d3 (diff)
downloadgitea-33a2ac38301e07ab78cbee07788e80668ca5b6fa.tar.gz
gitea-33a2ac38301e07ab78cbee07788e80668ca5b6fa.zip
Lint models/update.go & webhook_slack.go
Diffstat (limited to 'models/webhook_slack.go')
-rw-r--r--models/webhook_slack.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/models/webhook_slack.go b/models/webhook_slack.go
index 9b70b09354..f6b2a70f93 100644
--- a/models/webhook_slack.go
+++ b/models/webhook_slack.go
@@ -16,6 +16,7 @@ import (
"code.gitea.io/gitea/modules/setting"
)
+// SlackMeta contains the slack metdata
type SlackMeta struct {
Channel string `json:"channel"`
Username string `json:"username"`
@@ -23,6 +24,7 @@ type SlackMeta struct {
Color string `json:"color"`
}
+// SlackPayload contains the information about the slack channel
type SlackPayload struct {
Channel string `json:"channel"`
Text string `json:"text"`
@@ -33,6 +35,7 @@ type SlackPayload struct {
Attachments []SlackAttachment `json:"attachments"`
}
+// SlackAttachment contains the slack message
type SlackAttachment struct {
Fallback string `json:"fallback"`
Color string `json:"color"`
@@ -40,8 +43,10 @@ type SlackAttachment struct {
Text string `json:"text"`
}
+// SetSecret sets the slack secret
func (p *SlackPayload) SetSecret(_ string) {}
+// JSONPayload Marshals the SlackPayload to json
func (p *SlackPayload) JSONPayload() ([]byte, error) {
data, err := json.MarshalIndent(p, "", " ")
if err != nil {
@@ -50,6 +55,7 @@ func (p *SlackPayload) JSONPayload() ([]byte, error) {
return data, nil
}
+// SlackTextFormatter replaces &, <, > with HTML characters
// see: https://api.slack.com/docs/formatting
func SlackTextFormatter(s string) string {
// replace & < >
@@ -59,6 +65,7 @@ func SlackTextFormatter(s string) string {
return s
}
+// SlackShortTextFormatter replaces &, <, > with HTML characters
func SlackShortTextFormatter(s string) string {
s = strings.Split(s, "\n")[0]
// replace & < >
@@ -68,6 +75,7 @@ func SlackShortTextFormatter(s string) string {
return s
}
+// SlackLinkFormatter creates a link compatablie with slack
func SlackLinkFormatter(url string, text string) string {
return fmt.Sprintf("<%s|%s>", url, SlackTextFormatter(text))
}
@@ -181,6 +189,7 @@ func getSlackPullRequestPayload(p *api.PullRequestPayload, slack *SlackMeta) (*S
}, nil
}
+// GetSlackPayload converts a slack webhook into a SlackPayload
func GetSlackPayload(p api.Payloader, event HookEventType, meta string) (*SlackPayload, error) {
s := new(SlackPayload)