2022-10-18 01:24:12 +00:00
|
|
|
// Copyright 2022 Woodpecker Authors
|
2018-02-19 22:24:10 +00:00
|
|
|
// Copyright 2018 Drone.IO Inc.
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
2018-03-21 13:02:17 +00:00
|
|
|
//
|
2018-02-19 22:24:10 +00:00
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
2016-08-12 22:54:36 +00:00
|
|
|
package bitbucketserver
|
|
|
|
|
|
|
|
import (
|
2017-07-14 19:58:38 +00:00
|
|
|
"testing"
|
|
|
|
|
2019-09-14 12:21:16 +00:00
|
|
|
"github.com/franela/goblin"
|
2021-06-22 10:34:35 +00:00
|
|
|
"github.com/mrjones/oauth"
|
2021-10-12 07:25:13 +00:00
|
|
|
|
2022-11-04 23:35:06 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/server/forge/bitbucketserver/internal"
|
2021-09-27 17:51:55 +00:00
|
|
|
"github.com/woodpecker-ci/woodpecker/server/model"
|
2016-08-12 22:54:36 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func Test_helper(t *testing.T) {
|
|
|
|
g := goblin.Goblin(t)
|
|
|
|
g.Describe("Bitbucket Server converter", func() {
|
|
|
|
g.It("should convert repository", func() {
|
|
|
|
from := &internal.Repo{
|
|
|
|
Slug: "hello-world",
|
|
|
|
}
|
|
|
|
from.Project.Key = "octocat"
|
|
|
|
|
2022-01-05 20:50:23 +00:00
|
|
|
// var links [1]internal.LinkType
|
2016-08-12 22:54:36 +00:00
|
|
|
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)
|
|
|
|
|
2023-03-21 22:01:59 +00:00
|
|
|
to := convertRepo(from, &model.Perm{Pull: true})
|
2016-08-12 22:54:36 +00:00
|
|
|
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")
|
2021-11-22 11:55:13 +00:00
|
|
|
g.Assert(to.SCMKind).Equal(model.RepoGit)
|
|
|
|
g.Assert(to.IsSCMPrivate).Equal(true)
|
2016-08-12 22:54:36 +00:00
|
|
|
g.Assert(to.Clone).Equal("https://server.org/foo/bar.git")
|
|
|
|
g.Assert(to.Link).Equal("https://server.org/foo/bar")
|
2023-03-21 22:01:59 +00:00
|
|
|
g.Assert(to.Perm.Pull).IsTrue()
|
2016-08-12 22:54:36 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
g.It("should convert user", func() {
|
|
|
|
token := &oauth.AccessToken{
|
|
|
|
Token: "foo",
|
|
|
|
}
|
|
|
|
user := &internal.User{
|
2016-08-13 06:07:45 +00:00
|
|
|
Slug: "x12f",
|
2016-08-12 22:54:36 +00:00
|
|
|
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")
|
|
|
|
})
|
|
|
|
|
2016-09-19 14:19:12 +00:00
|
|
|
g.It("branch should be empty", func() {
|
|
|
|
change := internal.PostHook{}
|
|
|
|
change.RefChanges = append(change.RefChanges, internal.RefChange{
|
|
|
|
RefID: "refs/heads/",
|
|
|
|
ToHash: "73f9c44d",
|
|
|
|
})
|
|
|
|
|
|
|
|
value := internal.Value{}
|
|
|
|
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"
|
|
|
|
|
|
|
|
change.Changesets.Values = append(change.Changesets.Values, value)
|
|
|
|
|
2022-09-07 17:16:40 +00:00
|
|
|
change.Repository.Project = internal.Project{
|
|
|
|
Key: "octocat",
|
|
|
|
}
|
2016-09-19 14:19:12 +00:00
|
|
|
change.Repository.Slug = "hello-world"
|
2022-10-18 01:24:12 +00:00
|
|
|
pipeline := convertPushHook(&change, "http://base.com")
|
|
|
|
g.Assert(pipeline.Branch).Equal("")
|
2016-09-19 14:19:12 +00:00
|
|
|
})
|
|
|
|
|
2022-10-18 01:24:12 +00:00
|
|
|
g.It("should convert push hook to pipeline", func() {
|
2016-08-12 22:54:36 +00:00
|
|
|
change := internal.PostHook{}
|
|
|
|
|
|
|
|
change.RefChanges = append(change.RefChanges, internal.RefChange{
|
2016-09-19 14:19:12 +00:00
|
|
|
RefID: "refs/heads/release/some-feature",
|
2016-08-12 22:54:36 +00:00
|
|
|
ToHash: "73f9c44d",
|
|
|
|
})
|
|
|
|
|
|
|
|
value := internal.Value{}
|
2016-08-13 06:07:45 +00:00
|
|
|
value.ToCommit.Author.Name = "John Doe, Appleboy, Mary, Janet E. Dawson and Ann S. Palmer"
|
2016-08-12 22:54:36 +00:00
|
|
|
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"
|
|
|
|
|
2022-10-18 01:24:12 +00:00
|
|
|
pipeline := convertPushHook(&change, "http://base.com")
|
|
|
|
g.Assert(pipeline.Event).Equal(model.EventPush)
|
2016-08-13 06:07:45 +00:00
|
|
|
// Ensuring the author label is not longer then 40
|
2022-10-18 01:24:12 +00:00
|
|
|
g.Assert(pipeline.Author).Equal("John Doe, Appleboy, Mary, Janet E. Da...")
|
|
|
|
g.Assert(pipeline.Avatar).Equal(avatarLink("huh@huh.com"))
|
|
|
|
g.Assert(pipeline.Commit).Equal("73f9c44d")
|
|
|
|
g.Assert(pipeline.Branch).Equal("release/some-feature")
|
|
|
|
g.Assert(pipeline.Link).Equal("http://base.com/projects/octocat/repos/hello-world/commits/73f9c44d")
|
|
|
|
g.Assert(pipeline.Ref).Equal("refs/heads/release/some-feature")
|
|
|
|
g.Assert(pipeline.Message).Equal("message")
|
2016-08-12 22:54:36 +00:00
|
|
|
})
|
|
|
|
|
2022-10-18 01:24:12 +00:00
|
|
|
g.It("should convert tag hook to pipeline", func() {
|
2016-08-12 22:54:36 +00:00
|
|
|
change := internal.PostHook{}
|
|
|
|
change.RefChanges = append(change.RefChanges, internal.RefChange{
|
2016-08-13 06:07:45 +00:00
|
|
|
RefID: "refs/tags/v1",
|
2016-08-12 22:54:36 +00:00
|
|
|
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"
|
|
|
|
|
2022-10-18 01:24:12 +00:00
|
|
|
pipeline := convertPushHook(&change, "http://base.com")
|
|
|
|
g.Assert(pipeline.Event).Equal(model.EventTag)
|
|
|
|
g.Assert(pipeline.Author).Equal("John Doe")
|
|
|
|
g.Assert(pipeline.Avatar).Equal(avatarLink("huh@huh.com"))
|
|
|
|
g.Assert(pipeline.Commit).Equal("73f9c44d")
|
|
|
|
g.Assert(pipeline.Branch).Equal("v1")
|
|
|
|
g.Assert(pipeline.Link).Equal("http://base.com/projects/octocat/repos/hello-world/commits/73f9c44d")
|
|
|
|
g.Assert(pipeline.Ref).Equal("refs/tags/v1")
|
|
|
|
g.Assert(pipeline.Message).Equal("message")
|
2016-08-12 22:54:36 +00:00
|
|
|
})
|
|
|
|
})
|
2016-08-13 06:07:45 +00:00
|
|
|
}
|