Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions docs/gl_objects/wikis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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()})
Expand Down
2 changes: 2 additions & 0 deletions gitlab/v4/objects/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",))
Expand Down
18 changes: 18 additions & 0 deletions gitlab/v4/objects/wikis.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
__all__ = [
"ProjectWiki",
"ProjectWikiManager",
"GroupWiki",
"GroupWikiManager",
]


Expand All @@ -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",)
15 changes: 15 additions & 0 deletions tests/functional/api/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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