Skip to content

RFE: Support deployment approve/reject #2253

Closed
@JohnVillalovos

Description

@JohnVillalovos

Discussed in #2252

Originally posted by jbotello7381 August 23, 2022
I was playing with deployment and gitlab python library, and notice there's no method to approve or reject a deployment? i was able to do it via REST API from my python code, but not via the python wrapper. I'm using 3.8.1 of the gitlab python library.

So it looks like it is this API:
https://docs.gitlab.com/ee/api/deployments.html#approve-or-reject-a-blocked-deployment

And it doesn't look like there is any support for that yet in:
https://github.com/python-gitlab/python-gitlab/blob/main/gitlab/v4/objects/deployments.py

Implementing it will look similar to how the "approve" method is done for a merge request.

@cli.register_custom_action("ProjectMergeRequest", (), ("sha",))
@exc.on_http_error(exc.GitlabMRApprovalError)
def approve(self, sha: Optional[str] = None, **kwargs: Any) -> Dict[str, Any]:
"""Approve the merge request.
Args:
sha: Head SHA of MR
**kwargs: Extra options to send to the server (e.g. sudo)
Raises:
GitlabAuthenticationError: If authentication is not correct
GitlabMRApprovalError: If the approval failed
Returns:
A dict containing the result.
https://docs.gitlab.com/ee/api/merge_request_approvals.html#approve-merge-request
"""
path = f"{self.manager.path}/{self.encoded_id}/approve"
data = {}
if sha:
data["sha"] = sha
server_data = self.manager.gitlab.http_post(path, post_data=data, **kwargs)
if TYPE_CHECKING:
assert isinstance(server_data, dict)
self._update_attrs(server_data)
return server_data

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions