Skip to content

Commit a5a48ad

Browse files
committed
refactor(v4): split objects and managers per API resource
1 parent 9d6c188 commit a5a48ad

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+6167
-5850
lines changed

gitlab/v4/objects/__init__.py

+57-5,850
Large diffs are not rendered by default.

gitlab/v4/objects/access_requests.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
from gitlab.base import * # noqa
2+
from gitlab.mixins import * # noqa
3+
4+
5+
class GroupAccessRequest(AccessRequestMixin, ObjectDeleteMixin, RESTObject):
6+
pass
7+
8+
9+
class GroupAccessRequestManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
10+
_path = "/groups/%(group_id)s/access_requests"
11+
_obj_cls = GroupAccessRequest
12+
_from_parent_attrs = {"group_id": "id"}
13+
14+
15+
class ProjectAccessRequest(AccessRequestMixin, ObjectDeleteMixin, RESTObject):
16+
pass
17+
18+
19+
class ProjectAccessRequestManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
20+
_path = "/projects/%(project_id)s/access_requests"
21+
_obj_cls = ProjectAccessRequest
22+
_from_parent_attrs = {"project_id": "id"}

gitlab/v4/objects/appearance.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from gitlab import exceptions as exc
2+
from gitlab.base import * # noqa
3+
from gitlab.mixins import * # noqa
4+
5+
6+
class ApplicationAppearance(SaveMixin, RESTObject):
7+
_id_attr = None
8+
9+
10+
class ApplicationAppearanceManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
11+
_path = "/application/appearance"
12+
_obj_cls = ApplicationAppearance
13+
_update_attrs = (
14+
tuple(),
15+
(
16+
"title",
17+
"description",
18+
"logo",
19+
"header_logo",
20+
"favicon",
21+
"new_project_guidelines",
22+
"header_message",
23+
"footer_message",
24+
"message_background_color",
25+
"message_font_color",
26+
"email_header_and_footer_enabled",
27+
),
28+
)
29+
30+
@exc.on_http_error(exc.GitlabUpdateError)
31+
def update(self, id=None, new_data=None, **kwargs):
32+
"""Update an object on the server.
33+
34+
Args:
35+
id: ID of the object to update (can be None if not required)
36+
new_data: the update data for the object
37+
**kwargs: Extra options to send to the server (e.g. sudo)
38+
39+
Returns:
40+
dict: The new object data (*not* a RESTObject)
41+
42+
Raises:
43+
GitlabAuthenticationError: If authentication is not correct
44+
GitlabUpdateError: If the server cannot perform the request
45+
"""
46+
new_data = new_data or {}
47+
data = new_data.copy()
48+
super(ApplicationAppearanceManager, self).update(id, data, **kwargs)

gitlab/v4/objects/applications.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from gitlab.base import * # noqa
2+
from gitlab.mixins import * # noqa
3+
4+
5+
class Application(ObjectDeleteMixin, RESTObject):
6+
_url = "/applications"
7+
_short_print_attr = "name"
8+
9+
10+
class ApplicationManager(ListMixin, CreateMixin, DeleteMixin, RESTManager):
11+
_path = "/applications"
12+
_obj_cls = Application
13+
_create_attrs = (("name", "redirect_uri", "scopes"), ("confidential",))

