Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION=v0.2.16
VERSION=v0.2.17

OUT_DIR=dist
YEAR?=$(shell date +"%Y")
Expand Down
2 changes: 1 addition & 1 deletion cmd/commands/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ global:
username: some-username`,
gitProvider: platmodel.GitProvidersGithub,
gitApiUrl: "some-api-url",
wantErr: "failed verifying runtime git token with git server \"some-api-url\": invalid git-token: Head \"some-api-url\": some error",
wantErr: "failed verifying runtime git token with git server \"some-api-url\": invalid git-token: Head \"/api/v3\": some error",
beforeFn: func(rt *gitmocks.MockRoundTripper) {
rt.EXPECT().RoundTrip(gomock.AssignableToTypeOf(&http.Request{})).Times(1).Return(nil, errors.New("some error"))
},
Expand Down
7 changes: 4 additions & 3 deletions internal/git/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ func getProvider(providerType ProviderType, cloneURL, certFile string) (Provider

func getGitProviderFromUserSelect(baseURL string, client *http.Client) Provider {
var providers = map[string]func(string, *http.Client) (Provider, error){
"Bitbucket": NewBitbucketServerProvider,
"GitHub": NewGithubProvider,
"GitLab": NewGitlabProvider,
"Bitbucket": NewBitbucketProvider,
"GitHub": NewGithubProvider,
"GitLab": NewGitlabProvider,
"Bitbucket Server": NewBitbucketServerProvider,
}

templates := &promptui.SelectTemplates{
Expand Down
4 changes: 1 addition & 3 deletions internal/git/provider_bitbucket-server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ func NewBitbucketServerProvider(baseURL string, client *http.Client) (Provider,
return nil, fmt.Errorf("wrong domain for bitbucket-server provider: \"%s\"\n maybe you meant to use \"bitbucket\" for the cloud git provider?", baseURL)
}

if u.Path == "" {
u.Path = BITBUCKET_SERVER_REST_ENDPOINT
}
u.Path = BITBUCKET_SERVER_REST_ENDPOINT

return &bitbucketServer{
providerType: BITBUCKET_SERVER,
Expand Down
4 changes: 2 additions & 2 deletions internal/git/provider_bitbucket-server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ func TestNewBitbucketServerProvider(t *testing.T) {
baseURL: "https://some.server",
wantApiURL: "https://some.server/rest/api/1.0",
},
"should use baseUrl as apiUrl if it has path": {
"should ignore baseUrl path and use standard api path": {
baseURL: "https://some.server/some/api/v-whatever",
wantApiURL: "https://some.server/some/api/v-whatever",
wantApiURL: "https://some.server/rest/api/1.0",
},
"should fail when base is not a valid url": {
baseURL: "https://contains-bad-\x7f",
Expand Down
6 changes: 5 additions & 1 deletion internal/git/provider_bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ type (

const (
BITBUCKET_CLOUD_DOMAIN = "bitbucket.org"
BITBUCKET_REST_ENDPOINT = "/api/2.0"
BITBUCKET_CLOUD_API_URL = "api.bitbucket.org"
BITBUCKET_REST_ENDPOINT = "/2.0"
BITBUCKET ProviderType = "bitbucket"
)

Expand Down Expand Up @@ -68,7 +69,10 @@ func NewBitbucketProvider(baseURL string, client *http.Client) (Provider, error)
return nil, fmt.Errorf("wrong domain for bitbucket provider: \"%s\", expected \"%s\"\n maybe you meant to use \"bitbucket-server\" for on-prem git provider?", baseURL, BITBUCKET_CLOUD_DOMAIN)
}

// new api token working only with api.bitbucket.org/2.0
u.Host = BITBUCKET_CLOUD_API_URL
u.Path = BITBUCKET_REST_ENDPOINT
u.User = nil // make sure to remove prefix of https://user:pass@..
return &bitbucket{
providerType: BITBUCKET,
apiURL: u,
Expand Down
6 changes: 3 additions & 3 deletions internal/git/provider_bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ func TestNewBitbucketProvider(t *testing.T) {
}{
"should use standard api path when base is host only": {
baseURL: "https://bitbucket.org",
wantApiURL: "https://bitbucket.org/api/2.0",
wantApiURL: "https://api.bitbucket.org/2.0",
},
"should ignore baseUrl path if it contains it": {
baseURL: "https://bitbucket.org/some/api/v-whatever",
wantApiURL: "https://bitbucket.org/api/2.0",
wantApiURL: "https://api.bitbucket.org/2.0",
},
"should fail when base is not a valid url": {
baseURL: "https://bitbucket.org/\x7f",
Expand Down Expand Up @@ -78,7 +78,7 @@ func Test_bitbucket_verifyToken(t *testing.T) {
beforeFn func(c *mocks.MockRoundTripper)
}{
"Should fail if HEAD fails": {
wantErr: "failed checking token scope permission: failed getting current user: Head \"https://bitbucket.org/api/2.0/user\": some error",
wantErr: "failed checking token scope permission: failed getting current user: Head \"https://api.bitbucket.org/2.0/user\": some error",
beforeFn: func(c *mocks.MockRoundTripper) {
c.EXPECT().RoundTrip(gomock.AssignableToTypeOf(&http.Request{})).Return(nil, errors.New("some error"))
},
Expand Down
2 changes: 1 addition & 1 deletion internal/git/provider_github.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func NewGithubProvider(baseURL string, client *http.Client) (Provider, error) {

if strings.Contains(u.Hostname(), GITHUB_CLOUD_DOMAIN) {
u, _ = url.Parse(GITHUB_CLOUD_API_URL)
} else if u.Path == "" {
} else {
u.Path = GITHUB_REST_ENDPOINT
}

Expand Down
4 changes: 2 additions & 2 deletions internal/git/provider_github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ func TestNewGithubProvider(t *testing.T) {
wantApiURL: "https://some.server/api/v3",
wantCloud: false,
},
"should use baseUrl as apiUrl if it on-prem and has path": {
"should ignore on-prem baseUrl path and use standard api path": {
baseURL: "https://some.server/some/api/v-whatever",
wantApiURL: "https://some.server/some/api/v-whatever",
wantApiURL: "https://some.server/api/v3",
wantCloud: false,
},
"should fail when base is not a valid url": {
Expand Down
7 changes: 5 additions & 2 deletions internal/git/provider_gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ const (
GITLAB_CLOUD_DOMAIN = "gitlab.com"
GITLAB_REST_ENDPOINT = "/api/v4"
GITLAB ProviderType = "gitlab"
GITLAB_CLOUD_API_URL = "https://gitlab.com"
)

func NewGitlabProvider(baseURL string, client *http.Client) (Provider, error) {
u, err := url.Parse(baseURL)
u, err := url.Parse(baseURL) // baseURL is the isc url
if err != nil {
return nil, err
}

if u.Host == GITLAB_CLOUD_DOMAIN || u.Path == "" {
if strings.Contains(u.Hostname(), GITLAB_CLOUD_DOMAIN) {
u, _ = url.Parse(GITLAB_CLOUD_API_URL)
} else {
u.Path = GITLAB_REST_ENDPOINT
}

Expand Down
8 changes: 4 additions & 4 deletions internal/git/provider_gitlab_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ func TestNewGitlabProvider(t *testing.T) {
}{
"should use standard api path when base is cloud host": {
baseURL: "https://gitlab.com",
wantApiURL: "https://gitlab.com/api/v4",
wantApiURL: "https://gitlab.com",
wantCloud: true,
},
"should use standard api path when base is cloud host with path": {
baseURL: "https://gitlab.com/org/repo",
wantApiURL: "https://gitlab.com/api/v4",
wantApiURL: "https://gitlab.com",
wantCloud: true,
},
"should use standard api path when base is host only": {
baseURL: "https://some.server",
wantApiURL: "https://some.server/api/v4",
wantCloud: false,
},
"should use baseUrl as apiUrl if it on-prem and has path": {
"should ignore on-prem baseUrl path and use standard api path": {
baseURL: "https://some.server/some/api/v-whatever",
wantApiURL: "https://some.server/some/api/v-whatever",
wantApiURL: "https://some.server/api/v4",
wantCloud: false,
},
"should fail when base is not a valid url": {
Expand Down
6 changes: 3 additions & 3 deletions internal/git/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ func TestGetProvider(t *testing.T) {
"should return gitlab when url is in gitlab.com": {
baseURL: "https://gitlab.com/org/repo",
wantType: GITLAB,
wantApiURL: "https://gitlab.com/api/v4",
wantApiURL: "https://gitlab.com",
},
"should return bitbucket when url is in bitbucket.org": {
baseURL: "https://bitbucket.org/org/repo",
wantType: BITBUCKET,
wantApiURL: "https://bitbucket.org/api/2.0",
wantApiURL: "https://api.bitbucket.org/2.0",
},
"should use providedType when domain doesn't match known cloud providers": {
providerType: BITBUCKET_SERVER,
baseURL: "https://some.on-prem-provider.com/org/repo",
wantType: BITBUCKET_SERVER,
wantApiURL: "https://some.on-prem-provider.com/org/repo",
wantApiURL: "https://some.on-prem-provider.com/rest/api/1.0",
},
"should fail if provider does not match known cloud url, and no providerType was supplied": {
providerType: GITLAB,
Expand Down