diff options
author | Christopher Brickley <brickley@gmail.com> | 2014-08-26 08:20:18 -0400 |
---|---|---|
committer | Christopher Brickley <brickley@gmail.com> | 2014-09-01 14:56:19 -0400 |
commit | 00a864e693434bce687f3f5145d8369583197b78 (patch) | |
tree | df25bf583ec2a0070c159bcb3d0d161d931f6801 /models/slack.go | |
parent | d55c5b9e289c0c97aa51ffe5cb5b77f703cc2a47 (diff) | |
download | gitea-00a864e693434bce687f3f5145d8369583197b78.tar.gz gitea-00a864e693434bce687f3f5145d8369583197b78.zip |
add commit compare functionality
Diffstat (limited to 'models/slack.go')
-rw-r--r-- | models/slack.go | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/models/slack.go b/models/slack.go index 0a55740947..714b2f6ca2 100644 --- a/models/slack.go +++ b/models/slack.go @@ -70,19 +70,21 @@ func getSlackPushPayload(p *Payload, slack *Slack) (*SlackPayload, error) { branchName := refSplit[len(refSplit)-1] var commitString string - // TODO: add commit compare before/after link when gogs adds it if len(p.Commits) == 1 { commitString = "1 new commit" } else { commitString = fmt.Sprintf("%d new commits", len(p.Commits)) + commitString = SlackLinkFormatter(p.CompareUrl, commitString) } - text := fmt.Sprintf("[%s:%s] %s pushed by %s", p.Repo.Name, branchName, commitString, p.Pusher.Name) + repoLink := SlackLinkFormatter(p.Repo.Url, p.Repo.Name) + branchLink := SlackLinkFormatter(p.Repo.Url+"/src/"+branchName, branchName) + text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.Name) var attachmentText string // for each commit, generate attachment text for i, commit := range p.Commits { - attachmentText += fmt.Sprintf("<%s|%s>: %s - %s", commit.Url, commit.Id[:7], SlackFormatter(commit.Message), commit.Author.Name) + attachmentText += fmt.Sprintf("%s: %s - %s", SlackLinkFormatter(commit.Url, commit.Id[:7]), SlackTextFormatter(commit.Message), SlackTextFormatter(commit.Author.Name)) // add linebreak to each commit but the last if i < len(p.Commits)-1 { attachmentText += "\n" @@ -103,7 +105,7 @@ func getSlackPushPayload(p *Payload, slack *Slack) (*SlackPayload, error) { } // see: https://api.slack.com/docs/formatting -func SlackFormatter(s string) string { +func SlackTextFormatter(s string) string { // take only first line of commit first := strings.Split(s, "\n")[0] // replace & < > @@ -112,3 +114,7 @@ func SlackFormatter(s string) string { first = strings.Replace(first, ">", ">", -1) return first } + +func SlackLinkFormatter(url string, text string) string { + return fmt.Sprintf("<%s|%s>", url, SlackTextFormatter(text)) +} |