Skip to content

Commit

Permalink
added github.dev link support and removed raw links
Browse files Browse the repository at this point in the history
  • Loading branch information
hellt committed Oct 22, 2023
1 parent 64f3307 commit 78ae4ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
8 changes: 6 additions & 2 deletions utils/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func (u *GithubURL) Parse(ghURL string) error {
return fmt.Errorf("%w %s", errInvalidGithubURL, ghURL)
}

// github.dev links can be cloned using github.com
if parsedURL.Host == "github.dev" {
parsedURL.Host = "github.com"
}

u.URLBase = parsedURL.Scheme + "://" + parsedURL.Host
u.ProjectOwner = splitPath[1]

Expand Down Expand Up @@ -101,6 +106,5 @@ func CloneGithubRepo(u *GithubURL) error {
// IsGitHubURL checks if the url is a github url.
func IsGitHubURL(url string) bool {
return strings.Contains(url, "github.com") ||
strings.Contains(url, "github.dev") ||
strings.Contains(url, "raw.githubusercontent.com")
strings.Contains(url, "github.dev")
}
15 changes: 10 additions & 5 deletions utils/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ func TestIsGitHubURL(t *testing.T) {
input: "gitlab.com/containers",
want: false,
},
{
name: "raw.githubusercontent.com/containers",
input: "raw.githubusercontent.com/containers",
want: true,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -81,6 +76,16 @@ func TestGithubURLParse(t *testing.T) {
},
expectedError: nil,
},
{
name: "bare github.dev url with trailing slash",
ghURL: "https://github.dev/srl-labs/repo-name/",
expectedResult: &GithubURL{
URLBase: "https://github.com",
ProjectOwner: "srl-labs",
RepositoryName: "repo-name",
},
expectedError: nil,
},
{
name: "bare github url with .git suffix",
ghURL: "https://github.com/srl-labs/repo-name.git",
Expand Down

0 comments on commit 78ae4ae

Please sign in to comment.