attach methods to Flowdock struct

This commit is contained in:
nevalla 2014-08-27 21:38:38 +03:00
parent ac1c7bb9fa
commit 299b9619e1

View File

@ -38,7 +38,7 @@ func (f *Flowdock) Send(context *Context) error {
return nil return nil
} }
func getBuildUrl(context *Context) string { func (f *Flowdock) getBuildUrl(context *Context) string {
branchQuery := url.Values{} branchQuery := url.Values{}
if context.Commit.Branch != "" { if context.Commit.Branch != "" {
branchQuery.Set("branch", context.Commit.Branch) branchQuery.Set("branch", context.Commit.Branch)
@ -47,19 +47,19 @@ func getBuildUrl(context *Context) string {
return fmt.Sprintf("%s/%s/commit/%s?%s", context.Host, context.Repo.Slug, context.Commit.Hash, branchQuery.Encode()) return fmt.Sprintf("%s/%s/commit/%s?%s", context.Host, context.Repo.Slug, context.Commit.Hash, branchQuery.Encode())
} }
func getRepoUrl(context *Context) string { func (f *Flowdock) getRepoUrl(context *Context) string {
return fmt.Sprintf("%s/%s", context.Host, context.Repo.Slug) return fmt.Sprintf("%s/%s", context.Host, context.Repo.Slug)
} }
func getMessage(context *Context) string { func (f *Flowdock) getMessage(context *Context) string {
buildUrl := fmt.Sprintf("<a href=\"%s\"><span class=\"commit-sha\">%s</span></a>", getBuildUrl(context), context.Commit.HashShort()) buildUrl := fmt.Sprintf("<a href=\"%s\"><span class=\"commit-sha\">%s</span></a>", f.getBuildUrl(context), context.Commit.HashShort())
return fmt.Sprintf(flowdockMessage, context.Repo.Name, buildUrl, context.Commit.Status, context.Commit.Author, context.Commit.Message, getRepoUrl(context)) return fmt.Sprintf(flowdockMessage, context.Repo.Name, buildUrl, context.Commit.Status, context.Commit.Author, context.Commit.Message, f.getRepoUrl(context))
} }
func (f *Flowdock) sendStarted(context *Context) error { func (f *Flowdock) sendStarted(context *Context) error {
fromAddress := context.Commit.Author fromAddress := context.Commit.Author
subject := fmt.Sprintf(flowdockStartedSubject, context.Repo.Name, context.Commit.Branch) subject := fmt.Sprintf(flowdockStartedSubject, context.Repo.Name, context.Commit.Branch)
msg := getMessage(context) msg := f.getMessage(context)
tags := strings.Split(f.Tags, ",") tags := strings.Split(f.Tags, ",")
return f.send(fromAddress, subject, msg, tags) return f.send(fromAddress, subject, msg, tags)
} }
@ -68,7 +68,7 @@ func (f *Flowdock) sendFailure(context *Context) error {
fromAddress := flowdockBuildFailEmail fromAddress := flowdockBuildFailEmail
tags := strings.Split(f.Tags, ",") tags := strings.Split(f.Tags, ",")
subject := fmt.Sprintf(flowdockFailureSubject, context.Repo.Name, context.Commit.Branch) subject := fmt.Sprintf(flowdockFailureSubject, context.Repo.Name, context.Commit.Branch)
msg := getMessage(context) msg := f.getMessage(context)
return f.send(fromAddress, subject, msg, tags) return f.send(fromAddress, subject, msg, tags)
} }
@ -76,7 +76,7 @@ func (f *Flowdock) sendSuccess(context *Context) error {
fromAddress := flowdockBuildOkEmail fromAddress := flowdockBuildOkEmail
tags := strings.Split(f.Tags, ",") tags := strings.Split(f.Tags, ",")
subject := fmt.Sprintf(flowdockSuccessSubject, context.Repo.Name, context.Commit.Branch) subject := fmt.Sprintf(flowdockSuccessSubject, context.Repo.Name, context.Commit.Branch)
msg := getMessage(context) msg := f.getMessage(context)
return f.send(fromAddress, subject, msg, tags) return f.send(fromAddress, subject, msg, tags)
} }