From 1152e430c42bc5b69ed7d3eb66425e29000164d2 Mon Sep 17 00:00:00 2001 From: Joachim Hill-Grannec Date: Mon, 13 Jun 2016 18:10:16 -0500 Subject: [PATCH] Cleaner way to remove the username from the git clone URL --- remote/bitbucketserver/bitbucketserver.go | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/remote/bitbucketserver/bitbucketserver.go b/remote/bitbucketserver/bitbucketserver.go index 170946d2..ab2d5298 100644 --- a/remote/bitbucketserver/bitbucketserver.go +++ b/remote/bitbucketserver/bitbucketserver.go @@ -154,9 +154,9 @@ func (c *client) Repo(u *model.User, owner, name string) (*model.Repo, error) { client := NewClientWithToken(&c.Consumer, u.Token) - url := fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos/%s", c.URL, owner, name) + urlString := fmt.Sprintf("%s/rest/api/1.0/projects/%s/repos/%s", c.URL, owner, name) - response, err := client.Get(url) + response, err := client.Get(urlString) if err != nil { log.Error(err) } @@ -178,13 +178,12 @@ func (c *client) Repo(u *model.User, owner, name string) (*model.Repo, error) { for _, item := range bsRepo.Links.Clone { if item.Name == "http" { - //TODO sdhould find a clean way to do this - //We are removing the username out of the link to allow for Netrc to work - splitUrl := strings.SplitAfterN(item.Href,"@",2) - splitProtocal := strings.SplitAfterN(splitUrl[0],"//",2) - cleanUrl := fmt.Sprintf("%s%s",splitProtocal[0], splitUrl[1]) - - repo.Clone = cleanUrl + uri, err := url.Parse(item.Href) + if err != nil { + return err + } + uri.User = nil + repo.Clone = uri.String() } } for _, item := range bsRepo.Links.Self {