From b76bcea2c9550a0d3e96464f62b2483a3af36dd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20G=C3=B3mez=20Zarzosa?= <34076979+jorgegomzar@users.noreply.github.com> Date: Fri, 26 Jul 2024 09:57:04 +0200 Subject: [PATCH] Bitbucket: update merge_pull_request method to add merge_message, close_source_branch and merge_strategy parameters (#1437) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Jorge Gómez Zarzosa --- atlassian/bitbucket/__init__.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) 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)