Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gonchik committed Aug 16, 2023
2 parents 5df2d32 + 9226daa commit 749831e
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ '3.6', '3.7', '3.8', '3.9' ]
python-version: [ '3.6', '3.7', '3.8', '3.9', '3.11' ]

steps:
- uses: actions/checkout@v3
Expand Down
3 changes: 2 additions & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ include atlassian/VERSION
include LICENSE
include README.rst
include tox.ini
include requirements.txt
include requirements.txt
recursive-include tests *
43 changes: 43 additions & 0 deletions atlassian/bitbucket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1154,6 +1154,7 @@ def get_branches(
limit=None,
details=True,
order_by="MODIFICATION",
boost_matches=False,
):
"""
Retrieve the branches matching the supplied filterText param.
Expand All @@ -1167,6 +1168,7 @@ def get_branches(
fixed system limits. Default by built-in method: None
:param details: whether to retrieve plugin-provided metadata about each branch
:param order_by: OPTIONAL: ordering of refs either ALPHABETICAL (by name) or MODIFICATION (last updated)
:param boost_matches: Controls whether exact and prefix matches will be boosted to the top
:return:
"""
url = self._url_repo_branches(project_key, repository_slug)
Expand All @@ -1182,6 +1184,7 @@ def get_branches(
if order_by:
params["orderBy"] = order_by
params["details"] = details
params["boostMatches"] = boost_matches
return self._get_paged(url, params=params)

def _url_repo_default_branche(self, project_key, repository_slug):
Expand Down Expand Up @@ -1588,6 +1591,37 @@ def get_pull_requests(
params["at"] = at
return self._get_paged(url, params=params)

def get_required_reviewers_for_pull_request(
self, source_project, source_repo, dest_project, dest_repo, source_branch, dest_branch
):
"""
Get required reviewers for PR creation
:param source_project: the project that the PR source is from
:param source_repo: the repository that the PR source is from
:param source_branch: the branch name of the PR
:param dest_project: the project that the PR destination is from
:param dest_repo: the repository that the PR destination is from
:param dest_branch: where the PR is being merged into
:return:
"""
url = "{}/reviewers".format(
self._url_repo(
dest_project,
dest_repo,
api_root="rest/default-reviewers",
api_version="1.0",
)
)
source_repo_id = self.get_repo(source_project, source_repo)["id"]
dest_repo_id = self.get_repo(dest_project, dest_repo)["id"]
params = {
"sourceRepoId": source_repo_id,
"sourceRefId": source_branch,
"targetRepoId": dest_repo_id,
"targetRefId": dest_branch,
}
return self.get(url, params=params)

def open_pull_request(
self,
source_project,
Expand All @@ -1599,6 +1633,7 @@ def open_pull_request(
title,
description,
reviewers=None,
include_required_reviewers=False,
):
"""
Create a new pull request between two branches.
Expand All @@ -1614,6 +1649,7 @@ def open_pull_request(
:param title: the title of the PR
:param description: the description of what the PR does
:param reviewers: the list of reviewers or a single reviewer of the PR
:param include_required_reviewers: OPTIONAL defaults to False, include required reviewers for the PR
:return:
"""
body = {
Expand Down Expand Up @@ -1642,6 +1678,13 @@ def add_reviewer(reviewer_name):
entry = {"user": {"name": reviewer_name}}
body["reviewers"].append(entry)

if not self.cloud and include_required_reviewers:
required_reviewers = self.get_required_reviewers_for_pull_request(
source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch
)
for required_reviewer in required_reviewers:
add_reviewer(required_reviewer["name"])

if reviewers is not None:
if isinstance(reviewers, str):
add_reviewer(reviewers)
Expand Down
8 changes: 7 additions & 1 deletion docs/bitbucket.rst
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ Manage code
bitbucket.create_repo(project_key, repository, forkable=False, is_private=True)
# Get branches from repo
bitbucket.get_branches(project, repository, filter='', limit=99999, details=True)
bitbucket.get_branches(project, repository, filter='', limit=99999, details=True, boost_matches=False)
# Creates a branch using the information provided in the request.
# The authenticated user must have REPO_WRITE permission for the context repository to call this resource.
Expand All @@ -211,6 +211,9 @@ Manage code
# Reply to a comment of a pull request
bitbucket.add_pull_request_comment(project, repository, pull_request_id, text, parent_id=None)
# Get required reviewers for PR creation
bitbucket.get_required_reviewers_for_pull_request(source_project, source_repo, dest_project, dest_repo, source_branch, dest_branch)
# Create a new pull request between two branches.
bitbucket.open_pull_request(source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch, title, description)
Expand All @@ -220,6 +223,9 @@ Manage code
# Create a new pull request between two branches with multiple reviewers.
bitbucket.open_pull_request(source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch, title, description, reviewers=['name1', 'name2'])
# Create a new pull request between two branches with required reviewers.
bitbucket.open_pull_request(source_project, source_repo, dest_project, dest_repo, source_branch, destination_branch, title, description, include_required_reviewers=True)
# Delete a pull request
bitbucket.delete_pull_request(project, repository, pull_request_id, pull_request_version)
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
maintainer_email="[email protected]",
url="https://github.com/atlassian-api/atlassian-python-api",
keywords="atlassian jira core software confluence bitbucket bamboo crowd portfolio tempo servicedesk assets api",
packages=find_packages(include=["atlassian*", "tests*"]),
package_dir={"atlassian": "atlassian", "tests": "tests"},
packages=find_packages(include=["atlassian*"]),
package_dir={"atlassian": "atlassian"},
include_package_data=True,
zip_safe=False,
install_requires=["deprecated", "requests", "six", "oauthlib", "requests_oauthlib"],
Expand Down
5 changes: 3 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@ commands = black --check --diff {[base]linting_targets} --exclude __pycache__
[testenv:mypy]
basepython = python3
skip_install = true
deps = mypy == 0.812
commands = mypy atlassian/
deps =
mypy>=0.812
commands = mypy --install-types --non-interactive atlassian/

[testenv:bandit]
basepython = python3
Expand Down

0 comments on commit 749831e

Please sign in to comment.