Skip to content

Commit 285378d

Browse files
authored
CR-13227-github-enterprise (#513)
1 parent 893822d commit 285378d

File tree

10 files changed

+71
-58
lines changed

10 files changed

+71
-58
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
VERSION=v0.0.457
1+
VERSION=v0.0.458
22

33

44
OUT_DIR=dist

cmd/commands/runtime_install.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,13 @@ func ensureGitData(cmd *cobra.Command, opts *RuntimeInstallOptions) error {
323323
return err
324324
}
325325

326-
opts.gitProvider, err = cfgit.GetProvider(cfgit.ProviderType(opts.InsCloneOpts.Provider), opts.InsCloneOpts.Repo)
326+
baseURL, _, _, _, _, _, _ := aputil.ParseGitUrl(opts.InsCloneOpts.Repo)
327+
opts.gitProvider, err = cfgit.GetProvider(cfgit.ProviderType(opts.InsCloneOpts.Provider), baseURL)
327328
if err != nil {
328329
return err
329330
}
330331

331-
if opts.gitProvider.Type() != cfgit.GITHUB_CLOUD && !opts.EnableGitProviders {
332+
if opts.gitProvider.Type() != cfgit.GITHUB && !opts.EnableGitProviders {
332333
return fmt.Errorf("Unsupported git provider type %s", opts.gitProvider.Type())
333334
}
334335

@@ -581,6 +582,7 @@ func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
581582

582583
ingressControllerName := opts.IngressController.Name()
583584

585+
repoURL := opts.InsCloneOpts.URL()
584586
token, iv, err := createRuntimeOnPlatform(ctx, &model.RuntimeInstallationArgs{
585587
RuntimeName: opts.RuntimeName,
586588
Cluster: server,
@@ -590,7 +592,7 @@ func runRuntimeInstall(ctx context.Context, opts *RuntimeInstallOptions) error {
590592
IngressClass: &opts.IngressClass,
591593
IngressController: &ingressControllerName,
592594
ComponentNames: componentNames,
593-
Repo: &opts.InsCloneOpts.Repo,
595+
Repo: &repoURL,
594596
Recover: &opts.FromRepo,
595597
})
596598
handleCliStep(reporter.InstallStepCreateRuntimeOnPlatform, "Creating runtime on platform", err, false, true)
@@ -2074,8 +2076,8 @@ func ensureGitIntegrationOpts(opts *RuntimeInstallOptions) error {
20742076
}
20752077

20762078
opts.GitIntegrationCreationOpts.Provider = provider
2077-
apiUrl := opts.gitProvider.ApiUrl()
2078-
opts.GitIntegrationCreationOpts.APIURL = &apiUrl
2079+
baseURL := opts.gitProvider.BaseURL()
2080+
opts.GitIntegrationCreationOpts.APIURL = &baseURL
20792081

20802082
return nil
20812083
}

docs/releases/release_notes.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cf version
2323

2424
```bash
2525
# download and extract the binary
26-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.457/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.458/cf-linux-amd64.tar.gz | tar zx
2727

2828
# move the binary to your $PATH
2929
mv ./cf-linux-amd64 /usr/local/bin/cf
@@ -36,7 +36,7 @@ cf version
3636

3737
```bash
3838
# download and extract the binary
39-
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.457/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.458/cf-darwin-amd64.tar.gz | tar zx
4040

4141
# move the binary to your $PATH
4242
mv ./cf-darwin-amd64 /usr/local/bin/cf

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.18
44

55
require (
66
github.com/Masterminds/semver/v3 v3.1.1
7-
github.com/argoproj-labs/argocd-autopilot v0.4.2
7+
github.com/argoproj-labs/argocd-autopilot v0.4.3
88
github.com/argoproj/applicationset v0.4.1
99
github.com/argoproj/argo-cd/v2 v2.4.6
1010
github.com/argoproj/argo-events v0.17.1-0.20220327045437-70eaafe9afec

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,8 @@ github.com/antonmedv/expr v1.9.0/go.mod h1:5qsM3oLGDND7sDmQGDXHkYfkjYMUX14qsgqmH
154154
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
155155
github.com/apache/thrift v0.13.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
156156
github.com/appscode/go v0.0.0-20190808133642-1d4ef1f1c1e0/go.mod h1:iy07dV61Z7QQdCKJCIvUoDL21u6AIceRhZzyleh2ymc=
157-
github.com/argoproj-labs/argocd-autopilot v0.4.2 h1:lL8yU/cu5vqrIIpfVXwHzxbdCUQDlFw5V3YFQIbzxKs=
158-
github.com/argoproj-labs/argocd-autopilot v0.4.2/go.mod h1:FV6AIgKWXubDwGAZfPzwWpQLNOneVS78qWdDRJUnAII=
157+
github.com/argoproj-labs/argocd-autopilot v0.4.3 h1:Jbiu4sf6UGZPpLjiwFlntycgwTCkC0OTKPEntraQESg=
158+
github.com/argoproj-labs/argocd-autopilot v0.4.3/go.mod h1:FV6AIgKWXubDwGAZfPzwWpQLNOneVS78qWdDRJUnAII=
159159
github.com/argoproj/applicationset v0.4.1 h1:PzTn77TK7XQB3CdpCDPbwU4pQgip0x4qvuJQ8XiBk5E=
160160
github.com/argoproj/applicationset v0.4.1/go.mod h1:cJZ7CWG80kBII4QNalyAvSr8eVifo8jKkyXoVl9qXaA=
161161
github.com/argoproj/argo-cd/v2 v2.4.6 h1:n3Y0UaAUVbdd8tBpSzwpH3iuLtzAbK1hmGXyk7ueKT4=

manifests/runtime.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
namespace: "{{ namespace }}"
66
spec:
77
defVersion: 1.0.1
8-
version: 0.0.457
8+
version: 0.0.458
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

pkg/git/provider.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ type (
2727
// Provider represents a git provider
2828
Provider interface {
2929
Type() ProviderType
30-
ApiUrl() string
30+
BaseURL() string
3131
VerifyToken(ctx context.Context, tokenType TokenType, token string) error
3232
SupportsMarketplace() bool
3333
}
@@ -41,29 +41,29 @@ const (
4141
var (
4242
providers = map[ProviderType]func(string) (Provider, error){
4343
BITBUCKET_SERVER: NewBitbucketServerProvider,
44-
GITHUB_CLOUD: NewGithubCloudProvider,
45-
GITHUB_ENT: NewGithubEnterpriseProvider,
44+
GITHUB: NewGithubProvider,
45+
GITHUB_ENT: NewGithubProvider, // for backward compatability
4646
GITLAB: NewGitlabProvider,
4747
}
4848
)
4949

50-
func GetProvider(providerType ProviderType, cloneURL string) (Provider, error) {
50+
func GetProvider(providerType ProviderType, baseURL string) (Provider, error) {
5151
if providerType != "" {
5252
fn := providers[providerType]
5353
if fn == nil {
5454
return nil, fmt.Errorf("invalid git provider %s", providerType)
5555
}
5656

57-
return fn(cloneURL)
57+
return fn(baseURL)
5858
}
5959

60-
if strings.Contains(cloneURL, GITHUB_CLOUD_DOMAIN) {
61-
return NewGithubCloudProvider(cloneURL)
60+
if strings.Contains(baseURL, GITHUB_CLOUD_DOMAIN) {
61+
return NewGithubProvider(baseURL)
6262
}
6363

64-
if strings.Contains(cloneURL, GITLAB_CLOUD_DOMAIN) {
65-
return NewGitlabProvider(cloneURL)
64+
if strings.Contains(baseURL, GITLAB_CLOUD_DOMAIN) {
65+
return NewGitlabProvider(baseURL)
6666
}
6767

68-
return nil, fmt.Errorf("failed getting provider for clone url %s", cloneURL)
68+
return nil, fmt.Errorf("failed getting provider for clone url %s", baseURL)
6969
}

pkg/git/provider_bitbucket-server.go

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ import (
2323

2424
type (
2525
bitbucketServer struct {
26-
apiURL string
26+
providerType ProviderType
27+
apiURL *url.URL
2728
}
2829
)
2930

@@ -32,24 +33,28 @@ const (
3233
BITBUCKET_SERVER ProviderType = "bitbucket-server"
3334
)
3435

35-
func NewBitbucketServerProvider(cloneURL string) (Provider, error) {
36-
u, err := url.Parse(cloneURL)
36+
func NewBitbucketServerProvider(baseURL string) (Provider, error) {
37+
u, err := url.Parse(baseURL)
3738
if err != nil {
3839
return nil, err
3940
}
4041

41-
u.Path = ""
42+
u.Path = BITBUCKET_REST_ENDPOINT
4243
return &bitbucketServer{
43-
apiURL: u.String(),
44+
providerType: BITBUCKET_SERVER,
45+
apiURL: u,
4446
}, nil
4547
}
4648

4749
func (bbs *bitbucketServer) Type() ProviderType {
48-
return BITBUCKET_SERVER
50+
return bbs.providerType
4951
}
5052

51-
func (bbs *bitbucketServer) ApiUrl() string {
52-
return bbs.apiURL
53+
func (bbs *bitbucketServer) BaseURL() string {
54+
urlClone := *bbs.apiURL
55+
urlClone.Path = ""
56+
urlClone.RawQuery = ""
57+
return urlClone.String()
5358
}
5459

5560
func (bbs *bitbucketServer) VerifyToken(ctx context.Context, tokenType TokenType, token string) error {

pkg/git/provider_github.go

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,54 +25,57 @@ import (
2525
type (
2626
github struct {
2727
providerType ProviderType
28-
apiURL string
28+
apiURL *url.URL
2929
}
3030
)
3131

3232
const (
33-
GITHUB_CLOUD_DOMAIN = "github.com"
34-
GITHUB_CLOUD_URL = "https://api.github.com"
35-
GITHUB_REST_ENDPOINT = "/api/v3"
36-
GITHUB_CLOUD ProviderType = "github"
37-
GITHUB_ENT ProviderType = "github-enterprise"
33+
GITHUB_CLOUD_DOMAIN = "github.com"
34+
GITHUB_CLOUD_BASE_URL = "https://github.com/"
35+
GITHUB_CLOUD_API_URL = "https://api.github.com"
36+
GITHUB_REST_ENDPOINT = "/api/v3"
37+
GITHUB ProviderType = "github"
38+
GITHUB_ENT ProviderType = "github-enterpeise" // for backward compatability
3839
)
3940

4041
var requiredScopes = map[TokenType][]string{
4142
RuntimeToken: {"repo", "admin:repo_hook"},
4243
PersonalToken: {"repo"},
4344
}
4445

45-
func NewGithubCloudProvider(_ string) (Provider, error) {
46-
return &github{
47-
providerType: GITHUB_CLOUD,
48-
apiURL: GITHUB_CLOUD_URL,
49-
}, nil
50-
}
46+
func NewGithubProvider(baseURL string) (Provider, error) {
47+
if baseURL == GITHUB_CLOUD_BASE_URL {
48+
baseURL = GITHUB_CLOUD_API_URL
49+
}
5150

52-
func NewGithubEnterpriseProvider(cloneURL string) (Provider, error) {
53-
u, err := url.Parse(cloneURL)
51+
u, err := url.Parse(baseURL)
5452
if err != nil {
5553
return nil, err
5654
}
5755

58-
u.Path = ""
56+
if baseURL != GITHUB_CLOUD_API_URL {
57+
u.Path = GITHUB_REST_ENDPOINT
58+
}
59+
5960
return &github{
60-
providerType: GITHUB_ENT,
61-
apiURL: u.String(),
61+
providerType: GITHUB,
62+
apiURL: u,
6263
}, nil
6364
}
6465

6566
func (g *github) Type() ProviderType {
6667
return g.providerType
6768
}
6869

69-
func (g *github) ApiUrl() string {
70-
return g.apiURL
70+
func (g *github) BaseURL() string {
71+
urlClone := *g.apiURL
72+
urlClone.Path = ""
73+
urlClone.RawQuery = ""
74+
return urlClone.String()
7175
}
7276

7377
func (g *github) VerifyToken(ctx context.Context, tokenType TokenType, token string) error {
74-
fullURL := g.apiURL + GITHUB_REST_ENDPOINT
75-
req, err := http.NewRequestWithContext(ctx, "HEAD", fullURL, nil)
78+
req, err := http.NewRequestWithContext(ctx, "HEAD", g.apiURL.String(), nil)
7679
if err != nil {
7780
return err
7881
}

pkg/git/provider_gitlab.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import (
2424
type (
2525
gitlab struct {
2626
providerType ProviderType
27-
apiURL string
27+
apiURL *url.URL
2828
}
2929
)
3030

@@ -34,25 +34,28 @@ const (
3434
GITLAB ProviderType = "gitlab"
3535
)
3636

37-
func NewGitlabProvider(cloneURL string) (Provider, error) {
38-
u, err := url.Parse(cloneURL)
37+
func NewGitlabProvider(baseURL string) (Provider, error) {
38+
u, err := url.Parse(baseURL)
3939
if err != nil {
4040
return nil, err
4141
}
4242

43-
u.Path = ""
43+
u.Path = GITLAB_REST_ENDPOINT
4444
return &gitlab{
4545
providerType: GITLAB,
46-
apiURL: u.String(),
46+
apiURL: u,
4747
}, nil
4848
}
4949

5050
func (g *gitlab) Type() ProviderType {
5151
return g.providerType
5252
}
5353

54-
func (g *gitlab) ApiUrl() string {
55-
return g.apiURL
54+
func (g *gitlab) BaseURL() string {
55+
urlClone := *g.apiURL
56+
urlClone.Path = ""
57+
urlClone.RawQuery = ""
58+
return urlClone.String()
5659
}
5760

5861
func (g *gitlab) VerifyToken(ctx context.Context, tokenType TokenType, token string) error {

0 commit comments

Comments
 (0)