gitlab/v4/objects/award_emojis.py

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
from gitlab.base import * # noqa
2+
from gitlab.mixins import * # noqa
3+
4+
5+
class ProjectIssueAwardEmoji(ObjectDeleteMixin, RESTObject):
6+
pass
7+
8+
9+
class ProjectIssueAwardEmojiManager(NoUpdateMixin, RESTManager):
10+
_path = "/projects/%(project_id)s/issues/%(issue_iid)s/award_emoji"
11+
_obj_cls = ProjectIssueAwardEmoji
12+
_from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"}
13+
_create_attrs = (("name",), tuple())
14+
15+
16+
class ProjectIssueNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
17+
pass
18+
19+
20+
class ProjectIssueNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
21+
_path = (
22+
"/projects/%(project_id)s/issues/%(issue_iid)s" "/notes/%(note_id)s/award_emoji"
23+
)
24+
_obj_cls = ProjectIssueNoteAwardEmoji
25+
_from_parent_attrs = {
26+
"project_id": "project_id",
27+
"issue_iid": "issue_iid",
28+
"note_id": "id",
29+
}
30+
_create_attrs = (("name",), tuple())
31+
32+
33+
class ProjectMergeRequestAwardEmoji(ObjectDeleteMixin, RESTObject):
34+
pass
35+
36+
37+
class ProjectMergeRequestAwardEmojiManager(NoUpdateMixin, RESTManager):
38+
_path = "/projects/%(project_id)s/merge_requests/%(mr_iid)s/award_emoji"
39+
_obj_cls = ProjectMergeRequestAwardEmoji
40+
_from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"}
41+
_create_attrs = (("name",), tuple())
42+
43+
44+
class ProjectMergeRequestNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
45+
pass
46+
47+
48+
class ProjectMergeRequestNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
49+
_path = (
50+
"/projects/%(project_id)s/merge_requests/%(mr_iid)s"
51+
"/notes/%(note_id)s/award_emoji"
52+
)
53+
_obj_cls = ProjectMergeRequestNoteAwardEmoji
54+
_from_parent_attrs = {
55+
"project_id": "project_id",
56+
"mr_iid": "mr_iid",
57+
"note_id": "id",
58+
}
59+
_create_attrs = (("name",), tuple())
60+
61+
62+
class ProjectSnippetAwardEmoji(ObjectDeleteMixin, RESTObject):
63+
pass
64+
65+
66+
class ProjectSnippetAwardEmojiManager(NoUpdateMixin, RESTManager):
67+
_path = "/projects/%(project_id)s/snippets/%(snippet_id)s/award_emoji"
68+
_obj_cls = ProjectSnippetAwardEmoji
69+
_from_parent_attrs = {"project_id": "project_id", "snippet_id": "id"}
70+
_create_attrs = (("name",), tuple())
71+
72+
73+
class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject):
74+
pass
75+
76+
77+
class ProjectSnippetNoteAwardEmojiManager(NoUpdateMixin, RESTManager):
78+
_path = (
79+
"/projects/%(project_id)s/snippets/%(snippet_id)s"
80+
"/notes/%(note_id)s/award_emoji"
81+
)
82+
_obj_cls = ProjectSnippetNoteAwardEmoji
83+
_from_parent_attrs = {
84+
"project_id": "project_id",
85+
"snippet_id": "snippet_id",
86+
"note_id": "id",
87+
}
88+
_create_attrs = (("name",), tuple())

gitlab/v4/objects/badges.py

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from gitlab.base import * # noqa
2+
from gitlab.mixins import * # noqa
3+
4+
5+
class GroupBadge(SaveMixin, ObjectDeleteMixin, RESTObject):
6+
pass
7+
8+
9+
class GroupBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager):
10+
_path = "/groups/%(group_id)s/badges"
11+
_obj_cls = GroupBadge
12+
_from_parent_attrs = {"group_id": "id"}
13+
_create_attrs = (("link_url", "image_url"), tuple())
14+
_update_attrs = (tuple(), ("link_url", "image_url"))
15+
16+
17+
class ProjectBadge(SaveMixin, ObjectDeleteMixin, RESTObject):
18+
pass
19+
20+
21+
class ProjectBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager):
22+
_path = "/projects/%(project_id)s/badges"
23+
_obj_cls = ProjectBadge
24+
_from_parent_attrs = {"project_id": "id"}
25+
_create_attrs = (("link_url", "image_url"), tuple())
26+
_update_attrs = (tuple(), ("link_url", "image_url"))

gitlab/v4/objects/boards.py

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from gitlab.base import * # noqa
2+
from gitlab.mixins import * # noqa
3+
4+
5+
class GroupBoardList(SaveMixin, ObjectDeleteMixin, RESTObject):
6+
pass
7+
8+
9+
class GroupBoardListManager(CRUDMixin, RESTManager):
10+
_path = "/groups/%(group_id)s/boards/%(board_id)s/lists"
11+
_obj_cls = GroupBoardList
12+
_from_parent_attrs = {"group_id": "group_id", "board_id": "id"}
13+
_create_attrs = (("label_id",), tuple())
14+
_update_attrs = (("position",), tuple())
15+
16+
17+
class GroupBoard(SaveMixin, ObjectDeleteMixin, RESTObject):
18+
_managers = (("lists", "GroupBoardListManager"),)
19+
20+
21+
class GroupBoardManager(CRUDMixin, RESTManager):
22+
_path = "/groups/%(group_id)s/boards"
23+
_obj_cls = GroupBoard
24+
_from_parent_attrs = {"group_id": "id"}
25+
_create_attrs = (("name",), tuple())
26+
27+
28+
class ProjectBoardList(SaveMixin, ObjectDeleteMixin, RESTObject):
29+
pass
30+
31+
32+
class ProjectBoardListManager(CRUDMixin, RESTManager):
33+
_path = "/projects/%(project_id)s/boards/%(board_id)s/lists"
34+
_obj_cls = ProjectBoardList
35+
_from_parent_attrs = {"project_id": "project_id", "board_id": "id"}
36+
_create_attrs = (("label_id",), tuple())
37+
_update_attrs = (("position",), tuple())
38+
39+
40+
class ProjectBoard(SaveMixin, ObjectDeleteMixin, RESTObject):
41+
_managers = (("lists", "ProjectBoardListManager"),)
42+
43+
44+
class ProjectBoardManager(CRUDMixin, RESTManager):
45+
_path = "/projects/%(project_id)s/boards"
46+
_obj_cls = ProjectBoard
47+
_from_parent_attrs = {"project_id": "id"}
48+
_create_attrs = (("name",), tuple())

