Skip to content

Commit

Permalink
fix: repository url computation (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
teodora-sandu authored Apr 9, 2024
1 parent 399e577 commit aa7e17d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/util/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package util
import (
"fmt"
"net/url"
"strings"

"github.com/go-git/go-git/v5"
)
Expand All @@ -42,6 +43,8 @@ func GetRepositoryUrl(path string) (string, error) {
repoUrl := remote.Config().URLs[0]
repoUrl, err = sanitiseCredentials(repoUrl)

// we need to return an actual URL, not the SSH
repoUrl = strings.Replace(repoUrl, "git@github.com:", "https://github.com/", 1)
return repoUrl, err
}

Expand Down
4 changes: 2 additions & 2 deletions internal/util/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func Test_GetRepositoryUrl_repo_with_credentials(t *testing.T) {

func Test_GetRepositoryUrl_repo_without_credentials(t *testing.T) {
// check out a repo and prepare its config to contain credentials in the URL
expectedRepoUrl := "git@github.com:snyk-fixtures/shallow-goof-locked.git"
repoDir, _ := clone(t, expectedRepoUrl)
expectedRepoUrl := "https://github.com/snyk-fixtures/shallow-goof-locked.git"
repoDir, _ := clone(t, "git@github.com:snyk-fixtures/shallow-goof-locked.git")

// run method under test
actualUrl, err := util.GetRepositoryUrl(repoDir)
Expand Down

0 comments on commit aa7e17d

Please sign in to comment.