diff --git a/apis/githubapi/apis.go b/apis/githubapi/apis.go index 06f60c6..e218a91 100644 --- a/apis/githubapi/apis.go +++ b/apis/githubapi/apis.go @@ -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 { diff --git a/githubparser/v1/parser.go b/githubparser/v1/parser.go index e54b004..37a03ff 100644 --- a/githubparser/v1/parser.go +++ b/githubparser/v1/parser.go @@ -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() } diff --git a/githubparser/v1/parser_test.go b/githubparser/v1/parser_test.go index dfb8ee1..c669ca1 100644 --- a/githubparser/v1/parser_test.go +++ b/githubparser/v1/parser_test.go @@ -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) { @@ -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) { @@ -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()) + } } diff --git a/init.go b/init.go index 78b8094..00bf54d 100644 --- a/init.go +++ b/init.go @@ -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) diff --git a/init_test.go b/init_test.go index acdf69e..cb707bb 100644 --- a/init_test.go +++ b/init_test.go @@ -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)