gitlab/v4/objects/branches.py

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
from gitlab import cli
2+
from gitlab import exceptions as exc
3+
from gitlab.base import * # noqa
4+
from gitlab.mixins import * # noqa
5+
6+
7+
class ProjectBranch(ObjectDeleteMixin, RESTObject):
8+
_id_attr = "name"
9+
10+
@cli.register_custom_action(
11+
"ProjectBranch", tuple(), ("developers_can_push", "developers_can_merge")
12+
)
13+
@exc.on_http_error(exc.GitlabProtectError)
14+
def protect(self, developers_can_push=False, developers_can_merge=False, **kwargs):
15+
"""Protect the branch.
16+
17+
Args:
18+
developers_can_push (bool): Set to True if developers are allowed
19+
to push to the branch
20+
developers_can_merge (bool): Set to True if developers are allowed
21+
to merge to the branch
22+
**kwargs: Extra options to send to the server (e.g. sudo)
23+
24+
Raises:
25+
GitlabAuthenticationError: If authentication is not correct
26+
GitlabProtectError: If the branch could not be protected
27+
"""
28+
id = self.get_id().replace("/", "%2F")
29+
path = "%s/%s/protect" % (self.manager.path, id)
30+
post_data = {
31+
"developers_can_push": developers_can_push,
32+
"developers_can_merge": developers_can_merge,
33+
}
34+
self.manager.gitlab.http_put(path, post_data=post_data, **kwargs)
35+
self._attrs["protected"] = True
36+
37+
@cli.register_custom_action("ProjectBranch")
38+
@exc.on_http_error(exc.GitlabProtectError)
39+
def unprotect(self, **kwargs):
40+
"""Unprotect the branch.
41+
42+
Args:
43+
**kwargs: Extra options to send to the server (e.g. sudo)
44+
45+
Raises:
46+
GitlabAuthenticationError: If authentication is not correct
47+
GitlabProtectError: If the branch could not be unprotected
48+
"""
49+
id = self.get_id().replace("/", "%2F")
50+
path = "%s/%s/unprotect" % (self.manager.path, id)
51+
self.manager.gitlab.http_put(path, **kwargs)
52+
self._attrs["protected"] = False
53+
54+
55+
class ProjectBranchManager(NoUpdateMixin, RESTManager):
56+
_path = "/projects/%(project_id)s/repository/branches"
57+
_obj_cls = ProjectBranch
58+
_from_parent_attrs = {"project_id": "id"}
59+
_create_attrs = (("branch", "ref"), tuple())
60+
61+
62+
class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject):
63+
_id_attr = "name"
64+
65+
66+
class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager):
67+
_path = "/projects/%(project_id)s/protected_branches"
68+
_obj_cls = ProjectProtectedBranch
69+
_from_parent_attrs = {"project_id": "id"}
70+
_create_attrs = (
71+
("name",),
72+
(
73+
"push_access_level",
74+
"merge_access_level",
75+
"unprotect_access_level",
76+
"allowed_to_push",
77+
"allowed_to_merge",
78+
"allowed_to_unprotect",
79+
),
80+
)
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from gitlab.base import * # noqa
2+
from gitlab.mixins import * # noqa
3+
4+
5+
class BroadcastMessage(SaveMixin, ObjectDeleteMixin, RESTObject):
6+
pass
7+
8+
9+
class BroadcastMessageManager(CRUDMixin, RESTManager):
10+
_path = "/broadcast_messages"
11+
_obj_cls = BroadcastMessage
12+
13+
_create_attrs = (("message",), ("starts_at", "ends_at", "color", "font"))
14+
_update_attrs = (tuple(), ("message", "starts_at", "ends_at", "color", "font"))

0 commit comments

Comments
 (0)