From c953a7190262b7347f158b572048e28e7096148d Mon Sep 17 00:00:00 2001 From: Gustavo Araujo Date: Thu, 31 Mar 2022 20:20:16 -0300 Subject: [PATCH 1/4] Introduce `group_descendants` fixture --- spec/fixtures/group_descendants.json | 1 + 1 file changed, 1 insertion(+) create mode 100644 spec/fixtures/group_descendants.json diff --git a/spec/fixtures/group_descendants.json b/spec/fixtures/group_descendants.json new file mode 100644 index 000000000..d3a06745c --- /dev/null +++ b/spec/fixtures/group_descendants.json @@ -0,0 +1 @@ +[{"id": 1,"name":"Foobar Group","path":"foo-bar","description":"An interesting group","visibility":"public","lfs_enabled":true,"avatar_url":"http://gitlab.example.com/uploads/group/avatar/1/foo.jpg","web_url":"http://gitlab.example.com/groups/foo-bar","request_access_enabled":false,"full_name":"Foobar Group","full_path":"foo-bar","parent_id":3},{"id":2,"name": "Foobar Group 2","path":"foo-bar-2","description":"Another interesting group","visibility":"public","lfs_enabled":true,"avatar_url":"http://gitlab.example.com/uploads/group/avatar/2/foo.jpg","web_url":"http://gitlab.example.com/groups/foo-bar-2","request_access_enabled":false,"full_name":"Foobar Group 2","full_path":"foo-bar-2","parent_id":1}] From f72f3ef7798db653c6ebfbbb33b76b3f4fb949d3 Mon Sep 17 00:00:00 2001 From: Gustavo Araujo Date: Thu, 31 Mar 2022 20:21:02 -0300 Subject: [PATCH 2/4] Introduce tests for `group_descendants` endpoint --- spec/gitlab/client/groups_spec.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/spec/gitlab/client/groups_spec.rb b/spec/gitlab/client/groups_spec.rb index c235d184e..c3435b18d 100644 --- a/spec/gitlab/client/groups_spec.rb +++ b/spec/gitlab/client/groups_spec.rb @@ -126,6 +126,23 @@ end end + describe '.group_descendants' do + before do + stub_get('/groups/3/descendant_groups', 'group_descendants') + @descendants = Gitlab.group_descendants(3) + end + + it 'gets the correct resource' do + expect(a_get('/groups/3/descendant_groups')).to have_been_made + end + + it "returns information about a group's descendants" do + expect(@descendants).to be_a Gitlab::PaginatedResponse + expect(@descendants.size).to eq(2) + expect(@descendants[1].name).to eq('Foobar Group 2') + end + end + describe '.group_billable_members' do before do stub_get('/groups/3/billable_members', 'group_billable_members') From aff628bf926784c7025498d0c7659c765dbcb860 Mon Sep 17 00:00:00 2001 From: Gustavo Araujo Date: Thu, 31 Mar 2022 20:23:39 -0300 Subject: [PATCH 3/4] Introduce `group_descendants` endpoint --- lib/gitlab/client/groups.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index 63afb1a9c..2910bef34 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -71,6 +71,20 @@ def group_members(id, options = {}) get("/groups/#{url_encode id}/members", query: options) end + # Get a list of descendant groups of a group. + # + # @example + # Gitlab.group_descendants(42) + # + # @param [Integer] id The ID of a group. + # @param [Hash] options A customizable set of options. + # @option options [Integer] :page The page number. + # @option options [Integer] :per_page The number of results per page. + # @return [Array] + def group_descendants(id, options = {}) + get("/groups/#{url_encode id}/descendant_groups", query: options) + end + # Get a list of group members that are billable. # # @example From 0438984edf0537bb339e48c782d636a8ec09ff6c Mon Sep 17 00:00:00 2001 From: Gustavo Araujo Date: Thu, 31 Mar 2022 20:36:05 -0300 Subject: [PATCH 4/4] Update endpoint YARD compliance comment --- lib/gitlab/client/groups.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index 2910bef34..03a756aa1 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -76,11 +76,16 @@ def group_members(id, options = {}) # @example # Gitlab.group_descendants(42) # - # @param [Integer] id The ID of a group. - # @param [Hash] options A customizable set of options. - # @option options [Integer] :page The page number. - # @option options [Integer] :per_page The number of results per page. - # @return [Array] + # @param [Integer] id the ID of a group + # @param [Hash] options A customizable set of options. + # @option options [String] :skip_groups Skip the group IDs passed. + # @option options [String] :all_available Show all the groups you have access to (defaults to false for authenticated users). + # @option options [String] :search Return the list of authorized groups matching the search criteria. + # @option options [String] :order_by Order groups by name or path. Default is name. + # @option options [String] :sort Order groups in asc or desc order. Default is asc. + # @option options [String] :statistics Include group statistics (admins only). + # @option options [String] :owned Limit to groups owned by the current user. + # @return [Array] List of all subgroups under a group def group_descendants(id, options = {}) get("/groups/#{url_encode id}/descendant_groups", query: options) end