Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(v4): split objects and managers per API resource
- Loading branch information
Showing
54 changed files
with
6,167 additions
and
5,850 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
class GroupAccessRequest(AccessRequestMixin, ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class GroupAccessRequestManager(ListMixin, CreateMixin, DeleteMixin, RESTManager): | ||
_path = "/groups/%(group_id)s/access_requests" | ||
_obj_cls = GroupAccessRequest | ||
_from_parent_attrs = {"group_id": "id"} | ||
|
||
|
||
class ProjectAccessRequest(AccessRequestMixin, ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class ProjectAccessRequestManager(ListMixin, CreateMixin, DeleteMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/access_requests" | ||
_obj_cls = ProjectAccessRequest | ||
_from_parent_attrs = {"project_id": "id"} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from gitlab import exceptions as exc | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
class ApplicationAppearance(SaveMixin, RESTObject): | ||
_id_attr = None | ||
|
||
|
||
class ApplicationAppearanceManager(GetWithoutIdMixin, UpdateMixin, RESTManager): | ||
_path = "/application/appearance" | ||
_obj_cls = ApplicationAppearance | ||
_update_attrs = ( | ||
tuple(), | ||
( | ||
"title", | ||
"description", | ||
"logo", | ||
"header_logo", | ||
"favicon", | ||
"new_project_guidelines", | ||
"header_message", | ||
"footer_message", | ||
"message_background_color", | ||
"message_font_color", | ||
"email_header_and_footer_enabled", | ||
), | ||
) | ||
|
||
@exc.on_http_error(exc.GitlabUpdateError) | ||
def update(self, id=None, new_data=None, **kwargs): | ||
"""Update an object on the server. | ||
Args: | ||
id: ID of the object to update (can be None if not required) | ||
new_data: the update data for the object | ||
**kwargs: Extra options to send to the server (e.g. sudo) | ||
Returns: | ||
dict: The new object data (*not* a RESTObject) | ||
Raises: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabUpdateError: If the server cannot perform the request | ||
""" | ||
new_data = new_data or {} | ||
data = new_data.copy() | ||
super(ApplicationAppearanceManager, self).update(id, data, **kwargs) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
class Application(ObjectDeleteMixin, RESTObject): | ||
_url = "/applications" | ||
_short_print_attr = "name" | ||
|
||
|
||
class ApplicationManager(ListMixin, CreateMixin, DeleteMixin, RESTManager): | ||
_path = "/applications" | ||
_obj_cls = Application | ||
_create_attrs = (("name", "redirect_uri", "scopes"), ("confidential",)) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,88 @@ | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
class ProjectIssueAwardEmoji(ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class ProjectIssueAwardEmojiManager(NoUpdateMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/issues/%(issue_iid)s/award_emoji" | ||
_obj_cls = ProjectIssueAwardEmoji | ||
_from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"} | ||
_create_attrs = (("name",), tuple()) | ||
|
||
|
||
class ProjectIssueNoteAwardEmoji(ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class ProjectIssueNoteAwardEmojiManager(NoUpdateMixin, RESTManager): | ||
_path = ( | ||
"/projects/%(project_id)s/issues/%(issue_iid)s" "/notes/%(note_id)s/award_emoji" | ||
) | ||
_obj_cls = ProjectIssueNoteAwardEmoji | ||
_from_parent_attrs = { | ||
"project_id": "project_id", | ||
"issue_iid": "issue_iid", | ||
"note_id": "id", | ||
} | ||
_create_attrs = (("name",), tuple()) | ||
|
||
|
||
class ProjectMergeRequestAwardEmoji(ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class ProjectMergeRequestAwardEmojiManager(NoUpdateMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/merge_requests/%(mr_iid)s/award_emoji" | ||
_obj_cls = ProjectMergeRequestAwardEmoji | ||
_from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"} | ||
_create_attrs = (("name",), tuple()) | ||
|
||
|
||
class ProjectMergeRequestNoteAwardEmoji(ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class ProjectMergeRequestNoteAwardEmojiManager(NoUpdateMixin, RESTManager): | ||
_path = ( | ||
"/projects/%(project_id)s/merge_requests/%(mr_iid)s" | ||
"/notes/%(note_id)s/award_emoji" | ||
) | ||
_obj_cls = ProjectMergeRequestNoteAwardEmoji | ||
_from_parent_attrs = { | ||
"project_id": "project_id", | ||
"mr_iid": "mr_iid", | ||
"note_id": "id", | ||
} | ||
_create_attrs = (("name",), tuple()) | ||
|
||
|
||
class ProjectSnippetAwardEmoji(ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class ProjectSnippetAwardEmojiManager(NoUpdateMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/snippets/%(snippet_id)s/award_emoji" | ||
_obj_cls = ProjectSnippetAwardEmoji | ||
_from_parent_attrs = {"project_id": "project_id", "snippet_id": "id"} | ||
_create_attrs = (("name",), tuple()) | ||
|
||
|
||
class ProjectSnippetNoteAwardEmoji(ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class ProjectSnippetNoteAwardEmojiManager(NoUpdateMixin, RESTManager): | ||
_path = ( | ||
"/projects/%(project_id)s/snippets/%(snippet_id)s" | ||
"/notes/%(note_id)s/award_emoji" | ||
) | ||
_obj_cls = ProjectSnippetNoteAwardEmoji | ||
_from_parent_attrs = { | ||
"project_id": "project_id", | ||
"snippet_id": "snippet_id", | ||
"note_id": "id", | ||
} | ||
_create_attrs = (("name",), tuple()) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
class GroupBadge(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class GroupBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager): | ||
_path = "/groups/%(group_id)s/badges" | ||
_obj_cls = GroupBadge | ||
_from_parent_attrs = {"group_id": "id"} | ||
_create_attrs = (("link_url", "image_url"), tuple()) | ||
_update_attrs = (tuple(), ("link_url", "image_url")) | ||
|
||
|
||
class ProjectBadge(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class ProjectBadgeManager(BadgeRenderMixin, CRUDMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/badges" | ||
_obj_cls = ProjectBadge | ||
_from_parent_attrs = {"project_id": "id"} | ||
_create_attrs = (("link_url", "image_url"), tuple()) | ||
_update_attrs = (tuple(), ("link_url", "image_url")) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
class GroupBoardList(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class GroupBoardListManager(CRUDMixin, RESTManager): | ||
_path = "/groups/%(group_id)s/boards/%(board_id)s/lists" | ||
_obj_cls = GroupBoardList | ||
_from_parent_attrs = {"group_id": "group_id", "board_id": "id"} | ||
_create_attrs = (("label_id",), tuple()) | ||
_update_attrs = (("position",), tuple()) | ||
|
||
|
||
class GroupBoard(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
_managers = (("lists", "GroupBoardListManager"),) | ||
|
||
|
||
class GroupBoardManager(CRUDMixin, RESTManager): | ||
_path = "/groups/%(group_id)s/boards" | ||
_obj_cls = GroupBoard | ||
_from_parent_attrs = {"group_id": "id"} | ||
_create_attrs = (("name",), tuple()) | ||
|
||
|
||
class ProjectBoardList(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class ProjectBoardListManager(CRUDMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/boards/%(board_id)s/lists" | ||
_obj_cls = ProjectBoardList | ||
_from_parent_attrs = {"project_id": "project_id", "board_id": "id"} | ||
_create_attrs = (("label_id",), tuple()) | ||
_update_attrs = (("position",), tuple()) | ||
|
||
|
||
class ProjectBoard(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
_managers = (("lists", "ProjectBoardListManager"),) | ||
|
||
|
||
class ProjectBoardManager(CRUDMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/boards" | ||
_obj_cls = ProjectBoard | ||
_from_parent_attrs = {"project_id": "id"} | ||
_create_attrs = (("name",), tuple()) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,80 @@ | ||
from gitlab import cli | ||
from gitlab import exceptions as exc | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
class ProjectBranch(ObjectDeleteMixin, RESTObject): | ||
_id_attr = "name" | ||
|
||
@cli.register_custom_action( | ||
"ProjectBranch", tuple(), ("developers_can_push", "developers_can_merge") | ||
) | ||
@exc.on_http_error(exc.GitlabProtectError) | ||
def protect(self, developers_can_push=False, developers_can_merge=False, **kwargs): | ||
"""Protect the branch. | ||
Args: | ||
developers_can_push (bool): Set to True if developers are allowed | ||
to push to the branch | ||
developers_can_merge (bool): Set to True if developers are allowed | ||
to merge to the branch | ||
**kwargs: Extra options to send to the server (e.g. sudo) | ||
Raises: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabProtectError: If the branch could not be protected | ||
""" | ||
id = self.get_id().replace("/", "%2F") | ||
path = "%s/%s/protect" % (self.manager.path, id) | ||
post_data = { | ||
"developers_can_push": developers_can_push, | ||
"developers_can_merge": developers_can_merge, | ||
} | ||
self.manager.gitlab.http_put(path, post_data=post_data, **kwargs) | ||
self._attrs["protected"] = True | ||
|
||
@cli.register_custom_action("ProjectBranch") | ||
@exc.on_http_error(exc.GitlabProtectError) | ||
def unprotect(self, **kwargs): | ||
"""Unprotect the branch. | ||
Args: | ||
**kwargs: Extra options to send to the server (e.g. sudo) | ||
Raises: | ||
GitlabAuthenticationError: If authentication is not correct | ||
GitlabProtectError: If the branch could not be unprotected | ||
""" | ||
id = self.get_id().replace("/", "%2F") | ||
path = "%s/%s/unprotect" % (self.manager.path, id) | ||
self.manager.gitlab.http_put(path, **kwargs) | ||
self._attrs["protected"] = False | ||
|
||
|
||
class ProjectBranchManager(NoUpdateMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/repository/branches" | ||
_obj_cls = ProjectBranch | ||
_from_parent_attrs = {"project_id": "id"} | ||
_create_attrs = (("branch", "ref"), tuple()) | ||
|
||
|
||
class ProjectProtectedBranch(ObjectDeleteMixin, RESTObject): | ||
_id_attr = "name" | ||
|
||
|
||
class ProjectProtectedBranchManager(NoUpdateMixin, RESTManager): | ||
_path = "/projects/%(project_id)s/protected_branches" | ||
_obj_cls = ProjectProtectedBranch | ||
_from_parent_attrs = {"project_id": "id"} | ||
_create_attrs = ( | ||
("name",), | ||
( | ||
"push_access_level", | ||
"merge_access_level", | ||
"unprotect_access_level", | ||
"allowed_to_push", | ||
"allowed_to_merge", | ||
"allowed_to_unprotect", | ||
), | ||
) |
This file contains 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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from gitlab.base import * # noqa | ||
from gitlab.mixins import * # noqa | ||
|
||
|
||
class BroadcastMessage(SaveMixin, ObjectDeleteMixin, RESTObject): | ||
pass | ||
|
||
|
||
class BroadcastMessageManager(CRUDMixin, RESTManager): | ||
_path = "/broadcast_messages" | ||
_obj_cls = BroadcastMessage | ||
|
||
_create_attrs = (("message",), ("starts_at", "ends_at", "color", "font")) | ||
_update_attrs = (tuple(), ("message", "starts_at", "ends_at", "color", "font")) |
Oops, something went wrong.