diff --git a/lib/gitlab/client/groups.rb b/lib/gitlab/client/groups.rb index 63afb1a9c..03a756aa1 100644 --- a/lib/gitlab/client/groups.rb +++ b/lib/gitlab/client/groups.rb @@ -71,6 +71,25 @@ 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 [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 + # Get a list of group members that are billable. # # @example 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}] 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')