diff options
author | Ethan Koenig <ethantkoenig@gmail.com> | 2017-10-29 19:04:25 -0700 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2017-10-30 10:04:25 +0800 |
commit | 513375c429435ba60a667b219bdfb00e5b760b38 (patch) | |
tree | 9f516c8d0ebbdc66808c9017df7db2ff9aa34b57 /models/webhook_slack.go | |
parent | 6e98812ecf4efb6f53d72414ca8f67b14fac6595 (diff) | |
download | gitea-513375c429435ba60a667b219bdfb00e5b760b38.tar.gz gitea-513375c429435ba60a667b219bdfb00e5b760b38.zip |
Make URL scheme unambiguous (#2408)
* Make URL scheme unambiguous
Redirect old routes to new routes
* Fix redirects to new URL scheme, and update template
* Fix branches/_new endpoints, and update integration test
Diffstat (limited to 'models/webhook_slack.go')
-rw-r--r-- | models/webhook_slack.go | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/models/webhook_slack.go b/models/webhook_slack.go index ca43cfd427..dd25a8d7df 100644 --- a/models/webhook_slack.go +++ b/models/webhook_slack.go @@ -80,12 +80,22 @@ func SlackLinkFormatter(url string, text string) string { return fmt.Sprintf("<%s|%s>", url, SlackTextFormatter(text)) } -func getSlackCreatePayload(p *api.CreatePayload, slack *SlackMeta) (*SlackPayload, error) { - // created tag/branch - refName := git.RefEndName(p.Ref) +// SlackLinkToRef slack-formatter link to a repo ref +func SlackLinkToRef(repoURL, ref string) string { + refName := git.RefEndName(ref) + switch { + case strings.HasPrefix(ref, git.BranchPrefix): + return SlackLinkFormatter(repoURL+"/src/branch/"+refName, refName) + case strings.HasPrefix(ref, git.TagPrefix): + return SlackLinkFormatter(repoURL+"/src/tag/"+refName, refName) + default: + return SlackLinkFormatter(repoURL+"/src/commit/"+refName, refName) + } +} +func getSlackCreatePayload(p *api.CreatePayload, slack *SlackMeta) (*SlackPayload, error) { repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.Name) - refLink := SlackLinkFormatter(p.Repo.HTMLURL+"/src/"+refName, refName) + refLink := SlackLinkToRef(p.Repo.HTMLURL, p.Ref) text := fmt.Sprintf("[%s:%s] %s created by %s", repoLink, refLink, p.RefType, p.Sender.UserName) return &SlackPayload{ @@ -99,7 +109,6 @@ func getSlackCreatePayload(p *api.CreatePayload, slack *SlackMeta) (*SlackPayloa func getSlackPushPayload(p *api.PushPayload, slack *SlackMeta) (*SlackPayload, error) { // n new commits var ( - branchName = git.RefEndName(p.Ref) commitDesc string commitString string ) @@ -116,7 +125,7 @@ func getSlackPushPayload(p *api.PushPayload, slack *SlackMeta) (*SlackPayload, e } repoLink := SlackLinkFormatter(p.Repo.HTMLURL, p.Repo.Name) - branchLink := SlackLinkFormatter(p.Repo.HTMLURL+"/src/"+branchName, branchName) + branchLink := SlackLinkToRef(p.Repo.HTMLURL, p.Ref) text := fmt.Sprintf("[%s:%s] %s pushed by %s", repoLink, branchLink, commitString, p.Pusher.UserName) var attachmentText string |