Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitbucket: update merge_pull_request method to add merge_message, close_source_branch and merge_strategy parameters #1437

Merged
merged 1 commit into from
Jul 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
: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 = {

Check warning on line 2234 in atlassian/bitbucket/__init__.py

View check run for this annotation

Codecov / codecov/patch

atlassian/bitbucket/__init__.py#L2234

Added line #L2234 was not covered by tests
"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