Groups

Groups

Use Group objects to manipulate groups. The gitlab.Gitlab.groups manager object provides helper functions.

Examples

List the groups:

groups = gl.groups.list()

Search groups:

groups = gl.groups.search('group')

Get a group’s detail:

group = gl.groups.get(group_id)

List a group’s projects:

projects = group.projects.list()
# or
projects = gl.group_projects.list(group_id)

You can filter and sort the result using the following parameters:

  • archived: limit by archived status
  • visibility: limit by visibility. Allowed values are public, internal and private
  • search: limit to groups matching the given value
  • order_by: sort by criteria. Allowed values are id, name, path, created_at, updated_at and last_activity_at
  • sort: sort order: asc or desc
  • ci_enabled_first: return CI enabled groups first

Create a group:

group = gl.groups.create({'name': 'group1', 'path': 'group1'})

Update a group:

group.description = 'My awesome group'
group.save()

Remove a group:

gl.group.delete(group_id)
# or
group.delete()

Group members

Use GroupMember objects to manipulate groups. The gitlab.Gitlab.group_members and Group.members manager objects provide helper functions.

The following Group attributes define the supported access levels:

  • GUEST_ACCESS = 10
  • REPORTER_ACCESS = 20
  • DEVELOPER_ACCESS = 30
  • MASTER_ACCESS = 40
  • OWNER_ACCESS = 50

List group members:

members = gl.group_members.list(group_id=1)
# or
members = group.members.list()

Get a group member:

members = gl.group_members.get(member_id)
# or
members = group.members.get(member_id)

Add a member to the group:

member = gl.group_members.create({'user_id': user_id,
                                  'access_level': gitlab.GUEST_ACCESS},
                                 group_id=1)
# or
member = group.members.create({'user_id': user_id,
                               'access_level': gitlab.GUEST_ACCESS})

Update a member (change the access level):

member.access_level = gitlab.DEVELOPER_ACCESS
member.save()

Remove a member from the group:

gl.group_members.delete(member_id, group_id=1)
# or
group.members.delete(member_id)
# or
member.delete()