Merge pull request #2256 from appleboy/gitea-tag

fix missing commit sha and wrong tag link for Gitea.
This commit is contained in:
Brad Rydzewski 2017-11-15 09:47:44 -08:00 committed by GitHub
commit 8eacbe382b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 32 additions and 5 deletions

View file

@ -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",

View file

@ -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,

View file

@ -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)

View file

@ -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"`