Merge pull request #1498 from bsauvajon/master
Manage tag hooks from gogs
This commit is contained in:
commit
668ecb446d
3 changed files with 22 additions and 4 deletions
|
@ -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.
|
// 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) {
|
func (c *client) File(u *model.User, r *model.Repo, b *model.Build, f string) ([]byte, error) {
|
||||||
client := c.newClientToken(u.Token)
|
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
|
return cfg, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -230,7 +234,7 @@ func (c *client) Hook(r *http.Request) (*model.Repo, *model.Build, error) {
|
||||||
case "push":
|
case "push":
|
||||||
var push *pushHook
|
var push *pushHook
|
||||||
push, err = parsePush(r.Body)
|
push, err = parsePush(r.Body)
|
||||||
if err == nil {
|
if err == nil && push.RefType != "branch" {
|
||||||
repo = repoFromPush(push)
|
repo = repoFromPush(push)
|
||||||
build = buildFromPush(push)
|
build = buildFromPush(push)
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,13 +70,26 @@ func buildFromPush(hook *pushHook) *model.Build {
|
||||||
hook.Repo.URL,
|
hook.Repo.URL,
|
||||||
fixMalformedAvatar(hook.Sender.Avatar),
|
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{
|
return &model.Build{
|
||||||
Event: model.EventPush,
|
Event: eventType,
|
||||||
Commit: hook.After,
|
Commit: hook.After,
|
||||||
Ref: hook.Ref,
|
Ref: hook.Ref,
|
||||||
Link: hook.Compare,
|
Link: hook.Compare,
|
||||||
Branch: strings.TrimPrefix(hook.Ref, "refs/heads/"),
|
Branch: strings.TrimPrefix(hook.Ref, "refs/heads/"),
|
||||||
Message: hook.Commits[0].Message,
|
Message: message,
|
||||||
Avatar: avatar,
|
Avatar: avatar,
|
||||||
Author: hook.Sender.Login,
|
Author: hook.Sender.Login,
|
||||||
Timestamp: time.Now().UTC().Unix(),
|
Timestamp: time.Now().UTC().Unix(),
|
||||||
|
|
|
@ -5,6 +5,7 @@ type pushHook struct {
|
||||||
Before string `json:"before"`
|
Before string `json:"before"`
|
||||||
After string `json:"after"`
|
After string `json:"after"`
|
||||||
Compare string `json:"compare_url"`
|
Compare string `json:"compare_url"`
|
||||||
|
RefType string `json:"ref_type"`
|
||||||
|
|
||||||
Pusher struct {
|
Pusher struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
|
|
Loading…
Reference in a new issue