diff options
author | Raimund Hook <raimund.hook@exfo.com> | 2021-09-24 10:22:27 +0100 |
---|---|---|
committer | Raimund Hook <raimund.hook@exfo.com> | 2021-10-18 10:30:34 +0100 |
commit | 6d7c88a1fe401d271a34df80943634652195b140 (patch) | |
tree | 0596d9782a50a60e95d1677c17f9a02428993d1d /gitlab/mixins.py | |
parent | 905781bed2afa33634b27842a42a077a160cffb8 (diff) | |
download | gitlab-6d7c88a1fe401d271a34df80943634652195b140.tar.gz |
feat(api): add project label promotion
Adds a mixin that allows the /promote endpoint to be called.
Signed-off-by: Raimund Hook <raimund.hook@exfo.com>
Diffstat (limited to 'gitlab/mixins.py')
-rw-r--r-- | gitlab/mixins.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/gitlab/mixins.py b/gitlab/mixins.py index 0c2cd94..62ff6dc 100644 --- a/gitlab/mixins.py +++ b/gitlab/mixins.py @@ -926,3 +926,50 @@ class BadgeRenderMixin(_RestManagerBase): if TYPE_CHECKING: assert not isinstance(result, requests.Response) return result + + +class PromoteMixin(_RestObjectBase): + _id_attr: Optional[str] + _attrs: Dict[str, Any] + _module: ModuleType + _parent_attrs: Dict[str, Any] + _updated_attrs: Dict[str, Any] + _update_uses_post: bool = False + manager: base.RESTManager + + def _get_update_method( + self, + ) -> Callable[..., Union[Dict[str, Any], requests.Response]]: + """Return the HTTP method to use. + + Returns: + object: http_put (default) or http_post + """ + if self._update_uses_post: + http_method = self.manager.gitlab.http_post + else: + http_method = self.manager.gitlab.http_put + return http_method + + @exc.on_http_error(exc.GitlabPromoteError) + def promote(self, **kwargs: Any) -> Dict[str, Any]: + """Promote the item. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabPromoteError: If the item could not be promoted + GitlabParsingError: If the json data could not be parsed + + Returns: + dict: The updated object data (*not* a RESTObject) + """ + + path = "%s/%s/promote" % (self.manager.path, self.id) + http_method = self._get_update_method() + result = http_method(path, **kwargs) + if TYPE_CHECKING: + assert not isinstance(result, requests.Response) + return result |