From 5acc30c9684b5899b7017d6a6ae92ff9ea7965f1 Mon Sep 17 00:00:00 2001 From: George Livas Date: Mon, 8 Jan 2024 15:29:22 +0000 Subject: [PATCH 1/5] update docs --- cmd/namespace.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cmd/namespace.go b/cmd/namespace.go index 37cf6cbab..799131ada 100644 --- a/cmd/namespace.go +++ b/cmd/namespace.go @@ -58,7 +58,7 @@ func newNamespaceCommand(config *settings.Config) *cobra.Command { } createCmd := &cobra.Command{ - Use: "create [] []", + Use: "create --org-id ", Short: "Create a namespace", Long: `Create a namespace. Please note that at this time all namespaces created in the registry are world-readable.`, @@ -86,13 +86,10 @@ Please note that at this time all namespaces created in the registry are world-r }, Args: cobra.RangeArgs(1, 3), Annotations: make(map[string]string), - Example: ` circleci namespace create NamespaceName github OrgName - circleci namespace create NamespaceName --org-id "your-org-id-here"`, + Example: ` circleci namespace create NamespaceName --org-id 00000000-0000-0000-0000-000000000000`, } createCmd.Annotations[""] = "The name to give your new namespace" - createCmd.Annotations["[]"] = `Your VCS provider, can be either "github" or "bitbucket". Optional when passing org-id flag.` - createCmd.Annotations["[]"] = `The name used for your organization. Optional when passing org-id flag.` createCmd.Flags().BoolVar(&opts.integrationTesting, "integration-testing", false, "Enable test mode to bypass interactive UI.") if err := createCmd.Flags().MarkHidden("integration-testing"); err != nil { From 169d9e38b3cb9d13c76b8f807ca0a7d5e7545e4d Mon Sep 17 00:00:00 2001 From: George Livas Date: Tue, 9 Jan 2024 15:22:11 +0000 Subject: [PATCH 2/5] remove VCS functionality --- cmd/.circleci/update_check.yml | 2 +- cmd/namespace.go | 42 +------ cmd/namespace_test.go | 209 --------------------------------- 3 files changed, 6 insertions(+), 247 deletions(-) diff --git a/cmd/.circleci/update_check.yml b/cmd/.circleci/update_check.yml index b4e5bdc0f..c2d7a0089 100644 --- a/cmd/.circleci/update_check.yml +++ b/cmd/.circleci/update_check.yml @@ -1 +1 @@ -last_update_check: 2023-12-11T13:24:04.24843+01:00 +last_update_check: 2024-01-11T10:44:52.12818Z diff --git a/cmd/namespace.go b/cmd/namespace.go index 799131ada..b8950b2ff 100644 --- a/cmd/namespace.go +++ b/cmd/namespace.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "strings" "github.com/CircleCI-Public/circleci-cli/api" "github.com/CircleCI-Public/circleci-cli/api/graphql" @@ -84,9 +83,9 @@ Please note that at this time all namespaces created in the registry are world-r return err }, - Args: cobra.RangeArgs(1, 3), + Args: cobra.RangeArgs(1, 1), Annotations: make(map[string]string), - Example: ` circleci namespace create NamespaceName --org-id 00000000-0000-0000-0000-000000000000`, + Example: ` circleci namespace create NamespaceName --org-id 00000000-0000-0000-0000-000000000000`, } createCmd.Annotations[""] = "The name to give your new namespace" @@ -138,42 +137,11 @@ To change the namespace, you will have to contact CircleCI customer support. return nil } -func createNamespaceWithVcsTypeAndOrgName(opts namespaceOptions, namespaceName, vcsType, orgName string) error { - if !opts.noPrompt { - fmt.Printf(`You are creating a namespace called "%s". - -This is the only namespace permitted for your %s organization, %s. - -To change the namespace, you will have to contact CircleCI customer support. - -`, namespaceName, strings.ToLower(opts.args[1]), opts.args[2]) - } - - confirm := fmt.Sprintf("Are you sure you wish to create the namespace: `%s`", namespaceName) - if opts.noPrompt || opts.tty.askUserToConfirm(confirm) { - _, err := api.CreateNamespace(opts.cl, namespaceName, opts.args[2], strings.ToUpper(opts.args[1])) - if err != nil { - return err - } - - fmt.Printf("Namespace `%s` created.\n", namespaceName) - fmt.Println("Please note that any orbs you publish in this namespace are open orbs and are world-readable.") - } - return nil -} - func createNamespace(cmd *cobra.Command, opts namespaceOptions) error { namespaceName := opts.args[0] - //skip if no orgid provided - if opts.orgID != nil && strings.TrimSpace(*opts.orgID) != "" { - _, err := uuid.Parse(*opts.orgID) - if err == nil { - return createNamespaceWithOrgId(opts, namespaceName, *opts.orgID) - } - - //skip if no vcs type and org name provided - } else if len(opts.args) == 3 { - return createNamespaceWithVcsTypeAndOrgName(opts, namespaceName, opts.args[1], opts.args[2]) + _, err := uuid.Parse(*opts.orgID) + if err == nil { + return createNamespaceWithOrgId(opts, namespaceName, *opts.orgID) } return cmd.Help() } diff --git a/cmd/namespace_test.go b/cmd/namespace_test.go index 216817c96..bf45842e8 100644 --- a/cmd/namespace_test.go +++ b/cmd/namespace_test.go @@ -9,7 +9,6 @@ import ( "github.com/CircleCI-Public/circleci-cli/telemetry" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" - "github.com/onsi/gomega/gbytes" "github.com/onsi/gomega/gexec" ) @@ -119,213 +118,5 @@ Namespace %s created. Please note that any orbs you publish in this namespace are open orbs and are world-readable.`, "foo-ns", "bb604b45-b6b0-4b81-ad80-796f15eddf87", "`foo-ns`", "`foo-ns`"))) }) }) - - Describe("registering a namespace with OrgName and OrgVcs", func() { - BeforeEach(func() { - command = exec.Command(pathCLI, - "namespace", "create", - "--skip-update-check", - "--token", token, - "--host", tempSettings.TestServer.URL(), - "--integration-testing", - "foo-ns", - "BITBUCKET", - "test-org", - ) - }) - - It("works with organizationName and organizationVcs", func() { - By("setting up a mock server") - - gqlOrganizationResponse := `{ - "organization": { - "name": "test-org", - "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" - } - }` - - expectedOrganizationRequest := `{ - "query": "query($organizationName: String!, $organizationVcs: VCSType!) {\n\t\t\t\torganization(\n\t\t\t\t\tname: $organizationName\n\t\t\t\t\tvcsType: $organizationVcs\n\t\t\t\t) {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}","variables":{"organizationName":"test-org","organizationVcs":"BITBUCKET"}}` - - gqlNsResponse := `{ - "createNamespace": { - "errors": [], - "namespace": { - "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" - } - } - }` - - expectedNsRequest := `{ - "query": "\n\t\t\tmutation($name: String!, $organizationId: UUID!) {\n\t\t\t\tcreateNamespace(\n\t\t\t\t\tname: $name,\n\t\t\t\t\torganizationId: $organizationId\n\t\t\t\t) {\n\t\t\t\t\tnamespace {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t\terrors {\n\t\t\t\t\t\tmessage\n\t\t\t\t\t\ttype\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}", - "variables": { - "name": "foo-ns", - "organizationId": "bb604b45-b6b0-4b81-ad80-796f15eddf87" - } - }` - - tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ - Status: http.StatusOK, - Request: expectedOrganizationRequest, - Response: gqlOrganizationResponse}) - tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ - Status: http.StatusOK, - Request: expectedNsRequest, - Response: gqlNsResponse}) - - By("running the command") - session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) - Expect(err).ShouldNot(HaveOccurred()) - Eventually(session).Should(gexec.Exit(0)) - - stdout := session.Wait().Out.Contents() - - Expect(string(stdout)).To(ContainSubstring(fmt.Sprintf(`You are creating a namespace called "%s". - -This is the only namespace permitted for your bitbucket organization, test-org. - -To change the namespace, you will have to contact CircleCI customer support. - -Are you sure you wish to create the namespace: %s -Namespace %s created. -Please note that any orbs you publish in this namespace are open orbs and are world-readable.`, "foo-ns", "`foo-ns`", "`foo-ns`"))) - }) - }) - - Describe("when creating / reserving a namespace", func() { - BeforeEach(func() { - command = exec.Command(pathCLI, - "namespace", "create", - "--skip-update-check", - "--token", token, - "--host", tempSettings.TestServer.URL(), - "--integration-testing", - "foo-ns", - "BITBUCKET", - "test-org", - ) - }) - - It("works with organizationName and organizationVcs", func() { - By("setting up a mock server") - - gqlOrganizationResponse := `{ - "organization": { - "name": "test-org", - "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" - } - }` - - expectedOrganizationRequest := `{ - "query": "query($organizationName: String!, $organizationVcs: VCSType!) {\n\t\t\t\torganization(\n\t\t\t\t\tname: $organizationName\n\t\t\t\t\tvcsType: $organizationVcs\n\t\t\t\t) {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}", - "variables": { - "organizationName": "test-org", - "organizationVcs": "BITBUCKET" - } - }` - - gqlNsResponse := `{ - "createNamespace": { - "errors": [], - "namespace": { - "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" - } - } - }` - - expectedNsRequest := `{ - "query": "\n\t\t\tmutation($name: String!, $organizationId: UUID!) {\n\t\t\t\tcreateNamespace(\n\t\t\t\t\tname: $name,\n\t\t\t\t\torganizationId: $organizationId\n\t\t\t\t) {\n\t\t\t\t\tnamespace {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t\terrors {\n\t\t\t\t\t\tmessage\n\t\t\t\t\t\ttype\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}", - "variables": { - "name": "foo-ns", - "organizationId": "bb604b45-b6b0-4b81-ad80-796f15eddf87" - } - }` - - tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ - Status: http.StatusOK, - Request: expectedOrganizationRequest, - Response: gqlOrganizationResponse}) - tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ - Status: http.StatusOK, - Request: expectedNsRequest, - Response: gqlNsResponse}) - - By("running the command") - session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) - Expect(err).ShouldNot(HaveOccurred()) - Eventually(session).Should(gexec.Exit(0)) - - stdout := session.Wait().Out.Contents() - - Expect(string(stdout)).To(ContainSubstring(fmt.Sprintf(`You are creating a namespace called "%s". - -This is the only namespace permitted for your bitbucket organization, test-org. - -To change the namespace, you will have to contact CircleCI customer support. - -Are you sure you wish to create the namespace: %s -Namespace %s created. -Please note that any orbs you publish in this namespace are open orbs and are world-readable.`, "foo-ns", "`foo-ns`", "`foo-ns`"))) - }) - - It("prints all in-band errors returned by the GraphQL API", func() { - By("setting up a mock server") - - gqlOrganizationResponse := `{ - "organization": { - "name": "test-org", - "id": "bb604b45-b6b0-4b81-ad80-796f15eddf87" - } - }` - - expectedOrganizationRequest := `{ - "query": "query($organizationName: String!, $organizationVcs: VCSType!) {\n\t\t\t\torganization(\n\t\t\t\t\tname: $organizationName\n\t\t\t\t\tvcsType: $organizationVcs\n\t\t\t\t) {\n\t\t\t\t\tid\n\t\t\t\t}\n\t\t\t}", - "variables": { - "organizationName": "test-org", - "organizationVcs": "BITBUCKET" - } - }` - - gqlResponse := `{ - "createNamespace": { - "errors": [ - {"message": "error1"}, - {"message": "error2"} - ], - "namespace": null - } - }` - - gqlNativeErrors := `[ { "message": "ignored error" } ]` - - expectedRequestJSON := `{ - "query": "\n\t\t\tmutation($name: String!, $organizationId: UUID!) {\n\t\t\t\tcreateNamespace(\n\t\t\t\t\tname: $name,\n\t\t\t\t\torganizationId: $organizationId\n\t\t\t\t) {\n\t\t\t\t\tnamespace {\n\t\t\t\t\t\tid\n\t\t\t\t\t}\n\t\t\t\t\terrors {\n\t\t\t\t\t\tmessage\n\t\t\t\t\t\ttype\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}", - "variables": { - "name": "foo-ns", - "organizationId": "bb604b45-b6b0-4b81-ad80-796f15eddf87" - } - }` - - tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ - Status: http.StatusOK, - Request: expectedOrganizationRequest, - Response: gqlOrganizationResponse, - }) - tempSettings.AppendPostHandler(token, clitest.MockRequestResponse{ - Status: http.StatusOK, - Request: expectedRequestJSON, - Response: gqlResponse, - ErrorResponse: gqlNativeErrors, - }) - - By("running the command") - session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) - - Expect(err).ShouldNot(HaveOccurred()) - Eventually(session.Err).Should(gbytes.Say(`Error: error1 -error2`)) - Eventually(session).ShouldNot(gexec.Exit(0)) - }) - }) }) }) From 1a1e3b16674b64f7a1d309198195a3b6b3f03a2f Mon Sep 17 00:00:00 2001 From: JulesFaucherre Date: Thu, 11 Jan 2024 12:07:46 +0100 Subject: [PATCH 3/5] ci: trigger CI From 0d659babd880896a1a203198117d2a2f64ea28f8 Mon Sep 17 00:00:00 2001 From: George Livas Date: Thu, 11 Jan 2024 15:05:09 +0000 Subject: [PATCH 4/5] use ExactArgs --- cmd/namespace.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/namespace.go b/cmd/namespace.go index b8950b2ff..d6cf8945a 100644 --- a/cmd/namespace.go +++ b/cmd/namespace.go @@ -83,7 +83,7 @@ Please note that at this time all namespaces created in the registry are world-r return err }, - Args: cobra.RangeArgs(1, 1), + Args: cobra.ExactArgs(1), Annotations: make(map[string]string), Example: ` circleci namespace create NamespaceName --org-id 00000000-0000-0000-0000-000000000000`, } From c96b18cff93a2874afa834136be9f00fe8c3e94b Mon Sep 17 00:00:00 2001 From: George Livas Date: Mon, 15 Jan 2024 12:37:42 +0000 Subject: [PATCH 5/5] upgrade go-git --- go.mod | 2 +- go.sum | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index d78740d26..e09e3719b 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/blang/semver v3.5.1+incompatible github.com/briandowns/spinner v1.23.0 github.com/fatih/color v1.16.0 - github.com/go-git/go-git/v5 v5.10.1 + github.com/go-git/go-git/v5 v5.11.0 github.com/google/go-querystring v1.1.0 // indirect github.com/google/uuid v1.4.0 github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf // indirect diff --git a/go.sum b/go.sum index 02ce9c2a4..4acc1e585 100644 --- a/go.sum +++ b/go.sum @@ -105,6 +105,8 @@ github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMj github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= github.com/go-git/go-git/v5 v5.10.1 h1:tu8/D8i+TWxgKpzQ3Vc43e+kkhXqtsZCKI/egajKnxk= github.com/go-git/go-git/v5 v5.10.1/go.mod h1:uEuHjxkHap8kAl//V5F/nNWwqIYtP/402ddd05mp0wg= +github.com/go-git/go-git/v5 v5.11.0 h1:XIZc1p+8YzypNr34itUfSvYJcv+eYdTnTvOZ2vD3cA4= +github.com/go-git/go-git/v5 v5.11.0/go.mod h1:6GFcX2P3NM7FPBfpePbpLd21XxsgdAt+lKqXmCUiUCY= github.com/go-ini/ini v1.67.0 h1:z6ZrTEZqSWOTyH2FlglNbNgARyHG8oLW9gMELqKr06A= github.com/go-ini/ini v1.67.0/go.mod h1:ByCAeIL28uOIIG0E3PJtZPDL8WnHpFKFOtgjp+3Ies8= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=