diff --git a/docs/gl_objects/wikis.rst b/docs/gl_objects/wikis.rst index 622c3a226..e98b9d443 100644 --- a/docs/gl_objects/wikis.rst +++ b/docs/gl_objects/wikis.rst @@ -11,21 +11,37 @@ References + :class:`gitlab.v4.objects.ProjectWiki` + :class:`gitlab.v4.objects.ProjectWikiManager` + :attr:`gitlab.v4.objects.Project.wikis` + + :class:`gitlab.v4.objects.GroupWiki` + + :class:`gitlab.v4.objects.GroupWikiManager` + + :attr:`gitlab.v4.objects.Group.wikis` -* GitLab API: https://docs.gitlab.com/ce/api/wikis.html +* GitLab API for Projects: https://docs.gitlab.com/ce/api/wikis.html +* GitLab API for Groups: https://docs.gitlab.com/ee/api/group_wikis.html Examples -------- -Get the list of wiki pages for a project:: +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:: pages = project.wikis.list() -Get a single wiki page:: +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:: + + pages = group.wikis.list() + +Get a single wiki page for a project:: page = project.wikis.get(page_slug) -Create a wiki page:: +Get a single wiki page for a group:: + + page = group.wikis.get(page_slug) + +Get the contents of a wiki page:: + + print(page.content) + +Create a wiki page on a project level:: page = project.wikis.create({'title': 'Wiki Page 1', 'content': open(a_file).read()}) diff --git a/gitlab/v4/objects/groups.py b/gitlab/v4/objects/groups.py index 2811c05f1..429d95da0 100644 --- a/gitlab/v4/objects/groups.py +++ b/gitlab/v4/objects/groups.py @@ -28,6 +28,7 @@ from .runners import GroupRunnerManager # noqa: F401 from .statistics import GroupIssuesStatisticsManager # noqa: F401 from .variables import GroupVariableManager # noqa: F401 +from .wikis import GroupWikiManager # noqa: F401 __all__ = [ "Group", @@ -67,6 +68,7 @@ class Group(SaveMixin, ObjectDeleteMixin, RESTObject): ("variables", "GroupVariableManager"), ("clusters", "GroupClusterManager"), ("deploytokens", "GroupDeployTokenManager"), + ("wikis", "GroupWikiManager"), ) @cli.register_custom_action("Group", ("to_project_id",)) diff --git a/gitlab/v4/objects/wikis.py b/gitlab/v4/objects/wikis.py index 52a230f45..a86b442da 100644 --- a/gitlab/v4/objects/wikis.py +++ b/gitlab/v4/objects/wikis.py @@ -4,6 +4,8 @@ __all__ = [ "ProjectWiki", "ProjectWikiManager", + "GroupWiki", + "GroupWikiManager", ] @@ -21,3 +23,19 @@ class ProjectWikiManager(CRUDMixin, RESTManager): ) _update_attrs = RequiredOptional(optional=("title", "content", "format")) _list_filters = ("with_content",) + + +class GroupWiki(SaveMixin, ObjectDeleteMixin, RESTObject): + _id_attr = "slug" + _short_print_attr = "slug" + + +class GroupWikiManager(CRUDMixin, RESTManager): + _path = "/groups/%(group_id)s/wikis" + _obj_cls = GroupWiki + _from_parent_attrs = {"group_id": "id"} + _create_attrs = RequiredOptional( + required=("title", "content"), optional=("format",) + ) + _update_attrs = RequiredOptional(optional=("title", "content", "format")) + _list_filters = ("with_content",) diff --git a/tests/functional/api/test_groups.py b/tests/functional/api/test_groups.py index c2b8cbd61..439d01ccd 100644 --- a/tests/functional/api/test_groups.py +++ b/tests/functional/api/test_groups.py @@ -194,3 +194,18 @@ def test_group_subgroups_projects(gl, user): assert group4.parent_id == group2.id assert gr1_project.namespace["id"] == group1.id assert gr2_project.namespace["parent_id"] == group1.id + + +@pytest.mark.skip +def test_group_wiki(group): + content = "Group Wiki page content" + wiki = group.wikis.create({"title": "groupwikipage", "content": content}) + assert len(group.wikis.list()) == 1 + + wiki = group.wikis.get(wiki.slug) + assert wiki.content == content + + wiki.content = "new content" + wiki.save() + wiki.delete() + assert len(group.wikis.list()) == 0