diff --git a/atlassian/bitbucket/__init__.py b/atlassian/bitbucket/__init__.py index 722257a7c..5dc1d4440 100644 --- a/atlassian/bitbucket/__init__.py +++ b/atlassian/bitbucket/__init__.py @@ -1,5 +1,7 @@ # coding=utf-8 import logging +from enum import Enum +from typing import Optional, Union from deprecated import deprecated from requests import HTTPError @@ -10,6 +12,16 @@ log = logging.getLogger(__name__) +class MergeStrategy(Enum): + """ + Merge strategies used by the merge_pull_request method. + """ + + MERGE_COMMIT = "merge_commit" + SQUASH = "squash" + FAST_FORWARD = "fast_forward" + + class Bitbucket(BitbucketBase): def __init__(self, url, *args, **kwargs): if "cloud" not in kwargs and ("bitbucket.org" in url): @@ -2194,7 +2206,16 @@ def is_pull_request_can_be_merged(self, project_key, repository_slug, pr_id): url = "{}/merge".format(self._url_pull_request(project_key, repository_slug, pr_id)) return self.get(url) - def merge_pull_request(self, project_key, repository_slug, pr_id, pr_version): + def merge_pull_request( + self, + project_key: str, + repository_slug: str, + pr_id: int, + pr_version: Optional[int], + merge_message: str, + close_source_branch: bool = False, + merge_strategy: Union[str, MergeStrategy] = MergeStrategy.MERGE_COMMIT, + ): """ Merge pull request The authenticated user must have REPO_READ permission for the repository @@ -2204,10 +2225,17 @@ def merge_pull_request(self, project_key, repository_slug, pr_id, pr_version): :param repository_slug: my_shiny_repo :param pr_id: 2341 :param pr_version: + :param merge_message: "feat: add new file handler" + :param close_source_branch: True + :param merge_strategy: "squash" :return: """ url = "{}/merge".format(self._url_pull_request(project_key, repository_slug, pr_id)) - params = {} + params = { + "message": merge_message, + "close_source_branch": close_source_branch, + "merge_strategy": MergeStrategy(merge_strategy).value, + } if not self.cloud: params["version"] = pr_version return self.post(url, params=params)