diff --git a/remote/gitea/fixtures/hooks.go b/remote/gitea/fixtures/hooks.go index 0765a8c07..8f79ff3e2 100644 --- a/remote/gitea/fixtures/hooks.go +++ b/remote/gitea/fixtures/hooks.go @@ -53,6 +53,7 @@ const HookPush = ` // HookPushTag is a sample Gitea tag hook const HookPushTag = `{ + "sha": "ef98532add3b2feb7a137426bba1248724367df5", "secret": "l26Un7G7HXogLAvsyf2hOA4EMARSTsR3", "ref": "v1.0.0", "ref_type": "tag", diff --git a/remote/gitea/helper.go b/remote/gitea/helper.go index d625dc040..587daf383 100644 --- a/remote/gitea/helper.go +++ b/remote/gitea/helper.go @@ -100,9 +100,9 @@ func buildFromTag(hook *pushHook) *model.Build { return &model.Build{ Event: model.EventTag, - Commit: hook.After, + Commit: hook.Sha, Ref: fmt.Sprintf("refs/tags/%s", hook.Ref), - Link: fmt.Sprintf("%s/src/%s", hook.Repo.URL, hook.Ref), + Link: fmt.Sprintf("%s/src/tag/%s", hook.Repo.URL, hook.Ref), Branch: fmt.Sprintf("refs/tags/%s", hook.Ref), Message: fmt.Sprintf("created tag %s", hook.Ref), Avatar: avatar, diff --git a/remote/gitea/helper_test.go b/remote/gitea/helper_test.go index 4bdcdc41b..3ff0d8c94 100644 --- a/remote/gitea/helper_test.go +++ b/remote/gitea/helper_test.go @@ -44,6 +44,7 @@ func Test_parse(t *testing.T) { hook, err := parsePush(buf) g.Assert(err == nil).IsTrue() g.Assert(hook.Ref).Equal("v1.0.0") + g.Assert(hook.Sha).Equal("ef98532add3b2feb7a137426bba1248724367df5") g.Assert(hook.Repo.Name).Equal("hello-world") g.Assert(hook.Repo.URL).Equal("http://gitea.golang.org/gordon/hello-world") g.Assert(hook.Repo.FullName).Equal("gordon/hello-world") @@ -105,6 +106,18 @@ func Test_parse(t *testing.T) { g.Assert(repo.Link).Equal(hook.Repo.URL) }) + g.It("Should return a Build struct from a tag hook", func() { + buf := bytes.NewBufferString(fixtures.HookPushTag) + hook, _ := parsePush(buf) + build := buildFromTag(hook) + g.Assert(build.Event).Equal(model.EventTag) + g.Assert(build.Commit).Equal(hook.Sha) + g.Assert(build.Ref).Equal("refs/tags/v1.0.0") + g.Assert(build.Branch).Equal("refs/tags/v1.0.0") + g.Assert(build.Link).Equal("http://gitea.golang.org/gordon/hello-world/src/tag/v1.0.0") + g.Assert(build.Message).Equal("created tag v1.0.0") + }) + g.It("Should return a Build struct from a pull_request hook", func() { buf := bytes.NewBufferString(fixtures.HookPullRequest) hook, _ := parsePullRequest(buf) @@ -132,9 +145,21 @@ func Test_parse(t *testing.T) { g.It("Should return a Perm struct from a Gitea Perm", func() { perms := []gitea.Permission{ - {true, true, true}, - {true, true, false}, - {true, false, false}, + { + Admin: true, + Push: true, + Pull: true, + }, + { + Admin: true, + Push: true, + Pull: false, + }, + { + Admin: true, + Push: false, + Pull: false, + }, } for _, from := range perms { perm := toPerm(&from) diff --git a/remote/gitea/types.go b/remote/gitea/types.go index f648f8de1..1671bd812 100644 --- a/remote/gitea/types.go +++ b/remote/gitea/types.go @@ -1,6 +1,7 @@ package gitea type pushHook struct { + Sha string `json:"sha"` Ref string `json:"ref"` Before string `json:"before"` After string `json:"after"`