Skip to content

Commit d0fbc81

Browse files
CR-14124 git integrestion step for bitbucket cloud (#556)
* git integrestion step for bitbucket cloud * bump * bump * bump app-proxy and go-sdk * bump * resolve comments * bump * fix lint Co-authored-by: Noam Gal <noam.gal@codefresh.io>
1 parent 16fb947 commit d0fbc81

File tree

10 files changed

+46
-21
lines changed

10 files changed

+46
-21
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.499
1+
VERSION=v0.0.500
22

33
OUT_DIR=dist
44
YEAR?=$(shell date +"%Y")

cmd/commands/common.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,9 @@ func ensureGitUserToken(ctx context.Context, opts *RuntimeInstallOptions) error
296296
}
297297

298298
log.G(ctx).Infof("Personal git token was not provided. Using runtime git token to register user: \"%s\". You may replace your personal git token at any time from the UI in the user settings", currentUser.Name)
299+
300+
opts.GitIntegrationRegistrationOpts.Username = opts.InsCloneOpts.Auth.Username
301+
299302
return nil
300303
}
301304

cmd/commands/integrations.go

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ type (
3838
Provider model.GitProviders
3939
SharingPolicy model.SharingPolicy
4040
}
41+
42+
GitIntegrationRegistrationOpts struct {
43+
Name string
44+
Token string
45+
Username string
46+
}
4147
)
4248

