Skip to content

Commit

Permalink
Bitbucket: update merge_pull_request method to add merge_message, clo…
Browse files Browse the repository at this point in the history
…se_source_branch and merge_strategy parameters (#1437)

Co-authored-by: Jorge Gómez Zarzosa <[email protected]>
  • Loading branch information
jorgegomzar and Jorge Gómez Zarzosa authored Jul 26, 2024
1 parent d08b7fb commit b76bcea
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions atlassian/bitbucket/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit b76bcea

Please sign in to comment.