From 2af27e8d748be9bd02370e39bb757c88ebc02186 Mon Sep 17 00:00:00 2001 From: Kira Muhlbauer Date: Mon, 22 Jul 2024 17:36:17 -0600 Subject: [PATCH 1/8] don't link to orb registry when host is not cloud --- cmd/orb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/orb.go b/cmd/orb.go index 332b451f..2d8db7f4 100644 --- a/cmd/orb.go +++ b/cmd/orb.go @@ -621,7 +621,7 @@ func formatListOrbsResult(list api.OrbsForListing, opts orbOptions) (string, err } } - if !opts.private { + if !opts.private && opts.cfg.Host == defaultHost { b.WriteString("\nIn order to see more details about each orb, type: `circleci orb info orb-namespace/orb-name`\n") b.WriteString("\nSearch, filter, and view sources for all Orbs online at https://circleci.com/developer/orbs/") } From 7787c34460215120f755f31df23c2dbfc0f08786 Mon Sep 17 00:00:00 2001 From: Kira Muhlbauer Date: Mon, 22 Jul 2024 17:44:04 -0600 Subject: [PATCH 2/8] test --- cmd/orb_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/orb_test.go b/cmd/orb_test.go index df41dd4d..e37d5021 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -2513,7 +2513,7 @@ query ListOrbs ($after: String!, $certifiedOnly: Boolean!) { command = exec.Command(pathCLI, "orb", "list", "--skip-update-check", - "--host", tempSettings.TestServer.URL(), + "--host", "https://circleci.com", "--details", ) By("setting up a mock server") From 4a88de3e193e32987c3b9a39c5b74ad6fa4d3336 Mon Sep 17 00:00:00 2001 From: Kira Muhlbauer Date: Mon, 22 Jul 2024 17:46:45 -0600 Subject: [PATCH 3/8] test --- cmd/orb_test.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cmd/orb_test.go b/cmd/orb_test.go index e37d5021..79d42ba6 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -2513,7 +2513,7 @@ query ListOrbs ($after: String!, $certifiedOnly: Boolean!) { command = exec.Command(pathCLI, "orb", "list", "--skip-update-check", - "--host", "https://circleci.com", + "--host", tempSettings.TestServer.URL(), "--details", ) By("setting up a mock server") @@ -2584,9 +2584,6 @@ foo/test (0.7.0) - last30DaysOrganizationCount: 0 - last30DaysProjectCount: 0 -In order to see more details about each orb, type: ` + "`circleci orb info orb-namespace/orb-name`" + ` - -Search, filter, and view sources for all Orbs online at https://circleci.com/developer/orbs/ `)) Eventually(session).Should(gexec.Exit(0)) Expect(tempSettings.TestServer.ReceivedRequests()).Should(HaveLen(1)) From 0131f932cfd8ff668228009e00ed1362ec87da6d Mon Sep 17 00:00:00 2001 From: Kira Muhlbauer Date: Mon, 22 Jul 2024 18:57:03 -0600 Subject: [PATCH 4/8] remove docs link from tests --- cmd/orb_test.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/cmd/orb_test.go b/cmd/orb_test.go index 79d42ba6..78045125 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -2229,9 +2229,6 @@ second (0.8.0) third (0.9.0) first (0.7.0) -In order to see more details about each orb, type: ` + "`circleci orb info orb-namespace/orb-name`" + ` - -Search, filter, and view sources for all Orbs online at https://circleci.com/developer/orbs/ `)) }) @@ -2256,9 +2253,6 @@ third (0.9.0) first (0.7.0) second (0.8.0) -In order to see more details about each orb, type: ` + "`circleci orb info orb-namespace/orb-name`" + ` - -Search, filter, and view sources for all Orbs online at https://circleci.com/developer/orbs/ `)) }) @@ -2283,9 +2277,6 @@ second (0.8.0) first (0.7.0) third (0.9.0) -In order to see more details about each orb, type: ` + "`circleci orb info orb-namespace/orb-name`" + ` - -Search, filter, and view sources for all Orbs online at https://circleci.com/developer/orbs/ `)) }) }) @@ -2475,9 +2466,6 @@ query ListOrbs ($after: String!, $certifiedOnly: Boolean!) { Eventually(session.Out).Should(gbytes.Say("circleci/codecov-clojure \\(0.0.4\\)")) // Include an orb with contents from the second mocked response Eventually(session.Out).Should(gbytes.Say("zzak/test4 \\(0.1.0\\)")) - - Eventually(session.Out).Should(gbytes.Say("In order to see more details about each orb, type: `circleci orb info orb-namespace/orb-name`")) - Eventually(session.Out).Should(gbytes.Say("Search, filter, and view sources for all Orbs online at https://circleci.com/developer/orbs/")) Expect(tempSettings.TestServer.ReceivedRequests()).Should(HaveLen(2)) }) From c891c5da130156761603bae613e14c62b91dad38 Mon Sep 17 00:00:00 2001 From: Kira Muhlbauer Date: Mon, 22 Jul 2024 19:22:39 -0600 Subject: [PATCH 5/8] add a new test --- cmd/orb_test.go | 78 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 77 insertions(+), 1 deletion(-) diff --git a/cmd/orb_test.go b/cmd/orb_test.go index 78045125..fec3eebf 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -2387,7 +2387,83 @@ query ListOrbs ($after: String!, $certifiedOnly: Boolean!) { }) }) - Describe("when listing all orbs with --uncertified", func() { + Describe("when listing all orbs default host", func() { + BeforeEach(func() { + command = exec.Command(pathCLI, + "orb", "list", + "--skip-update-check", + ) + By("setting up a mock server") + + query := ` +query ListOrbs ($after: String!, $certifiedOnly: Boolean!) { + orbs(first: 20, after: $after, certifiedOnly: $certifiedOnly) { + totalCount, + edges { + cursor + node { + name + statistics { + last30DaysBuildCount, + last30DaysProjectCount, + last30DaysOrganizationCount + } + versions(count: 1) { + version, + source + } + } + } + pageInfo { + hasNextPage + } + } +} +` + + firstRequest := graphql.NewRequest(query) + firstRequest.Variables["after"] = "" + firstRequest.Variables["certifiedOnly"] = false + + firstRequestEncoded, err := firstRequest.Encode() + Expect(err).ShouldNot(HaveOccurred()) + + secondRequest := graphql.NewRequest(query) + secondRequest.Variables["after"] = "test/here-we-go" + secondRequest.Variables["certifiedOnly"] = false + + secondRequestEncoded, err := secondRequest.Encode() + Expect(err).ShouldNot(HaveOccurred()) + + tmpBytes := golden.Get(GinkgoT(), filepath.FromSlash("gql_orb_list_uncertified/first_response.json")) + firstResponse := string(tmpBytes) + + tmpBytes = golden.Get(GinkgoT(), filepath.FromSlash("gql_orb_list_uncertified/second_response.json")) + secondResponse := string(tmpBytes) + + tempSettings.AppendPostHandler("", clitest.MockRequestResponse{ + Status: http.StatusOK, + Request: firstRequestEncoded.String(), + Response: firstResponse, + }) + tempSettings.AppendPostHandler("", clitest.MockRequestResponse{ + Status: http.StatusOK, + Request: secondRequestEncoded.String(), + Response: secondResponse, + }) + }) + + It("includes a link to the docs'", func() { + By("running the command") + session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) + + Expect(err).ShouldNot(HaveOccurred()) + Eventually(session.Out).Should(gbytes.Say("In order to see more details about each orb, type: `circleci orb info orb-namespace/orb-name`")) + Eventually(session.Out).Should(gbytes.Say("Search, filter, and view sources for all Orbs online at https://circleci.com/developer/orbs/")) + }) + }) + + Describe("when listing all orbs with --uncertified and custom host", func() { BeforeEach(func() { command = exec.Command(pathCLI, "orb", "list", From 2c426d60974ec4b049f28055d3c26af0f581c7bc Mon Sep 17 00:00:00 2001 From: Chris Stephen Date: Thu, 15 Aug 2024 08:43:17 -0300 Subject: [PATCH 6/8] Use the runner v3 API --- cmd/runner/runner.go | 9 +++++++-- cmd/runner/runner_test.go | 31 +++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 cmd/runner/runner_test.go diff --git a/cmd/runner/runner.go b/cmd/runner/runner.go index 72424c1b..e620b53b 100644 --- a/cmd/runner/runner.go +++ b/cmd/runner/runner.go @@ -15,7 +15,12 @@ type runnerOpts struct { r running } -func NewCommand(config *settings.Config, preRunE validator.Validator) *cobra.Command { +func NewCommand(rootConfig *settings.Config, preRunE validator.Validator) *cobra.Command { + // The runner API versioning is decoupled from the other Circle APIs. Here we make a copy of the root configuration, + // and update the rest endpoint accordingly + config := *rootConfig + config.RestEndpoint = "/api/v3" + var opts runnerOpts cmd := &cobra.Command{ Use: "runner", @@ -27,7 +32,7 @@ func NewCommand(config *settings.Config, preRunE validator.Validator) *cobra.Com } else { host = config.Host } - opts.r = runner.New(rest.NewFromConfig(host, config)) + opts.r = runner.New(rest.NewFromConfig(host, &config)) }, } diff --git a/cmd/runner/runner_test.go b/cmd/runner/runner_test.go new file mode 100644 index 00000000..cfef5128 --- /dev/null +++ b/cmd/runner/runner_test.go @@ -0,0 +1,31 @@ +package runner + +import ( + "net/http" + "net/http/httptest" + "testing" + + "gotest.tools/v3/assert" + "gotest.tools/v3/assert/cmp" + + "github.com/CircleCI-Public/circleci-cli/settings" +) + +func Test_NewCommand(t *testing.T) { + t.Run("Runner uses /api/v3", func(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + assert.Check(t, cmp.Equal(r.URL.EscapedPath(), "/api/v3/runner")) + + w.Header().Set("Content-Type", "application/json") + _, err := w.Write([]byte(`{"items":[]}`)) + assert.NilError(t, err) + w.WriteHeader(http.StatusOK) + })) + t.Cleanup(server.Close) + + cmd := NewCommand(&settings.Config{Host: server.URL, HTTPClient: &http.Client{}}, nil) + cmd.SetArgs([]string{"instance", "ls", "my-namespace"}) + err := cmd.Execute() + assert.NilError(t, err) + }) +} From ef80007f9be28ae399bc37db52387f4d3129433f Mon Sep 17 00:00:00 2001 From: Brandon Niu Date: Tue, 20 Aug 2024 11:12:38 -0400 Subject: [PATCH 7/8] Update CODEOWNERS --- .github/CODEOWNERS | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index facff8db..ea4f571d 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -1,5 +1,5 @@ -* @CircleCI-Public/developer-experience -*orb*.go @CircleCI-Public/orb-publishers @CircleCI-Public/developer-experience +* @CircleCI-Public/lifecycle +*orb*.go @CircleCI-Public/orb-publishers @CircleCI-Public/lifecycle /api/runner @CircleCI-Public/on-prem /cmd/runner @CircleCI-Public/on-prem From d0a1e4ff86ececb14243938f9adf589ba77b96a4 Mon Sep 17 00:00:00 2001 From: Liam Clarke Date: Thu, 22 Aug 2024 09:34:05 +0100 Subject: [PATCH 8/8] PIPE-4877 Remove config validate test with invalid org ID There has been a change to how configs are compiled that makes this test invalid. Previously we would allow any random owner ID to be passed in when compiling certified orbs as these were enabled by default and didn't require any checks with the provided owner ID. To support an upcoming feature, now when compiling the config, all provided owner IDs are checked and must exist to validate that the organization allows that type of orb. The CLI can continue to use no owner ID with public certified orbs as tested in the above case. https://github.com/CircleCI-Public/circleci-cli/blob/2766f0e710c8727e346e247f6c779079a79b010c/integration_tests/features/circleci_config.feature#L63-L85 --- .../features/circleci_config.feature | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/integration_tests/features/circleci_config.feature b/integration_tests/features/circleci_config.feature index 9628d3bf..17354219 100644 --- a/integration_tests/features/circleci_config.feature +++ b/integration_tests/features/circleci_config.feature @@ -84,30 +84,6 @@ Feature: Config checking Then the exit status should be 0 And the output should contain "Config file at config.yml is valid" - Scenario: Checking a valid config file with a private org - Given a file named "config.yml" with: - """ - version: 2.1 - - orbs: - node: circleci/node@5.0.3 - - jobs: - datadog-hello-world: - docker: - - image: cimg/base:stable - steps: - - run: | - echo "doing something really cool" - workflows: - datadog-hello-world: - jobs: - - datadog-hello-world - """ - When I run `circleci config validate --skip-update-check --org-id bb604b45-b6b0-4b81-ad80-796f15eddf87 -c config.yml` - Then the output should contain "Config file at config.yml is valid" - And the exit status should be 0 - Scenario: Checking a valid config file with a non-existant orb Given a file named "config.yml" with: """