| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,5 @@ | |||
| 1 | + from typing import Any, Dict, List, Optional, TYPE_CHECKING | ||
| 2 | + | ||
| 1 | 3 | from gitlab import exceptions as exc | |
| 2 | 4 | from gitlab.base import RequiredOptional, RESTManager, RESTObject | |
| 3 | 5 | from gitlab.mixins import ( | |
@@ -44,7 +46,12 @@ class ProjectApprovalManager(GetWithoutIdMixin, UpdateMixin, RESTManager): | |||
| 44 | 46 | _update_uses_post = True | |
| 45 | 47 | ||
| 46 | 48 | @exc.on_http_error(exc.GitlabUpdateError) | |
| 47 | - def set_approvers(self, approver_ids=None, approver_group_ids=None, **kwargs): | ||
| 49 | + def set_approvers( | ||
| 50 | + self, | ||
| 51 | + approver_ids: Optional[List[int]] = None, | ||
| 52 | + approver_group_ids: Optional[List[int]] = None, | ||
| 53 | + **kwargs: Any, | ||
| 54 | + ) -> Dict[str, Any]: | ||
| 48 | 55 | """Change project-level allowed approvers and approver groups. | |
| 49 | 56 | ||
| 50 | 57 | Args: | |
@@ -54,13 +61,21 @@ def set_approvers(self, approver_ids=None, approver_group_ids=None, **kwargs): | |||
| 54 | 61 | Raises: | |
| 55 | 62 | GitlabAuthenticationError: If authentication is not correct | |
| 56 | 63 | GitlabUpdateError: If the server failed to perform the request | |
| 64 | + | ||
| 65 | + Returns: | ||
| 66 | + A dict value of the result | ||
| 57 | 67 | """ | |
| 58 | 68 | approver_ids = approver_ids or [] | |
| 59 | 69 | approver_group_ids = approver_group_ids or [] | |
| 60 | 70 | ||
| 71 | + if TYPE_CHECKING: | ||
| 72 | + assert self._parent is not None | ||
| 61 | 73 | path = f"/projects/{self._parent.get_id()}/approvers" | |
| 62 | 74 | data = {"approver_ids": approver_ids, "approver_group_ids": approver_group_ids} | |
| 63 | - self.gitlab.http_put(path, post_data=data, **kwargs) | ||
| 75 | + result = self.gitlab.http_put(path, post_data=data, **kwargs) | ||
| 76 | + if TYPE_CHECKING: | ||
| 77 | + assert isinstance(result, dict) | ||
| 78 | + return result | ||
| 64 | 79 | ||
| 65 | 80 | ||
| 66 | 81 | class ProjectApprovalRule(SaveMixin, ObjectDeleteMixin, RESTObject): | |
@@ -93,12 +108,12 @@ class ProjectMergeRequestApprovalManager(GetWithoutIdMixin, UpdateMixin, RESTMan | |||
| 93 | 108 | @exc.on_http_error(exc.GitlabUpdateError) | |
| 94 | 109 | def set_approvers( | |
| 95 | 110 | self, | |
| 96 | - approvals_required, | ||
| 97 | - approver_ids=None, | ||
| 98 | - approver_group_ids=None, | ||
| 99 | - approval_rule_name="name", | ||
| 100 | - **kwargs, | ||
| 101 | - ): | ||
| 111 | + approvals_required: int, | ||
| 112 | + approver_ids: Optional[List[int]] = None, | ||
| 113 | + approver_group_ids: Optional[List[int]] = None, | ||
| 114 | + approval_rule_name: str = "name", | ||
| 115 | + **kwargs: Any, | ||
| 116 | + ) -> RESTObject: | ||
| 102 | 117 | """Change MR-level allowed approvers and approver groups. | |
| 103 | 118 | ||
| 104 | 119 | Args: | |
@@ -120,7 +135,11 @@ def set_approvers( | |||
| 120 | 135 | "user_ids": approver_ids, | |
| 121 | 136 | "group_ids": approver_group_ids, | |
| 122 | 137 | } | |
| 123 | - approval_rules = self._parent.approval_rules | ||
| 138 | + if TYPE_CHECKING: | ||
| 139 | + assert self._parent is not None | ||
| 140 | + approval_rules: ProjectMergeRequestApprovalRuleManager = ( | ||
| 141 | + self._parent.approval_rules | ||
| 142 | + ) | ||
| 124 | 143 | """ update any existing approval rule matching the name""" | |
| 125 | 144 | existing_approval_rules = approval_rules.list() | |
| 126 | 145 | for ar in existing_approval_rules: | |
@@ -137,9 +156,10 @@ def set_approvers( | |||
| 137 | 156 | class ProjectMergeRequestApprovalRule(SaveMixin, RESTObject): | |
| 138 | 157 | _id_attr = "approval_rule_id" | |
| 139 | 158 | _short_print_attr = "approval_rule" | |
| 159 | + id: int | ||
| 140 | 160 | ||
| 141 | 161 | @exc.on_http_error(exc.GitlabUpdateError) | |
| 142 | - def save(self, **kwargs): | ||
| 162 | + def save(self, **kwargs: Any) -> None: | ||
| 143 | 163 | """Save the changes made to the object to the server. | |
| 144 | 164 | ||
| 145 | 165 | The object is updated to match what the server returns. | |
@@ -185,7 +205,9 @@ class ProjectMergeRequestApprovalRuleManager( | |||
| 185 | 205 | optional=("approval_project_rule_id", "user_ids", "group_ids"), | |
| 186 | 206 | ) | |
| 187 | 207 | ||
| 188 | - def create(self, data, **kwargs): | ||
| 208 | + def create( | ||
| 209 | + self, data: Optional[Dict[str, Any]] = None, **kwargs: Any | ||
| 210 | + ) -> RESTObject: | ||
| 189 | 211 | """Create a new object. | |
| 190 | 212 | ||
| 191 | 213 | Args: | |
@@ -202,6 +224,8 @@ def create(self, data, **kwargs): | |||
| 202 | 224 | RESTObject: A new instance of the manage object class build with | |
| 203 | 225 | the data sent by the server | |
| 204 | 226 | """ | |
| 227 | + if TYPE_CHECKING: | ||
| 228 | + assert data is not None | ||
| 205 | 229 | new_data = data.copy() | |
| 206 | 230 | new_data["id"] = self._from_parent_attrs["project_id"] | |
| 207 | 231 | new_data["merge_request_iid"] = self._from_parent_attrs["mr_iid"] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,6 @@ module = [ | |||
| 18 | 18 | "gitlab.v4.objects.issues", | |
| 19 | 19 | "gitlab.v4.objects.jobs", | |
| 20 | 20 | "gitlab.v4.objects.labels", | |
| 21 | - "gitlab.v4.objects.merge_request_approvals", | ||
| 22 | 21 | "gitlab.v4.objects.milestones", | |
| 23 | 22 | "gitlab.v4.objects.pipelines", | |
| 24 | 23 | "gitlab.v4.objects.repositories", | |
| Back | FazBrowse Home | New Git URL |
0 commit comments