4349
var gitProvidersByName = map[string]model.GitProviders{
@@ -317,32 +323,45 @@ func RunGitIntegrationRemoveCommand(ctx context.Context, client sdk.AppProxyAPI,
317323
}
318324

319325
func NewGitIntegrationRegisterCommand(client *sdk.AppProxyAPI) *cobra.Command {
320-
var opts model.RegisterToGitIntegrationArgs
321-
326+
opts := &GitIntegrationRegistrationOpts{}
322327
cmd := &cobra.Command{
323328
Use: "register [NAME]",
324329
Short: "Register to a git integrations",
325330
Args: cobra.MaximumNArgs(1),
326331
RunE: func(cmd *cobra.Command, args []string) error {
327332
if len(args) > 0 {
328-
opts.Name = &args[0]
333+
opts.Name = args[0]
329334
}
330335

331-
return RunGitIntegrationRegisterCommand(cmd.Context(), *client, &opts)
336+
return RunGitIntegrationRegisterCommand(cmd.Context(), *client, opts)
332337
},
333338
}
334339

335340
util.Die(viper.BindEnv("token", "GIT_TOKEN"))
336-
337341
cmd.Flags().StringVar(&opts.Token, "token", "", "Authentication token")
338342

343+
util.Die(viper.BindEnv("username", "GIT_USER"))
344+
345+
cmd.Flags().StringVar(&opts.Username, "username", "", "Authentication user name")
346+
339347
util.Die(cmd.MarkFlagRequired("token"))
340348

341349
return cmd
342350
}
343351

344-
func RunGitIntegrationRegisterCommand(ctx context.Context, client sdk.AppProxyAPI, opts *model.RegisterToGitIntegrationArgs) error {
345-
intg, err := client.GitIntegrations().Register(ctx, opts)
352+
func RunGitIntegrationRegisterCommand(ctx context.Context, client sdk.AppProxyAPI, opts *GitIntegrationRegistrationOpts) error {
353+
regOpts := &model.RegisterToGitIntegrationArgs{
354+
Token: opts.Token,
355+
}
356+
if opts.Username != "" {
357+
regOpts.Username = &opts.Username
358+
}
359+
360+
if opts.Name != "" {
361+
regOpts.Name = &opts.Name
362+
}
363+
364+
intg, err := client.GitIntegrations().Register(ctx, regOpts)
346365
if err != nil {
347366
return fmt.Errorf("failed to register to git integration: %w", err)
348367
}

cmd/commands/runtime_install.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ type (
9696
GsCloneOpts *apgit.CloneOptions
9797
InsCloneOpts *apgit.CloneOptions
9898
GitIntegrationCreationOpts *apmodel.AddGitIntegrationArgs
99-
GitIntegrationRegistrationOpts *apmodel.RegisterToGitIntegrationArgs
99+
GitIntegrationRegistrationOpts *GitIntegrationRegistrationOpts
100100
KubeFactory kube.Factory
101101
CommonConfig *runtime.CommonConfig
102102
NamespaceLabels map[string]string
@@ -121,7 +121,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
121121
SharingPolicy: apmodel.SharingPolicyAllUsersInAccount,
122122
APIURL: &gitIntegrationApiURL,
123123
},
124-
GitIntegrationRegistrationOpts: &apmodel.RegisterToGitIntegrationArgs{},
124+
GitIntegrationRegistrationOpts: &GitIntegrationRegistrationOpts{},
125125
}
126126
finalParameters map[string]string
127127
)
@@ -197,6 +197,7 @@ func NewRuntimeInstallCommand() *cobra.Command {
197197
cmd.Flags().StringVar(&installationOpts.GatewayName, "gateway-name", "", "The gateway name")
198198
cmd.Flags().StringVar(&installationOpts.GatewayNamespace, "gateway-namespace", "", "The namespace of the gateway")
199199
cmd.Flags().StringVar(&installationOpts.GitIntegrationRegistrationOpts.Token, "personal-git-token", "", "The Personal git token for your user")
200+
cmd.Flags().StringVar(&installationOpts.GitIntegrationRegistrationOpts.Username, "personal-git-user", "", "The Personal git user that match the token, required for bitbucket cloud")
200201
cmd.Flags().StringVar(&installationOpts.versionStr, "version", "", "The runtime version to install (default: latest)")
201202
cmd.Flags().StringVar(&installationOpts.SuggestedSharedConfigRepo, "shared-config-repo", "", "URL to the shared configurations repo. (default: <installation-repo> or the existing one for this account)")
202203
cmd.Flags().BoolVar(&installationOpts.InstallDemoResources, "demo-resources", true, "Installs demo resources (default: true)")
@@ -965,12 +966,13 @@ you can try to create it manually by running:
965966
return nil
966967
}
967968

968-
func registerUserToGitIntegration(ctx context.Context, appProxyClient codefresh.AppProxyAPI, runtime string, opts *apmodel.RegisterToGitIntegrationArgs) error {
969+
func registerUserToGitIntegration(ctx context.Context, appProxyClient codefresh.AppProxyAPI, runtime string, opts *GitIntegrationRegistrationOpts) error {
969970
if err := RunGitIntegrationRegisterCommand(ctx, appProxyClient, opts); err != nil {
970971
command := util.Doc(fmt.Sprintf(
971-
"\t<BIN> integration git register default --runtime %s --token %s",
972+
"\t<BIN> integration git register default --runtime %s --token %s --username %s",
972973
runtime,
973974
opts.Token,
975+
opts.Username,
974976
))
975977
return fmt.Errorf(`
976978
%w

docs/commands/cli-v2_integration_git_register.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ cli-v2 integration git register [NAME] [flags]
99
### Options
1010

1111
```
12-
-h, --help help for register
13-
--token string Authentication token
12+
-h, --help help for register
13+
--token string Authentication token
14+
--username string Authentication user name
1415
```
1516

1617
### Options inherited from parent commands

docs/commands/cli-v2_runtime_install.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ cli-v2 runtime install [runtime_name] [flags]
4747
-n, --namespace string If present, the namespace scope for this CLI request
4848
--namespace-labels stringToString Optional labels that will be set on the namespace resource. (e.g. "key1=value1,key2=value2" (default [])
4949
--personal-git-token string The Personal git token for your user
50+
--personal-git-user string The Personal git user that match the token, required for bitbucket cloud
5051
--provider string The git provider, one of: azure|bitbucket|bitbucket-server|gitea|github|gitlab
5152
--provider-api-url string Git provider API url
5253
--repo string Repository URL [GIT_REPO]

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.499/cf-linux-amd64.tar.gz | tar zx
26+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.500/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.499/cf-darwin-amd64.tar.gz | tar zx
39+
curl -L --output - https://github.com/codefresh-io/cli-v2/releases/download/v0.0.500/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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/argoproj/argo-events v0.17.1-0.20220327045437-70eaafe9afec
1111
github.com/argoproj/argo-workflows/v3 v3.3.1
1212
github.com/briandowns/spinner v1.18.1
13-
github.com/codefresh-io/go-sdk v0.47.1
13+
github.com/codefresh-io/go-sdk v0.47.2
1414
github.com/fatih/color v1.13.0
1515
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
1616
github.com/go-git/go-billy/v5 v5.3.1
@@ -257,7 +257,6 @@ require (
257257
replace (
258258
// https://github.com/golang/go/issues/33546#issuecomment-519656923
259259
github.com/go-check/check => github.com/go-check/check v0.0.0-20180628173108-788fd7840127
260-
261260
github.com/golang/protobuf => github.com/golang/protobuf v1.4.2
262261
github.com/gorilla/websocket => github.com/gorilla/websocket v1.4.2
263262
github.com/grpc-ecosystem/grpc-gateway => github.com/grpc-ecosystem/grpc-gateway v1.16.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ github.com/cockroachdb/datadriven v0.0.0-20200714090401-bf6692d28da5/go.mod h1:h
308308
github.com/cockroachdb/errors v1.2.4/go.mod h1:rQD95gz6FARkaKkQXUksEje/d9a6wBJoCr5oaCLELYA=
309309
github.com/cockroachdb/logtags v0.0.0-20190617123548-eb05cc24525f/go.mod h1:i/u985jwjWRlyHXQbwatDASoW0RMlZ/3i9yJHE2xLkI=
310310
github.com/codahale/hdrhistogram v0.0.0-20161010025455-3a0bb77429bd/go.mod h1:sE/e/2PUdi/liOCUjSTXgM1o87ZssimdTWN964YiIeI=
311-
github.com/codefresh-io/go-sdk v0.47.1 h1:u75zJuphhFvqyjpcZWGzifAeOsZ7BcSrm2WZ4yTvxFo=
312-
github.com/codefresh-io/go-sdk v0.47.1/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
311+
github.com/codefresh-io/go-sdk v0.47.2 h1:GgQHvZgmMxuTd6QivT40cZ+brkOCjiQ2KFtrRFDHGP8=
312+
github.com/codefresh-io/go-sdk v0.47.2/go.mod h1:CcoVmTFWHGkbrSW8LyOGB/vJe5Vzr3iC/pNE2QIBTyg=
313313
github.com/codegangsta/inject v0.0.0-20150114235600-33e0aa1cb7c0/go.mod h1:4Zcjuz89kmFXt9morQgcfYZAYZ5n8WHjt81YYWIwtTM=
314314
github.com/codeskyblue/go-sh v0.0.0-20190412065543-76bd3d59ff27/go.mod h1:VQx0hjo2oUeQkQUET7wRwradO6f+fN5jzXgB/zROxxE=
315315
github.com/container-storage-interface/spec v1.5.0/go.mod h1:8K96oQNkJ7pFcC2R9Z1ynGGBB1I93kcS6PGg3SsOk8s=

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.499
8+
version: 0.0.500
99
bootstrapSpecifier: github.com/codefresh-io/cli-v2/manifests/argo-cd
1010
components:
1111
- name: events

0 commit comments

Comments
 (0)