diff --git a/remote/gogs/gogs.go b/remote/gogs/gogs.go index db467964c..4ff607068 100644 --- a/remote/gogs/gogs.go +++ b/remote/gogs/gogs.go @@ -166,7 +166,11 @@ 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 } @@ -230,7 +234,7 @@ func (c *client) Hook(r *http.Request) (*model.Repo, *model.Build, error) { case "push": var push *pushHook push, err = parsePush(r.Body) - if err == nil { + if err == nil && push.RefType != "branch" { repo = repoFromPush(push) build = buildFromPush(push) } diff --git a/remote/gogs/helper.go b/remote/gogs/helper.go index dd6f91ede..eb75937fe 100644 --- a/remote/gogs/helper.go +++ b/remote/gogs/helper.go @@ -70,13 +70,26 @@ 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 + 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"`