mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-30 12:20:33 +00:00
Testing author label length limitation.
Signed-off-by: Bo-Yi Wu <appleboy.tw@gmail.com>
This commit is contained in:
parent
e82ddd0022
commit
83056ab8b3
3 changed files with 59 additions and 65 deletions
|
@ -67,15 +67,14 @@ func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build {
|
|||
name := refParts[2]
|
||||
commitType := refParts[1]
|
||||
|
||||
|
||||
//Ensuring the author label is not longer then 40 for the label of the commit author (default size in the db)
|
||||
authorLabel := hook.Changesets.Values[0].ToCommit.Author.Name
|
||||
if (len(authorLabel) > 40) {
|
||||
authorLabel = authorLabel[0:40]
|
||||
if len(authorLabel) > 40 {
|
||||
authorLabel = authorLabel[0:37] + "..."
|
||||
}
|
||||
|
||||
build := &model.Build{
|
||||
Commit: hook.RefChanges[0].ToHash, // TODO check for index value
|
||||
Commit: hook.RefChanges[0].ToHash, // TODO check for index value
|
||||
Branch: name,
|
||||
Message: hook.Changesets.Values[0].ToCommit.Message, //TODO check for index Values
|
||||
Avatar: avatarLink(hook.Changesets.Values[0].ToCommit.Author.EmailAddress),
|
||||
|
|
|
@ -1,12 +1,11 @@
|
|||
package bitbucketserver
|
||||
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"github.com/drone/drone/model"
|
||||
"github.com/drone/drone/remote/bitbucketserver/internal"
|
||||
"github.com/franela/goblin"
|
||||
"github.com/mrjones/oauth"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func Test_helper(t *testing.T) {
|
||||
|
@ -14,7 +13,6 @@ func Test_helper(t *testing.T) {
|
|||
g := goblin.Goblin(t)
|
||||
g.Describe("Bitbucket Server converter", func() {
|
||||
|
||||
|
||||
g.It("should convert repository lite", func() {
|
||||
from := &internal.Repo{}
|
||||
from.Project.Key = "octocat"
|
||||
|
@ -26,7 +24,6 @@ func Test_helper(t *testing.T) {
|
|||
g.Assert(to.Name).Equal("hello-world")
|
||||
})
|
||||
|
||||
|
||||
g.It("should convert repository", func() {
|
||||
from := &internal.Repo{
|
||||
Slug: "hello-world",
|
||||
|
@ -62,7 +59,7 @@ func Test_helper(t *testing.T) {
|
|||
Token: "foo",
|
||||
}
|
||||
user := &internal.User{
|
||||
Slug: "x12f",
|
||||
Slug: "x12f",
|
||||
EmailAddress: "huh@huh.com",
|
||||
}
|
||||
|
||||
|
@ -72,18 +69,16 @@ func Test_helper(t *testing.T) {
|
|||
g.Assert(result.Token).Equal("foo")
|
||||
})
|
||||
|
||||
|
||||
|
||||
g.It("should convert push hook to build", func() {
|
||||
change := internal.PostHook{}
|
||||
|
||||
change.RefChanges = append(change.RefChanges, internal.RefChange{
|
||||
RefID: "refs/heads/master",
|
||||
RefID: "refs/heads/master",
|
||||
ToHash: "73f9c44d",
|
||||
})
|
||||
|
||||
value := internal.Value{}
|
||||
value.ToCommit.Author.Name = "John Doe"
|
||||
value.ToCommit.Author.Name = "John Doe, Appleboy, Mary, Janet E. Dawson and Ann S. Palmer"
|
||||
value.ToCommit.Author.EmailAddress = "huh@huh.com"
|
||||
value.ToCommit.Message = "message"
|
||||
|
||||
|
@ -94,7 +89,8 @@ func Test_helper(t *testing.T) {
|
|||
|
||||
build := convertPushHook(&change, "http://base.com")
|
||||
g.Assert(build.Event).Equal(model.EventPush)
|
||||
g.Assert(build.Author).Equal("John Doe")
|
||||
// Ensuring the author label is not longer then 40
|
||||
g.Assert(build.Author).Equal("John Doe, Appleboy, Mary, Janet E. Da...")
|
||||
g.Assert(build.Avatar).Equal(avatarLink("huh@huh.com"))
|
||||
g.Assert(build.Commit).Equal("73f9c44d")
|
||||
g.Assert(build.Branch).Equal("master")
|
||||
|
@ -106,7 +102,7 @@ func Test_helper(t *testing.T) {
|
|||
g.It("should convert tag hook to build", func() {
|
||||
change := internal.PostHook{}
|
||||
change.RefChanges = append(change.RefChanges, internal.RefChange{
|
||||
RefID: "refs/tags/v1",
|
||||
RefID: "refs/tags/v1",
|
||||
ToHash: "73f9c44d",
|
||||
})
|
||||
|
||||
|
@ -130,4 +126,4 @@ func Test_helper(t *testing.T) {
|
|||
g.Assert(build.Message).Equal("message")
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ type Repo struct {
|
|||
Forkable bool `json:"forkable"`
|
||||
ID int `json:"id"`
|
||||
Links struct {
|
||||
Clone []CloneLink`json:"clone"`
|
||||
Self []struct {
|
||||
Clone []CloneLink `json:"clone"`
|
||||
Self []struct {
|
||||
Href string `json:"href"`
|
||||
} `json:"self"`
|
||||
} `json:"links"`
|
||||
|
@ -76,56 +76,55 @@ type HookDetail struct {
|
|||
|
||||
type Value struct {
|
||||
Changes struct {
|
||||
Filter interface{} `json:"filter"`
|
||||
IsLastPage bool `json:"isLastPage"`
|
||||
Limit int `json:"limit"`
|
||||
Size int `json:"size"`
|
||||
Start int `json:"start"`
|
||||
Values []struct {
|
||||
ContentID string `json:"contentId"`
|
||||
Executable bool `json:"executable"`
|
||||
Link struct {
|
||||
Rel string `json:"rel"`
|
||||
URL string `json:"url"`
|
||||
} `json:"link"`
|
||||
NodeType string `json:"nodeType"`
|
||||
Path struct {
|
||||
Components []string `json:"components"`
|
||||
Extension string `json:"extension"`
|
||||
Name string `json:"name"`
|
||||
Parent string `json:"parent"`
|
||||
ToString string `json:"toString"`
|
||||
} `json:"path"`
|
||||
PercentUnchanged int `json:"percentUnchanged"`
|
||||
SrcExecutable bool `json:"srcExecutable"`
|
||||
Type string `json:"type"`
|
||||
} `json:"values"`
|
||||
} `json:"changes"`
|
||||
Filter interface{} `json:"filter"`
|
||||
IsLastPage bool `json:"isLastPage"`
|
||||
Limit int `json:"limit"`
|
||||
Size int `json:"size"`
|
||||
Start int `json:"start"`
|
||||
Values []struct {
|
||||
ContentID string `json:"contentId"`
|
||||
Executable bool `json:"executable"`
|
||||
Link struct {
|
||||
Rel string `json:"rel"`
|
||||
URL string `json:"url"`
|
||||
} `json:"link"`
|
||||
NodeType string `json:"nodeType"`
|
||||
Path struct {
|
||||
Components []string `json:"components"`
|
||||
Extension string `json:"extension"`
|
||||
Name string `json:"name"`
|
||||
Parent string `json:"parent"`
|
||||
ToString string `json:"toString"`
|
||||
} `json:"path"`
|
||||
PercentUnchanged int `json:"percentUnchanged"`
|
||||
SrcExecutable bool `json:"srcExecutable"`
|
||||
Type string `json:"type"`
|
||||
} `json:"values"`
|
||||
} `json:"changes"`
|
||||
FromCommit struct {
|
||||
DisplayID string `json:"displayId"`
|
||||
ID string `json:"id"`
|
||||
} `json:"fromCommit"`
|
||||
Link struct {
|
||||
Rel string `json:"rel"`
|
||||
URL string `json:"url"`
|
||||
} `json:"link"`
|
||||
ToCommit struct {
|
||||
Author struct {
|
||||
EmailAddress string `json:"emailAddress"`
|
||||
Name string `json:"name"`
|
||||
} `json:"author"`
|
||||
AuthorTimestamp int `json:"authorTimestamp"`
|
||||
DisplayID string `json:"displayId"`
|
||||
ID string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
Parents []struct {
|
||||
DisplayID string `json:"displayId"`
|
||||
ID string `json:"id"`
|
||||
} `json:"fromCommit"`
|
||||
Link struct {
|
||||
Rel string `json:"rel"`
|
||||
URL string `json:"url"`
|
||||
} `json:"link"`
|
||||
ToCommit struct {
|
||||
Author struct {
|
||||
EmailAddress string `json:"emailAddress"`
|
||||
Name string `json:"name"`
|
||||
} `json:"author"`
|
||||
AuthorTimestamp int `json:"authorTimestamp"`
|
||||
DisplayID string `json:"displayId"`
|
||||
ID string `json:"id"`
|
||||
Message string `json:"message"`
|
||||
Parents []struct {
|
||||
DisplayID string `json:"displayId"`
|
||||
ID string `json:"id"`
|
||||
} `json:"parents"`
|
||||
} `json:"toCommit"`
|
||||
} `json:"parents"`
|
||||
} `json:"toCommit"`
|
||||
}
|
||||
|
||||
|
||||
type PostHook struct {
|
||||
Changesets struct {
|
||||
Filter interface{} `json:"filter"`
|
||||
|
@ -133,7 +132,7 @@ type PostHook struct {
|
|||
Limit int `json:"limit"`
|
||||
Size int `json:"size"`
|
||||
Start int `json:"start"`
|
||||
Values []Value `json:"values"`
|
||||
Values []Value `json:"values"`
|
||||
} `json:"changesets"`
|
||||
RefChanges []RefChange `json:"refChanges"`
|
||||
Repository struct {
|
||||
|
@ -156,7 +155,7 @@ type PostHook struct {
|
|||
} `json:"repository"`
|
||||
}
|
||||
|
||||
type RefChange struct {
|
||||
type RefChange struct {
|
||||
FromHash string `json:"fromHash"`
|
||||
RefID string `json:"refId"`
|
||||
ToHash string `json:"toHash"`
|
||||
|
|
Loading…
Reference in a new issue