From 82c534ad18920720141899b2153e4d07c92545bf Mon Sep 17 00:00:00 2001 From: brice Date: Fri, 6 May 2016 22:14:19 +0200 Subject: [PATCH] Suppression de EventBranch --- remote/gogs/gogs.go | 7 ++++++- remote/gogs/helper.go | 19 +++++++++++++++++-- remote/gogs/types.go | 1 + 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/remote/gogs/gogs.go b/remote/gogs/gogs.go index db467964c..30981db77 100644 --- a/remote/gogs/gogs.go +++ b/remote/gogs/gogs.go @@ -166,7 +166,12 @@ func (c *client) Perm(u *model.User, owner, name string) (*model.Perm, error) { // File fetches the file from the Gogs repository and returns its contents. func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) { client := c.newClientToken(u.Token) - cfg, err := client.GetFile(r.Owner, r.Name, b.Commit, f) + buildRef := b.Commit + if buildRef == "" { + buildRef = b.Ref + } + cfg, err := client.GetFile(r.Owner, r.Name, buildRef, f) + return cfg, err } diff --git a/remote/gogs/helper.go b/remote/gogs/helper.go index dd6f91ede..ba66419f1 100644 --- a/remote/gogs/helper.go +++ b/remote/gogs/helper.go @@ -70,13 +70,28 @@ func buildFromPush(hook *pushHook) *model.Build { hook.Repo.URL, fixMalformedAvatar(hook.Sender.Avatar), ) + + var eventType string + var message string + + switch { + case hook.RefType == "tag": + eventType = model.EventTag + message = "Tag " + hook.Ref + case hook.RefType == "branch": + eventType = "" + default: + eventType = model.EventPush + message = hook.Commits[0].Message + } + return &model.Build{ - Event: model.EventPush, + Event: eventType, Commit: hook.After, Ref: hook.Ref, Link: hook.Compare, Branch: strings.TrimPrefix(hook.Ref, "refs/heads/"), - Message: hook.Commits[0].Message, + Message: message, Avatar: avatar, Author: hook.Sender.Login, Timestamp: time.Now().UTC().Unix(), diff --git a/remote/gogs/types.go b/remote/gogs/types.go index 2b9f38ed1..a2de2a0e8 100644 --- a/remote/gogs/types.go +++ b/remote/gogs/types.go @@ -5,6 +5,7 @@ type pushHook struct { Before string `json:"before"` After string `json:"after"` Compare string `json:"compare_url"` + RefType string `json:"ref_type"` Pusher struct { Name string `json:"name"`