8000 feat(api): add support for project Pages API · python-gitlab/python-gitlab@0ee0e02 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0ee0e02

Browse files
nejchmax-wittig
authored andcommitted
feat(api): add support for project Pages API
1 parent 5c27546 commit 0ee0e02

File tree

4 files changed

+80
-9
lines changed

4 files changed

+80
-9
lines changed

docs/gl_objects/pagesdomains.rst

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,38 @@
1-
#############
2-
Pages domains
3-
#############
1+
#######################
2+
Pages and Pages domains
3+
#######################
44

5-
Admin
6-
=====
5+
Project pages
6+
=============
7+
8+
References
9+
----------
10+
11+
* v4 API:
12+
13+
+ :class:`gitlab.v4.objects.ProjectPages`
14+
+ :class:`gitlab.v4.objects.ProjectPagesManager`
15+
+ :attr:`gitlab.v4.objects.Project.pages`
16+
17+
* GitLab API: https://docs.gitlab.com/ee/api/pages.html
18+
19+
Examples
20+
--------
21+
22+
Get Pages settings for a project::
23+
24+
pages = project.pages.get()
25+
26+
Update Pages settings for a project::
27+
28+
project.pages.update(new_data={'pages_https_only': True})
29+
30+
Delete (unpublish) Pages for a project (admin only)::
31+
32+
project.pages.delete()
33+
34+
Pages domains (admin only)
35+
==========================
736

837
References
938
----------
@@ -23,8 +52,8 @@ List all the existing domains (admin only)::
2352

2453
domains = gl.pagesdomains.list()
2554

26-
Project pages domain
27-
====================
55+
Project Pages domains
56+
=====================
2857

2958
References
3059
----------

gitlab/v4/objects/pages.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
from typing import Any, cast, Union
22

33
from gitlab.base import RESTManager, RESTObject
4-
from gitlab.mixins import CRUDMixin, ListMixin, ObjectDeleteMixin, SaveMixin
4+
from gitlab.mixins import (
5+
CRUDMixin,
6+
DeleteMixin,
7+
GetWithoutIdMixin,
8+
ListMixin,
9+
ObjectDeleteMixin,
10+
RefreshMixin,
11+
SaveMixin,
12+
UpdateMethod,
13+
UpdateMixin,
14+
)
515
from gitlab.types import RequiredOptional
616

717
__all__ = [
818
"PagesDomain",
919
"PagesDomainManager",
1020
"ProjectPagesDomain",
1121
"ProjectPagesDomainManager",
22+
"ProjectPages",
23+
"ProjectPagesManager",
1224
]
1325

1426

@@ -38,3 +50,20 @@ def get(
3850
self, id: Union[str, int], lazy: bool = False, **kwargs: Any
3951
) -> ProjectPagesDomain:
4052
return cast(ProjectPagesDomain, super().get(id=id, lazy=lazy, **kwargs))
53+
54+
55+
class ProjectPages(ObjectDeleteMixin, RefreshMixin, RESTObject):
56+
_id_attr = None
57+
58+
59+
class ProjectPagesManager(DeleteMixin, UpdateMixin, GetWithoutIdMixin, RESTManager):
60+
_path = "/projects/{project_id}/pages"
61+
_obj_cls = ProjectPages
62+
_from_parent_attrs = {"project_id": "id"}
63+
_update_attrs = RequiredOptional(
64+
optional=("pages_unique_domain_enabled", "pages_https_only")
65+
)
66+
_update_method: UpdateMethod = UpdateMethod.PATCH
67+
68+
def get(self, **kwargs: Any) -> ProjectPages:
69+
return cast(ProjectPages, super().get(**kwargs))

gitlab/v4/objects/projects.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
from .notification_settings import ProjectNotificationSettingsManager # noqa: F401
7979
from .package_protection_rules import ProjectPackageProtectionRuleManager
8080
from .packages import GenericPackageManager, ProjectPackageManager # noqa: F401
81-
from .pages import ProjectPagesDomainManager # noqa: F401
81+
from .pages import ProjectPagesDomainManager, ProjectPagesManager # noqa: F401
8282
from .pipelines import ( # noqa: F401
8383
ProjectPipeline,
8484
ProjectPipelineManager,
@@ -216,6 +216,7 @@ class Project(
216216
notificationsettings: ProjectNotificationSettingsManager
217217
packages: ProjectPackageManager
218218
package_protection_rules: ProjectPackageProtectionRuleManager
219+
pages: ProjectPagesManager
219220
pagesdomains: ProjectPagesDomainManager
220221
pipelines: ProjectPipelineManager
221222
pipelineschedules: ProjectPipelineScheduleManager

tests/functional/api/test_projects.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ def test_project_milestone_promotion(gl, group):
240240
)
241241

242242

243+
def test_project_pages(project):
244+
pages = project.pages.get()
245+
assert pages.is_unique_domain_enabled is True
246+
247+
project.pages.update(new_data={"pages_unique_domain_enabled": False})
248+
249+
pages.refresh()
250+
assert pages.is_unique_domain_enabled is False
251+
252+
project.pages.delete()
253+
254+
243255
def test_project_pages_domains(gl, project):
244256
domain = project.pagesdomains.create({"domain": "foo.domain.com"})
245257
assert domain in project.pagesdomains.list()

0 commit comments

Comments
 (0)
0