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:
Thor Anker Kvisgård Lange 2024-03-07 18:06:05 +01:00 committed by GitHub
parent 1d093f1b39
commit 632c946511
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 2 deletions

View file

@ -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)
}
}

View file

@ -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() {