FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

feat(objects): add support for Group wikis by spamsch · Pull Request #1484 · python-gitlab/python-gitlab · GitHub

Repository navigation

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

Filter by extension

Filter by extension .py  (3) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
24 changes: 20 additions & 4 deletions docs/gl_objects/wikis.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Comment thread
spamsch marked this conversation as resolved.
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)
Comment thread
spamsch marked this conversation as resolved.

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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL