mirror of
https://github.com/harness/drone.git
synced 2025-05-10 15:19:58 +08:00
Merge pull request #1755 from josmo/length-temp-fix
Quick fix for build author length on Stash remote
This commit is contained in:
commit
e82ddd0022
@ -111,7 +111,6 @@ func Test_helper(t *testing.T) {
|
|||||||
g.Assert(result.Avatar).Equal(user.Links.Avatar.Href)
|
g.Assert(result.Avatar).Equal(user.Links.Avatar.Href)
|
||||||
g.Assert(result.Login).Equal(user.Login)
|
g.Assert(result.Login).Equal(user.Login)
|
||||||
g.Assert(result.Token).Equal(token.AccessToken)
|
g.Assert(result.Token).Equal(token.AccessToken)
|
||||||
g.Assert(result.Token).Equal(token.AccessToken)
|
|
||||||
g.Assert(result.Secret).Equal(token.RefreshToken)
|
g.Assert(result.Secret).Equal(token.RefreshToken)
|
||||||
g.Assert(result.Expiry).Equal(token.Expiry.UTC().Unix())
|
g.Assert(result.Expiry).Equal(token.Expiry.UTC().Unix())
|
||||||
})
|
})
|
||||||
|
@ -67,13 +67,19 @@ func convertPushHook(hook *internal.PostHook, baseURL string) *model.Build {
|
|||||||
name := refParts[2]
|
name := refParts[2]
|
||||||
commitType := refParts[1]
|
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]
|
||||||
|
}
|
||||||
|
|
||||||
build := &model.Build{
|
build := &model.Build{
|
||||||
Commit: hook.RefChanges[0].ToHash, // TODO check for index value
|
Commit: hook.RefChanges[0].ToHash, // TODO check for index value
|
||||||
//Link: TODO find link
|
|
||||||
Branch: name,
|
Branch: name,
|
||||||
Message: hook.Changesets.Values[0].ToCommit.Message, //TODO check for index Values
|
Message: hook.Changesets.Values[0].ToCommit.Message, //TODO check for index Values
|
||||||
Avatar: avatarLink(hook.Changesets.Values[0].ToCommit.Author.EmailAddress),
|
Avatar: avatarLink(hook.Changesets.Values[0].ToCommit.Author.EmailAddress),
|
||||||
Author: fmt.Sprintf("%s <%s>", hook.Changesets.Values[0].ToCommit.Author.Name, hook.Changesets.Values[0].ToCommit.Author.EmailAddress),
|
Author: authorLabel,
|
||||||
Email: hook.Changesets.Values[0].ToCommit.Author.EmailAddress,
|
Email: hook.Changesets.Values[0].ToCommit.Author.EmailAddress,
|
||||||
Timestamp: time.Now().UTC().Unix(),
|
Timestamp: time.Now().UTC().Unix(),
|
||||||
Ref: hook.RefChanges[0].RefID, // TODO check for index Values
|
Ref: hook.RefChanges[0].RefID, // TODO check for index Values
|
||||||
|
133
remote/bitbucketserver/convert_test.go
Normal file
133
remote/bitbucketserver/convert_test.go
Normal file
@ -0,0 +1,133 @@
|
|||||||
|
package bitbucketserver
|
||||||
|
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"github.com/drone/drone/model"
|
||||||
|
"github.com/drone/drone/remote/bitbucketserver/internal"
|
||||||
|
"github.com/franela/goblin"
|
||||||
|
"github.com/mrjones/oauth"
|
||||||
|
)
|
||||||
|
|
||||||
|
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"
|
||||||
|
from.Slug = "hello-world"
|
||||||
|
|
||||||
|
to := convertRepoLite(from)
|
||||||
|
g.Assert(to.FullName).Equal("octocat/hello-world")
|
||||||
|
g.Assert(to.Owner).Equal("octocat")
|
||||||
|
g.Assert(to.Name).Equal("hello-world")
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
g.It("should convert repository", func() {
|
||||||
|
from := &internal.Repo{
|
||||||
|
Slug: "hello-world",
|
||||||
|
}
|
||||||
|
from.Project.Key = "octocat"
|
||||||
|
|
||||||
|
//var links [1]internal.LinkType
|
||||||
|
link := internal.CloneLink{
|
||||||
|
Name: "http",
|
||||||
|
Href: "https://x7hw@server.org/foo/bar.git",
|
||||||
|
}
|
||||||
|
from.Links.Clone = append(from.Links.Clone, link)
|
||||||
|
|
||||||
|
selfRef := internal.SelfRefLink{
|
||||||
|
Href: "https://server.org/foo/bar",
|
||||||
|
}
|
||||||
|
|
||||||
|
from.Links.Self = append(from.Links.Self, selfRef)
|
||||||
|
|
||||||
|
to := convertRepo(from)
|
||||||
|
g.Assert(to.FullName).Equal("octocat/hello-world")
|
||||||
|
g.Assert(to.Owner).Equal("octocat")
|
||||||
|
g.Assert(to.Name).Equal("hello-world")
|
||||||
|
g.Assert(to.Branch).Equal("master")
|
||||||
|
g.Assert(to.Kind).Equal(model.RepoGit)
|
||||||
|
g.Assert(to.IsPrivate).Equal(true)
|
||||||
|
g.Assert(to.Clone).Equal("https://server.org/foo/bar.git")
|
||||||
|
g.Assert(to.Link).Equal("https://server.org/foo/bar")
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("should convert user", func() {
|
||||||
|
token := &oauth.AccessToken{
|
||||||
|
Token: "foo",
|
||||||
|
}
|
||||||
|
user := &internal.User{
|
||||||
|
Slug: "x12f",
|
||||||
|
EmailAddress: "huh@huh.com",
|
||||||
|
}
|
||||||
|
|
||||||
|
result := convertUser(user, token)
|
||||||
|
g.Assert(result.Avatar).Equal(avatarLink("huh@huh.com"))
|
||||||
|
g.Assert(result.Login).Equal("x12f")
|
||||||
|
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",
|
||||||
|
ToHash: "73f9c44d",
|
||||||
|
})
|
||||||
|
|
||||||
|
value := internal.Value{}
|
||||||
|
value.ToCommit.Author.Name = "John Doe"
|
||||||
|
value.ToCommit.Author.EmailAddress = "huh@huh.com"
|
||||||
|
value.ToCommit.Message = "message"
|
||||||
|
|
||||||
|
change.Changesets.Values = append(change.Changesets.Values, value)
|
||||||
|
|
||||||
|
change.Repository.Project.Key = "octocat"
|
||||||
|
change.Repository.Slug = "hello-world"
|
||||||
|
|
||||||
|
build := convertPushHook(&change, "http://base.com")
|
||||||
|
g.Assert(build.Event).Equal(model.EventPush)
|
||||||
|
g.Assert(build.Author).Equal("John Doe")
|
||||||
|
g.Assert(build.Avatar).Equal(avatarLink("huh@huh.com"))
|
||||||
|
g.Assert(build.Commit).Equal("73f9c44d")
|
||||||
|
g.Assert(build.Branch).Equal("master")
|
||||||
|
g.Assert(build.Link).Equal("http://base.com/projects/octocat/repos/hello-world/commits/73f9c44d")
|
||||||
|
g.Assert(build.Ref).Equal("refs/heads/master")
|
||||||
|
g.Assert(build.Message).Equal("message")
|
||||||
|
})
|
||||||
|
|
||||||
|
g.It("should convert tag hook to build", func() {
|
||||||
|
change := internal.PostHook{}
|
||||||
|
change.RefChanges = append(change.RefChanges, internal.RefChange{
|
||||||
|
RefID: "refs/tags/v1",
|
||||||
|
ToHash: "73f9c44d",
|
||||||
|
})
|
||||||
|
|
||||||
|
value := internal.Value{}
|
||||||
|
value.ToCommit.Author.Name = "John Doe"
|
||||||
|
value.ToCommit.Author.EmailAddress = "huh@huh.com"
|
||||||
|
value.ToCommit.Message = "message"
|
||||||
|
|
||||||
|
change.Changesets.Values = append(change.Changesets.Values, value)
|
||||||
|
change.Repository.Project.Key = "octocat"
|
||||||
|
change.Repository.Slug = "hello-world"
|
||||||
|
|
||||||
|
build := convertPushHook(&change, "http://base.com")
|
||||||
|
g.Assert(build.Event).Equal(model.EventTag)
|
||||||
|
g.Assert(build.Author).Equal("John Doe")
|
||||||
|
g.Assert(build.Avatar).Equal(avatarLink("huh@huh.com"))
|
||||||
|
g.Assert(build.Commit).Equal("73f9c44d")
|
||||||
|
g.Assert(build.Branch).Equal("v1")
|
||||||
|
g.Assert(build.Link).Equal("http://base.com/projects/octocat/repos/hello-world/commits/73f9c44d")
|
||||||
|
g.Assert(build.Ref).Equal("refs/tags/v1")
|
||||||
|
g.Assert(build.Message).Equal("message")
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
@ -15,14 +15,20 @@ type User struct {
|
|||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CloneLink struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SelfRefLink struct {
|
||||||
|
Href string `json:"href"`
|
||||||
|
}
|
||||||
|
|
||||||
type Repo struct {
|
type Repo struct {
|
||||||
Forkable bool `json:"forkable"`
|
Forkable bool `json:"forkable"`
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Links struct {
|
Links struct {
|
||||||
Clone []struct {
|
Clone []CloneLink`json:"clone"`
|
||||||
Href string `json:"href"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
} `json:"clone"`
|
|
||||||
Self []struct {
|
Self []struct {
|
||||||
Href string `json:"href"`
|
Href string `json:"href"`
|
||||||
} `json:"self"`
|
} `json:"self"`
|
||||||
@ -33,9 +39,7 @@ type Repo struct {
|
|||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
Links struct {
|
Links struct {
|
||||||
Self []struct {
|
Self []SelfRefLink `json:"self"`
|
||||||
Href string `json:"href"`
|
|
||||||
} `json:"self"`
|
|
||||||
} `json:"links"`
|
} `json:"links"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Public bool `json:"public"`
|
Public bool `json:"public"`
|
||||||
@ -70,14 +74,7 @@ type HookDetail struct {
|
|||||||
ConfigFormKey string `json:"configFormKey"`
|
ConfigFormKey string `json:"configFormKey"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type PostHook struct {
|
type Value struct {
|
||||||
Changesets struct {
|
|
||||||
Filter interface{} `json:"filter"`
|
|
||||||
IsLastPage bool `json:"isLastPage"`
|
|
||||||
Limit int `json:"limit"`
|
|
||||||
Size int `json:"size"`
|
|
||||||
Start int `json:"start"`
|
|
||||||
Values []struct {
|
|
||||||
Changes struct {
|
Changes struct {
|
||||||
Filter interface{} `json:"filter"`
|
Filter interface{} `json:"filter"`
|
||||||
IsLastPage bool `json:"isLastPage"`
|
IsLastPage bool `json:"isLastPage"`
|
||||||
@ -126,14 +123,19 @@ type PostHook struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
} `json:"parents"`
|
} `json:"parents"`
|
||||||
} `json:"toCommit"`
|
} `json:"toCommit"`
|
||||||
} `json:"values"`
|
}
|
||||||
|
|
||||||
|
|
||||||
|
type PostHook struct {
|
||||||
|
Changesets struct {
|
||||||
|
Filter interface{} `json:"filter"`
|
||||||
|
IsLastPage bool `json:"isLastPage"`
|
||||||
|
Limit int `json:"limit"`
|
||||||
|
Size int `json:"size"`
|
||||||
|
Start int `json:"start"`
|
||||||
|
Values []Value `json:"values"`
|
||||||
} `json:"changesets"`
|
} `json:"changesets"`
|
||||||
RefChanges []struct {
|
RefChanges []RefChange `json:"refChanges"`
|
||||||
FromHash string `json:"fromHash"`
|
|
||||||
RefID string `json:"refId"`
|
|
||||||
ToHash string `json:"toHash"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
} `json:"refChanges"`
|
|
||||||
Repository struct {
|
Repository struct {
|
||||||
Forkable bool `json:"forkable"`
|
Forkable bool `json:"forkable"`
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
@ -153,3 +155,10 @@ type PostHook struct {
|
|||||||
StatusMessage string `json:"statusMessage"`
|
StatusMessage string `json:"statusMessage"`
|
||||||
} `json:"repository"`
|
} `json:"repository"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type RefChange struct {
|
||||||
|
FromHash string `json:"fromHash"`
|
||||||
|
RefID string `json:"refId"`
|
||||||
|
ToHash string `json:"toHash"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user