git: change message formatting

This commit is contained in:
Chris Sexton 2019-10-26 15:14:51 -04:00 committed by Chris Sexton
parent 686ba1d662
commit 6393d8bb22
1 changed files with 16 additions and 5 deletions

View File

@ -68,13 +68,18 @@ func (p *GitPlugin) gitlabEvent(w http.ResponseWriter, r *http.Request) {
case gitlab.PushEventPayload: case gitlab.PushEventPayload:
push := payload.(gitlab.PushEventPayload) push := payload.(gitlab.PushEventPayload)
repo = push.Repository.Name repo = push.Repository.Name
user := push.UserName
commits := "" commits := ""
for _, c := range push.Commits { for _, c := range push.Commits {
m := strings.Split(c.Message, "\n")[0] m := strings.Split(c.Message, "\n")[0]
commits += fmt.Sprintf("%s (%s) %s", c.Author.Name, c.ID[:5], m) commits += fmt.Sprintf("%s pushed to %s (<%s|%s>) %s\n",
c.Author.Name,
repo,
c.URL,
c.ID[:7],
m,
)
} }
msg = fmt.Sprintf("%s pushed to %s:\n%s", user, repo, commits) msg = commits
default: default:
w.WriteHeader(500) w.WriteHeader(500)
fmt.Fprintf(w, "unknown payload: %+v", payload) fmt.Fprintf(w, "unknown payload: %+v", payload)
@ -113,9 +118,15 @@ func (p *GitPlugin) githubEvent(w http.ResponseWriter, r *http.Request) {
commits := "" commits := ""
for _, c := range push.Commits { for _, c := range push.Commits {
m := strings.Split(c.Message, "\n")[0] m := strings.Split(c.Message, "\n")[0]
commits += fmt.Sprintf("%s (%s) %s", c.Author.Name, c.Sha[:5], m) commits += fmt.Sprintf("%s pushed to %s (<%s|%s>) %s\n",
c.Author.Name,
repo,
c.URL,
c.ID[:7],
m,
)
} }
msg = fmt.Sprintf("%s pushed to %s: \n%s", push.Pusher.Name, push.Repository.Name, commits) msg = commits
case github.PullRequestPayload: case github.PullRequestPayload:
pr := payload.(github.PullRequestPayload) pr := payload.(github.PullRequestPayload)
if pr.Action != "opened" { if pr.Action != "opened" {