@@ -1591,6 +1591,37 @@ def get_pull_requests(
1591
1591
params ["at" ] = at
1592
1592
return self ._get_paged (url , params = params )
1593
1593
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
+
1594
1625
def open_pull_request (
1595
1626
self ,
1596
1627
source_project ,
@@ -1602,6 +1633,7 @@ def open_pull_request(
1602
1633
title ,
1603
1634
description ,
1604
1635
reviewers = None ,
1636
+ include_required_reviewers = False ,
1605
1637
):
1606
1638
"""
1607
1639
Create a new pull request between two branches.
@@ -1617,6 +1649,7 @@ def open_pull_request(
1617
1649
:param title: the title of the PR
1618
1650
:param description: the description of what the PR does
1619
1651
: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
1620
1653
:return:
1621
1654
"""
1622
1655
body = {
@@ -1645,6 +1678,13 @@ def add_reviewer(reviewer_name):
1645
1678
entry = {"user" : {"name" : reviewer_name }}
1646
1679
body ["reviewers" ].append (entry )
1647
1680
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
+
1648
1688
if reviewers is not None :
1649
1689
if isinstance (reviewers , str ):
1650
1690
add_reviewer (reviewers )
0 commit comments