Skip to content

Commit

Permalink
Merge pull request #11 from anubhav06/github-issue-10
Browse files Browse the repository at this point in the history
add github support for www subdomain
  • Loading branch information
David Wertenteil authored May 14, 2023
2 parents 361182e + 305e4d5 commit 45c7e53
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 4 deletions.
5 changes: 3 additions & 2 deletions apis/githubapi/apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (
)

const (
DEFAULT_HOST string = "github.com"
RAW_HOST string = "raw.githubusercontent.com"
DEFAULT_HOST string = "github.com"
RAW_HOST string = "raw.githubusercontent.com"
SUBDOMAIN_HOST string = "www.github.com"
)

type IGitHubAPI interface {
Expand Down
2 changes: 1 addition & 1 deletion githubparser/v1/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (gh *GitHubURL) GetURL() *url.URL {
}
}
func IsHostGitHub(host string) bool {
return host == githubapi.DEFAULT_HOST || host == githubapi.RAW_HOST
return host == githubapi.DEFAULT_HOST || host == githubapi.RAW_HOST || host == githubapi.SUBDOMAIN_HOST
}

func (gh *GitHubURL) GetProvider() string { return apis.ProviderGitHub.String() }
Expand Down
17 changes: 17 additions & 0 deletions githubparser/v1/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var (
urlD = "https://raw.githubusercontent.com/kubescape/go-git-url/master/files/file0.json"
urlE = "git@github.com:kubescape/go-git-url.git"
urlF = "git@github.com:foobar/kubescape/go-git-url.git"
urlG = "https://www.github.com/kubescape/go-git-url"
)

func TestNewGitHubParserWithURL(t *testing.T) {
Expand Down Expand Up @@ -73,6 +74,16 @@ func TestNewGitHubParserWithURL(t *testing.T) {
_, _ = NewGitHubParserWithURL(urlF)
})
}
{
gh, err := NewGitHubParserWithURL(urlG)
assert.NoError(t, err)
assert.Equal(t, "github.com", gh.GetHostName())
assert.Equal(t, "kubescape", gh.GetOwnerName())
assert.Equal(t, "go-git-url", gh.GetRepoName())
assert.Equal(t, urlA, gh.GetURL().String())
assert.Equal(t, "", gh.GetBranchName())
assert.Equal(t, "", gh.GetPath())
}
}

func TestSetDefaultBranch(t *testing.T) {
Expand All @@ -94,4 +105,10 @@ func TestSetDefaultBranch(t *testing.T) {
assert.NoError(t, gh.SetDefaultBranchName())
assert.Equal(t, "master", gh.GetBranchName())
}
{
gh, err := NewGitHubParserWithURL(urlG)
assert.NoError(t, err)
assert.NoError(t, gh.SetDefaultBranchName())
assert.Equal(t, "master", gh.GetBranchName())
}
}
2 changes: 1 addition & 1 deletion init.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewGitAPI(fullURL string) (IGitAPI, error) {
}

switch hostUrl {
case githubapi.DEFAULT_HOST, githubapi.RAW_HOST:
case githubapi.DEFAULT_HOST, githubapi.RAW_HOST, githubapi.SUBDOMAIN_HOST:
return githubparserv1.NewGitHubParserWithURL(fullURL)
case gitlabapi.DEFAULT_HOST:
return gitlabparserv1.NewGitLabParserWithURL(fullURL)
Expand Down
10 changes: 10 additions & 0 deletions init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ func TestNewGitURL(t *testing.T) {
assert.Equal(t, "", gh.GetBranchName())
assert.Equal(t, githubURL, gh.GetURL().String())
}
{ // parse github
const githubURL = "https://www.github.com/kubescape/go-git-url"
gh, err := NewGitURL(githubURL)
assert.NoError(t, err)
assert.Equal(t, "github", gh.GetProvider())
assert.Equal(t, "kubescape", gh.GetOwnerName())
assert.Equal(t, "go-git-url", gh.GetRepoName())
assert.Equal(t, "", gh.GetBranchName())
assert.Equal(t, "https://github.com/kubescape/go-git-url", gh.GetURL().String())
}
{ // parse github
const githubURL = "git@github.com:kubescape/go-git-url.git"
gh, err := NewGitURL(githubURL)
Expand Down

0 comments on commit 45c7e53

Please sign in to comment.