@@ -1154,6 +1154,7 @@ def get_branches(
11541154 limit = None ,
11551155 details = True ,
11561156 order_by = "MODIFICATION" ,
1157+ boost_matches = False ,
11571158 ):
11581159 """
11591160 Retrieve the branches matching the supplied filterText param.
@@ -1167,6 +1168,7 @@ def get_branches(
11671168 fixed system limits. Default by built-in method: None
11681169 :param details: whether to retrieve plugin-provided metadata about each branch
11691170 :param order_by: OPTIONAL: ordering of refs either ALPHABETICAL (by name) or MODIFICATION (last updated)
1171+ :param boost_matches: Controls whether exact and prefix matches will be boosted to the top
11701172 :return:
11711173 """
11721174 url = self ._url_repo_branches (project_key , repository_slug )
@@ -1182,6 +1184,7 @@ def get_branches(
11821184 if order_by :
11831185 params ["orderBy" ] = order_by
11841186 params ["details" ] = details
1187+ params ["boostMatches" ] = boost_matches
11851188 return self ._get_paged (url , params = params )
11861189
11871190 def _url_repo_default_branche (self , project_key , repository_slug ):
@@ -1588,6 +1591,37 @@ def get_pull_requests(
15881591 params ["at" ] = at
15891592 return self ._get_paged (url , params = params )
15901593
1594+ def get_required_reviewers_for_pull_request (
1595+ self , source_project , source_repo , dest_project , dest_repo , source_branch , dest_branch
1596+ ):
1597+ """
1598+ Get required reviewers for PR creation
1599+ :param source_project: the project that the PR source is from
1600+ :param source_repo: the repository that the PR source is from
1601+ :param source_branch: the branch name of the PR
1602+ :param dest_project: the project that the PR destination is from
1603+ :param dest_repo: the repository that the PR destination is from
1604+ :param dest_branch: where the PR is being merged into
1605+ :return:
1606+ """
1607+ url = "{}/reviewers" .format (
1608+ self ._url_repo (
1609+ dest_project ,
1610+ dest_repo ,
1611+ api_root = "rest/default-reviewers" ,
1612+ api_version = "1.0" ,
1613+ )
1614+ )
1615+ source_repo_id = self .get_repo (source_project , source_repo )["id" ]
1616+ dest_repo_id = self .get_repo (dest_project , dest_repo )["id" ]
1617+ params = {
1618+ "sourceRepoId" : source_repo_id ,
1619+ "sourceRefId" : source_branch ,
1620+ "targetRepoId" : dest_repo_id ,
1621+ "targetRefId" : dest_branch ,
1622+ }
1623+ return self .get (url , params = params )
1624+
15911625 def open_pull_request (
15921626 self ,
15931627 source_project ,
@@ -1599,6 +1633,7 @@ def open_pull_request(
15991633 title ,
16001634 description ,
16011635 reviewers = None ,
1636+ include_required_reviewers = False ,
16021637 ):
16031638 """
16041639 Create a new pull request between two branches.
@@ -1614,6 +1649,7 @@ def open_pull_request(
16141649 :param title: the title of the PR
16151650 :param description: the description of what the PR does
16161651 :param reviewers: the list of reviewers or a single reviewer of the PR
1652+ :param include_required_reviewers: OPTIONAL defaults to False, include required reviewers for the PR
16171653 :return:
16181654 """
16191655 body = {
@@ -1642,6 +1678,13 @@ def add_reviewer(reviewer_name):
16421678 entry = {"user" : {"name" : reviewer_name }}
16431679 body ["reviewers" ].append (entry )
16441680
1681+ if not self .cloud and include_required_reviewers :
1682+ required_reviewers = self .get_required_reviewers_for_pull_request (
1683+ source_project , source_repo , dest_project , dest_repo , source_branch , destination_branch
1684+ )
1685+ for required_reviewer in required_reviewers :
1686+ add_reviewer (required_reviewer ["name" ])
1687+
16451688 if reviewers is not None :
16461689 if isinstance (reviewers , str ):
16471690 add_reviewer (reviewers )
0 commit comments