mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-24 08:02:18 +02:00
feat: Remove user part of http clone url (#3462)
Some configuration of Bitbucket Datacenter seems to return username as part of the clone URL. This needs to be removed for `.netrc` to work properly. Closes #3443 --------- Signed-off-by: Thor Anker Kvisgård Lange <tal@netic.dk>
This commit is contained in:
parent
1d093f1b39
commit
632c946511
@ -16,6 +16,7 @@ package bitbucketdatacenter
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -40,6 +41,15 @@ func convertID(id uint64) model.ForgeRemoteID {
|
||||
return model.ForgeRemoteID(fmt.Sprintf("%d", id))
|
||||
}
|
||||
|
||||
func anonymizeLink(link string) (href string) {
|
||||
parsed, err := url.Parse(link)
|
||||
if err != nil {
|
||||
return link
|
||||
}
|
||||
parsed.User = nil
|
||||
return parsed.String()
|
||||
}
|
||||
|
||||
func convertRepo(from *bb.Repository, perm *model.Perm, branch string) *model.Repo {
|
||||
r := &model.Repo{
|
||||
ForgeRemoteID: convertID(from.ID),
|
||||
@ -55,7 +65,7 @@ func convertRepo(from *bb.Repository, perm *model.Perm, branch string) *model.Re
|
||||
|
||||
for _, l := range from.Links["clone"] {
|
||||
if l.Name == "http" {
|
||||
r.Clone = l.Href
|
||||
r.Clone = anonymizeLink(l.Href)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,7 +67,7 @@ func TestHelper(t *testing.T) {
|
||||
"clone": {
|
||||
{
|
||||
Name: "http",
|
||||
Href: "https://git.domain/clone",
|
||||
Href: "https://user@git.domain/clone",
|
||||
},
|
||||
},
|
||||
"self": {
|
||||
@ -86,6 +86,7 @@ func TestHelper(t *testing.T) {
|
||||
g.Assert(to.SCMKind).Equal(model.RepoGit)
|
||||
g.Assert(to.FullName).Equal("PRJ/REPO")
|
||||
g.Assert(to.Perm).Equal(perm)
|
||||
g.Assert(to.Clone).Equal("https://git.domain/clone")
|
||||
})
|
||||
|
||||
g.It("should convert repository push event", func() {
|
||||
|
Loading…
Reference in New Issue
Block a user