diff options
| author | Walter Rowe <walter.rowe@gmail.com> | 2022-05-31 15:36:14 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-31 21:36:14 +0200 |
| commit | 3fa330cc341bbedb163ba757c7f6578d735c6efb (patch) | |
| tree | 6a27d234a22e77233990ba89991aa41d438c2528 /gitlab/v4/objects | |
| parent | 37eb8e0a4f0fd5fc7e221163b84df3461e64475b (diff) | |
| download | gitlab-3fa330cc341bbedb163ba757c7f6578d735c6efb.tar.gz | |
feat: support mutually exclusive attributes and consolidate validation to fix board lists (#2037)
add exclusive tuple to RequiredOptional data class to support for
mutually exclusive attributes
consolidate _check_missing_create_attrs and _check_missing_update_attrs
from mixins.py into _validate_attrs in utils.py
change _create_attrs in board list manager classes from
required=('label_ld',) to
exclusive=('label_id','asignee_id','milestone_id')
closes https://github.com/python-gitlab/python-gitlab/issues/1897
Diffstat (limited to 'gitlab/v4/objects')
| -rw-r--r-- | gitlab/v4/objects/boards.py | 8 | ||||
| -rw-r--r-- | gitlab/v4/objects/epics.py | 4 | ||||
| -rw-r--r-- | gitlab/v4/objects/files.py | 4 | ||||
| -rw-r--r-- | gitlab/v4/objects/issues.py | 4 |
4 files changed, 12 insertions, 8 deletions
diff --git a/gitlab/v4/objects/boards.py b/gitlab/v4/objects/boards.py index a5c59b3..c5243db 100644 --- a/gitlab/v4/objects/boards.py +++ b/gitlab/v4/objects/boards.py @@ -24,7 +24,9 @@ class GroupBoardListManager(CRUDMixin, RESTManager): _path = "/groups/{group_id}/boards/{board_id}/lists" _obj_cls = GroupBoardList _from_parent_attrs = {"group_id": "group_id", "board_id": "id"} - _create_attrs = RequiredOptional(required=("label_id",)) + _create_attrs = RequiredOptional( + exclusive=("label_id", "assignee_id", "milestone_id") + ) _update_attrs = RequiredOptional(required=("position",)) def get( @@ -55,7 +57,9 @@ class ProjectBoardListManager(CRUDMixin, RESTManager): _path = "/projects/{project_id}/boards/{board_id}/lists" _obj_cls = ProjectBoardList _from_parent_attrs = {"project_id": "project_id", "board_id": "id"} - _create_attrs = RequiredOptional(required=("label_id",)) + _create_attrs = RequiredOptional( + exclusive=("label_id", "assignee_id", "milestone_id") + ) _update_attrs = RequiredOptional(required=("position",)) def get( diff --git a/gitlab/v4/objects/epics.py b/gitlab/v4/objects/epics.py index 76dadf2..f9b110b 100644 --- a/gitlab/v4/objects/epics.py +++ b/gitlab/v4/objects/epics.py @@ -1,7 +1,7 @@ from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union from gitlab import exceptions as exc -from gitlab import types +from gitlab import types, utils from gitlab.base import RESTManager, RESTObject from gitlab.mixins import ( CreateMixin, @@ -107,7 +107,7 @@ class GroupEpicIssueManager( """ if TYPE_CHECKING: assert data is not None - CreateMixin._check_missing_create_attrs(self, data) + utils._validate_attrs(data=data, attributes=self._create_attrs) path = f"{self.path}/{data.pop('issue_id')}" server_data = self.gitlab.http_post(path, **kwargs) if TYPE_CHECKING: diff --git a/gitlab/v4/objects/files.py b/gitlab/v4/objects/files.py index c0b7261..b80d129 100644 --- a/gitlab/v4/objects/files.py +++ b/gitlab/v4/objects/files.py @@ -145,7 +145,7 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa if TYPE_CHECKING: assert data is not None - self._check_missing_create_attrs(data) + utils._validate_attrs(data=data, attributes=self._create_attrs) new_data = data.copy() file_path = utils.EncodedId(new_data.pop("file_path")) path = f"{self.path}/{file_path}" @@ -179,7 +179,7 @@ class ProjectFileManager(GetMixin, CreateMixin, UpdateMixin, DeleteMixin, RESTMa file_path = utils.EncodedId(file_path) data["file_path"] = file_path path = f"{self.path}/{file_path}" - self._check_missing_update_attrs(data) + utils._validate_attrs(data=data, attributes=self._update_attrs) result = self.gitlab.http_put(path, post_data=data, **kwargs) if TYPE_CHECKING: assert isinstance(result, dict) diff --git a/gitlab/v4/objects/issues.py b/gitlab/v4/objects/issues.py index e368357..f4da4b1 100644 --- a/gitlab/v4/objects/issues.py +++ b/gitlab/v4/objects/issues.py @@ -2,7 +2,7 @@ from typing import Any, cast, Dict, Tuple, TYPE_CHECKING, Union from gitlab import cli from gitlab import exceptions as exc -from gitlab import types +from gitlab import types, utils from gitlab.base import RESTManager, RESTObject from gitlab.mixins import ( CreateMixin, @@ -272,7 +272,7 @@ class ProjectIssueLinkManager(ListMixin, CreateMixin, DeleteMixin, RESTManager): GitlabAuthenticationError: If authentication is not correct GitlabCreateError: If the server cannot perform the request """ - self._check_missing_create_attrs(data) + utils._validate_attrs(data=data, attributes=self._create_attrs) if TYPE_CHECKING: assert self.path is not None server_data = self.gitlab.http_post(self.path, post_data=data, **kwargs) |
