From e7f5036747470773e71f5a6f0109ff830280a72b Mon Sep 17 00:00:00 2001 From: Ai Mi Bui Date: Wed, 5 Oct 2022 12:31:54 -0700 Subject: [PATCH 1/4] updated listNamespaceOrbs to include details flag --- api/api.go | 15 +++++++++++---- cmd/orb.go | 2 +- cmd/orb_import.go | 2 +- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/api/api.go b/api/api.go index 674ae112c..ce10fff5a 100644 --- a/api/api.go +++ b/api/api.go @@ -1673,7 +1673,7 @@ query namespaceOrbs ($namespace: String, $after: String!) { // ListNamespaceOrbs queries the API to find all orbs belonging to the given // namespace. // Returns a collection of Orb objects containing their relevant data. -func ListNamespaceOrbs(cl *graphql.Client, namespace string, isPrivate bool) (*OrbsForListing, error) { +func ListNamespaceOrbs(cl *graphql.Client, namespace string, isPrivate, showDetails bool) (*OrbsForListing, error) { l := log.New(os.Stderr, "", 0) query := ` @@ -1685,9 +1685,15 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType edges { cursor node { - versions { - source - version + versions ` + + if showDetails { + query+=`(count: 1){ source,` + } else { + query+=`{` + } + + query+=` version } name statistics { @@ -1705,6 +1711,7 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType } } ` + var orbs OrbsForListing var result NamespaceOrbResponse currentCursor := "" diff --git a/cmd/orb.go b/cmd/orb.go index 2650a720e..435504563 100644 --- a/cmd/orb.go +++ b/cmd/orb.go @@ -636,7 +636,7 @@ func listOrbs(opts orbOptions) error { func listNamespaceOrbs(opts orbOptions) error { namespace := opts.args[0] - orbs, err := api.ListNamespaceOrbs(opts.cl, namespace, opts.private) + orbs, err := api.ListNamespaceOrbs(opts.cl, namespace, opts.private, opts.listDetails) if err != nil { return errors.Wrapf(err, "Failed to list orbs in namespace `%s`", namespace) } diff --git a/cmd/orb_import.go b/cmd/orb_import.go index 5ddb18168..fca5512b9 100644 --- a/cmd/orb_import.go +++ b/cmd/orb_import.go @@ -216,7 +216,7 @@ func deleteNamespace(nsOpts namespaceOptions) error { // Currently, private orbs will not be included in the list of orbs to be deleted. // This can be changed once we have 'listBothPublicAndPrivateOrbs' functionality. - orbs, err := api.ListNamespaceOrbs(nsOpts.cl, namespaceArg, false) + orbs, err := api.ListNamespaceOrbs(nsOpts.cl, namespaceArg, false, false) if err != nil { return fmt.Errorf("unable to list orbs: %s", err.Error()) } From e46985649b21e1c3abe3f93676b5182b629a8334 Mon Sep 17 00:00:00 2001 From: Ai Mi Bui Date: Fri, 7 Oct 2022 11:50:12 -0700 Subject: [PATCH 2/4] fixed tests --- cmd/admin_test.go | 6 +++--- cmd/orb_test.go | 17 +++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/cmd/admin_test.go b/cmd/admin_test.go index ae8764f06..21baab91e 100644 --- a/cmd/admin_test.go +++ b/cmd/admin_test.go @@ -181,7 +181,7 @@ var _ = Describe("Namespace integration tests", func() { }` expectedListOrbsRequest := `{ - "query": "\nquery namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType) {\n\tregistryNamespace(name: $namespace) {\n\t\tname\n id\n\t\torbs(first: 20, after: $after, view: $view) {\n\t\t\tedges {\n\t\t\t\tcursor\n\t\t\t\tnode {\n\t\t\t\t\tversions {\n\t\t\t\t\t\tsource\n\t\t\t\t\t\tversion\n\t\t\t\t\t}\n\t\t\t\t\tname\n\t statistics {\n\t\t last30DaysBuildCount,\n\t\t last30DaysProjectCount,\n\t\t last30DaysOrganizationCount\n\t }\n\t\t\t\t}\n\t\t\t}\n\t\t\ttotalCount\n\t\t\tpageInfo {\n\t\t\t\thasNextPage\n\t\t\t}\n\t\t}\n\t}\n}\n", + "query": "\nquery namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType) {\n\tregistryNamespace(name: $namespace) {\n\t\tname\n id\n\t\torbs(first: 20, after: $after, view: $view) {\n\t\t\tedges {\n\t\t\t\tcursor\n\t\t\t\tnode {\n\t\t\t\t\tversions { version\n\t\t\t\t\t}\n\t\t\t\t\tname\n\t statistics {\n\t\t last30DaysBuildCount,\n\t\t last30DaysProjectCount,\n\t\t last30DaysOrganizationCount\n\t }\n\t\t\t\t}\n\t\t\t}\n\t\t\ttotalCount\n\t\t\tpageInfo {\n\t\t\t\thasNextPage\n\t\t\t}\n\t\t}\n\t}\n}\n", "variables": { "after": "", "namespace": "foo-ns", @@ -236,7 +236,7 @@ var _ = Describe("Namespace integration tests", func() { }` expectedListOrbsRequest := `{ - "query": "\nquery namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType) {\n\tregistryNamespace(name: $namespace) {\n\t\tname\n id\n\t\torbs(first: 20, after: $after, view: $view) {\n\t\t\tedges {\n\t\t\t\tcursor\n\t\t\t\tnode {\n\t\t\t\t\tversions {\n\t\t\t\t\t\tsource\n\t\t\t\t\t\tversion\n\t\t\t\t\t}\n\t\t\t\t\tname\n\t statistics {\n\t\t last30DaysBuildCount,\n\t\t last30DaysProjectCount,\n\t\t last30DaysOrganizationCount\n\t }\n\t\t\t\t}\n\t\t\t}\n\t\t\ttotalCount\n\t\t\tpageInfo {\n\t\t\t\thasNextPage\n\t\t\t}\n\t\t}\n\t}\n}\n", + "query": "\nquery namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType) {\n\tregistryNamespace(name: $namespace) {\n\t\tname\n id\n\t\torbs(first: 20, after: $after, view: $view) {\n\t\t\tedges {\n\t\t\t\tcursor\n\t\t\t\tnode {\n\t\t\t\t\tversions { version\n\t\t\t\t\t}\n\t\t\t\t\tname\n\t statistics {\n\t\t last30DaysBuildCount,\n\t\t last30DaysProjectCount,\n\t\t last30DaysOrganizationCount\n\t }\n\t\t\t\t}\n\t\t\t}\n\t\t\ttotalCount\n\t\t\tpageInfo {\n\t\t\t\thasNextPage\n\t\t\t}\n\t\t}\n\t}\n}\n", "variables": { "after": "", "namespace": "foo-ns", @@ -310,7 +310,7 @@ var _ = Describe("Namespace integration tests", func() { }` expectedListOrbsRequest := `{ - "query": "\nquery namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType) {\n\tregistryNamespace(name: $namespace) {\n\t\tname\n id\n\t\torbs(first: 20, after: $after, view: $view) {\n\t\t\tedges {\n\t\t\t\tcursor\n\t\t\t\tnode {\n\t\t\t\t\tversions {\n\t\t\t\t\t\tsource\n\t\t\t\t\t\tversion\n\t\t\t\t\t}\n\t\t\t\t\tname\n\t statistics {\n\t\t last30DaysBuildCount,\n\t\t last30DaysProjectCount,\n\t\t last30DaysOrganizationCount\n\t }\n\t\t\t\t}\n\t\t\t}\n\t\t\ttotalCount\n\t\t\tpageInfo {\n\t\t\t\thasNextPage\n\t\t\t}\n\t\t}\n\t}\n}\n", + "query": "\nquery namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType) {\n\tregistryNamespace(name: $namespace) {\n\t\tname\n id\n\t\torbs(first: 20, after: $after, view: $view) {\n\t\t\tedges {\n\t\t\t\tcursor\n\t\t\t\tnode {\n\t\t\t\t\tversions { version\n\t\t\t\t\t}\n\t\t\t\t\tname\n\t statistics {\n\t\t last30DaysBuildCount,\n\t\t last30DaysProjectCount,\n\t\t last30DaysOrganizationCount\n\t }\n\t\t\t\t}\n\t\t\t}\n\t\t\ttotalCount\n\t\t\tpageInfo {\n\t\t\t\thasNextPage\n\t\t\t}\n\t\t}\n\t}\n}\n", "variables": { "after": "", "namespace": "foo-ns", diff --git a/cmd/orb_test.go b/cmd/orb_test.go index f10100bb7..16290b896 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -2288,6 +2288,7 @@ Search, filter, and view sources for all Orbs online at https://circleci.com/dev tmpBytes := golden.Get(GinkgoT(), filepath.FromSlash("gql_orb_list_details/pretty_json_output.json")) expectedOutput := string(tmpBytes) completeOutput := string(session.Wait().Out.Contents()) + Expect(completeOutput).Should(MatchJSON(expectedOutput)) Expect(tempSettings.TestServer.ReceivedRequests()).Should(HaveLen(1)) }) @@ -2313,9 +2314,7 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType edges { cursor node { - versions { - source - version + versions (count: 1){ source, version } name statistics { @@ -2390,6 +2389,7 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType "orb", "list", "circleci", "--skip-update-check", "--host", tempSettings.TestServer.URL(), + "--details", "--json", ) }) @@ -2406,7 +2406,7 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType Expect(completeOutput).Should(MatchJSON(expectedOutput)) Eventually(session).Should(gexec.Exit(0)) Expect(tempSettings.TestServer.ReceivedRequests()).Should(HaveLen(2)) - }) + }) }) }) @@ -2429,9 +2429,7 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType edges { cursor node { - versions { - source - version + versions { version } name statistics { @@ -2467,6 +2465,7 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType }) }) + It("returns an error", func() { By("running the command") session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter) @@ -2491,9 +2490,7 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType edges { cursor node { - versions { - source - version + versions { version } name statistics { From ff36709c7a7be0b797fd39c547385dfe7884aa56 Mon Sep 17 00:00:00 2001 From: corinnesollows Date: Fri, 7 Oct 2022 15:57:41 -0300 Subject: [PATCH 3/4] linted --- api/api.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/api/api.go b/api/api.go index ce10fff5a..a88272e85 100644 --- a/api/api.go +++ b/api/api.go @@ -1686,14 +1686,14 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType cursor node { versions ` - - if showDetails { - query+=`(count: 1){ source,` - } else { - query+=`{` - } - query+=` version + if showDetails { + query += `(count: 1){ source,` + } else { + query += `{` + } + + query += ` version } name statistics { From 5b2349529e87dfd39bf5b99f3533ecc36f8ca594 Mon Sep 17 00:00:00 2001 From: corinnesollows Date: Fri, 7 Oct 2022 16:07:19 -0300 Subject: [PATCH 4/4] lint again --- cmd/orb_test.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cmd/orb_test.go b/cmd/orb_test.go index 16290b896..ed2ae913f 100644 --- a/cmd/orb_test.go +++ b/cmd/orb_test.go @@ -2406,7 +2406,7 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType Expect(completeOutput).Should(MatchJSON(expectedOutput)) Eventually(session).Should(gexec.Exit(0)) Expect(tempSettings.TestServer.ReceivedRequests()).Should(HaveLen(2)) - }) + }) }) }) @@ -2465,7 +2465,6 @@ query namespaceOrbs ($namespace: String, $after: String!, $view: OrbListViewType }) }) - It("returns an error", func() { By("running the command") session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)