Build ref link point to commit not compare if only one commit was pushed (#673)

close #401
This commit is contained in:
6543 2022-01-08 22:06:00 +01:00 committed by GitHub
parent 7986eba002
commit 1588495b1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View file

@ -84,15 +84,20 @@ func buildFromPush(hook *pushHook) *model.Build {
}
message := ""
link := hook.Compare
if len(hook.Commits) > 0 {
message = hook.Commits[0].Message
}
if len(hook.Commits) == 1 {
link = hook.Commits[0].URL
}
return &model.Build{
Event: model.EventPush,
Commit: hook.After,
Ref: hook.Ref,
Link: hook.Compare,
Link: link,
Branch: strings.TrimPrefix(hook.Ref, "refs/heads/"),
Message: message,
Avatar: avatar,

View file

@ -101,7 +101,7 @@ func Test_parse(t *testing.T) {
g.Assert(build.Event).Equal(model.EventPush)
g.Assert(build.Commit).Equal(hook.After)
g.Assert(build.Ref).Equal(hook.Ref)
g.Assert(build.Link).Equal(hook.Compare)
g.Assert(build.Link).Equal(hook.Commits[0].URL)
g.Assert(build.Branch).Equal("master")
g.Assert(build.Message).Equal(hook.Commits[0].Message)
g.Assert(build.Avatar).Equal("http://1.gravatar.com/avatar/8c58a0be77ee441bb8f8595b7f1b4e87")