Skip to content

Commit 74f5e62

Browse files
authored
feat(objects): add support for Group wikis (#1484)
feat(objects): add support for Group wikis
1 parent 85bbd1a commit 74f5e62

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

docs/gl_objects/wikis.rst

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,37 @@ References
1111
+ :class:`gitlab.v4.objects.ProjectWiki`
1212
+ :class:`gitlab.v4.objects.ProjectWikiManager`
1313
+ :attr:`gitlab.v4.objects.Project.wikis`
14+
+ :class:`gitlab.v4.objects.GroupWiki`
15+
+ :class:`gitlab.v4.objects.GroupWikiManager`
16+
+ :attr:`gitlab.v4.objects.Group.wikis`
1417

15-
* GitLab API: https://docs.gitlab.com/ce/api/wikis.html
18+
* GitLab API for Projects: https://docs.gitlab.com/ce/api/wikis.html
19+
* GitLab API for Groups: https://docs.gitlab.com/ee/api/group_wikis.html
1620

1721
Examples
1822
--------
1923

20-
Get the list of wiki pages for a project::
24+
Get the list of wiki pages for a project. These do not contain the contents of the wiki page. You will need to call get(slug) to retrieve the content by accessing the content attribute::
2125

2226
pages = project.wikis.list()
2327

24-
Get a single wiki page::
28+
Get the list of wiki pages for a group. These do not contain the contents of the wiki page. You will need to call get(slug) to retrieve the content by accessing the content attribute::
29+
30+
pages = group.wikis.list()
31+
32+
Get a single wiki page for a project::
2533

2634
page = project.wikis.get(page_slug)
2735

28-
Create a wiki page::
36+
Get a single wiki page for a group::
37+
38+
page = group.wikis.get(page_slug)
39+
40+
Get the contents of a wiki page::
41+
42+
print(page.content)
43+
44+
Create a wiki page on a project level::
2945

3046
page = project.wikis.create({'title': 'Wiki Page 1',
3147
'content': open(a_file).read()})

gitlab/v4/objects/groups.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
from .runners import GroupRunnerManager # noqa: F401
2929
from .statistics import GroupIssuesStatisticsManager # noqa: F401
3030
from .variables import GroupVariableManager # noqa: F401
31+
from .wikis import GroupWikiManager # noqa: F401
3132

3233
__all__ = [
3334
"Group",
@@ -67,6 +68,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject):
6768
("variables", "GroupVariableManager"),
6869
("clusters", "GroupClusterManager"),
6970
("deploytokens", "GroupDeployTokenManager"),
71+
("wikis", "GroupWikiManager"),
7072
)
7173

7274
@cli.register_custom_action("Group", ("to_project_id",))

gitlab/v4/objects/wikis.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
__all__ = [
55
"ProjectWiki",
66
"ProjectWikiManager",
7+
"GroupWiki",
8+
"GroupWikiManager",
79
]
810

911

@@ -21,3 +23,19 @@ class ProjectWikiManager(CRUDMixin, RESTManager):
2123
)
2224
_update_attrs = RequiredOptional(optional=("title", "content", "format"))
2325
_list_filters = ("with_content",)
26+
27+
28+
class GroupWiki(SaveMixin, ObjectDeleteMixin, RESTObject):
29+
_id_attr = "slug"
30+
_short_print_attr = "slug"
31+
32+
33+
class GroupWikiManager(CRUDMixin, RESTManager):
34+
_path = "/groups/%(group_id)s/wikis"
35+
_obj_cls = GroupWiki
36+
_from_parent_attrs = {"group_id": "id"}
37+
_create_attrs = RequiredOptional(
38+
required=("title", "content"), optional=("format",)
39+
)
40+
_update_attrs = RequiredOptional(optional=("title", "content", "format"))
41+
_list_filters = ("with_content",)

tests/functional/api/test_groups.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,18 @@ def test_group_subgroups_projects(gl, user):
194194
assert group4.parent_id == group2.id
195195
assert gr1_project.namespace["id"] == group1.id
196196
assert gr2_project.namespace["parent_id"] == group1.id
197+
198+
199+
@pytest.mark.skip
200+
def test_group_wiki(group):
201+
content = "Group Wiki page content"
202+
wiki = group.wikis.create({"title": "groupwikipage", "content": content})
203+
assert len(group.wikis.list()) == 1
204+
205+
wiki = group.wikis.get(wiki.slug)
206+
assert wiki.content == content
207+
208+
wiki.content = "new content"
209+
wiki.save()
210+
wiki.delete()
211+
assert len(group.wikis.list()) == 0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy