Skip to content

Commit 421a4ae

Browse files
fix: add support for projects.groups.*
Add support for `projects.groups.*` endpoints. Closes #1717
1 parent 8d4c953 commit 421a4ae

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

gitlab/v4/objects/projects.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,24 @@ class GroupProjectManager(ListMixin, RESTManager):
109109
)
110110

111111

112+
class ProjectGroup(RESTObject):
113+
pass
114+
115+
116+
class ProjectGroupManager(ListMixin, RESTManager):
117+
_path = "/projects/{project_id}/groups"
118+
_obj_cls = ProjectGroup
119+
_from_parent_attrs = {"project_id": "id"}
120+
_list_filters = (
121+
"search",
122+
"skip_groups",
123+
"with_shared",
124+
"shared_min_access_level",
125+
"shared_visible_only",
126+
)
127+
_types = {"skip_groups": types.ListAttribute}
128+
129+
112130
class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTObject):
113131
_short_print_attr = "path"
114132

@@ -132,6 +150,7 @@ class Project(RefreshMixin, SaveMixin, ObjectDeleteMixin, RepositoryMixin, RESTO
132150
files: ProjectFileManager
133151
forks: "ProjectForkManager"
134152
generic_packages: GenericPackageManager
153+
groups: ProjectGroupManager
135154
hooks: ProjectHookManager
136155
imports: ProjectImportManager
137156
issues: ProjectIssueManager

tests/functional/api/test_projects.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,3 +311,21 @@ def test_project_wiki(project):
311311
wiki.save()
312312
wiki.delete()
313313
assert len(project.wikis.list()) == 0
314+
315+
316+
def test_project_groups_list(gl, group):
317+
"""Test listing groups of a project"""
318+
# Create a subgroup of our top-group, we will place our new project inside
319+
# this group.
320+
group2 = gl.groups.create(
321+
{"name": "group2_proj", "path": "group2_proj", "parent_id": group.id}
322+
)
323+
data = {
324+
"name": "test-project-tpsg",
325+
"namespace_id": group2.id,
326+
}
327+
project = gl.projects.create(data)
328+
329+
groups = project.groups.list()
330+
group_ids = set([x.id for x in groups])
331+
assert set((group.id, group2.id)) == group_ids

0 commit comments

Comments
 (0)