| 
1 | 1 | from app.config import app_config  | 
2 | 2 | from app.helpers import azuredevops  | 
3 | 3 | from app.helpers import github  | 
 | 4 | +from app.helpers.git import get_default_branch_name  | 
4 | 5 | 
 
  | 
5 | 6 | from azure.devops.credentials import BasicAuthentication  | 
6 | 7 | from azure.devops.v7_0.git import GitPullRequest  | 
@@ -51,7 +52,14 @@ def is_open_pull_requests(repo: Repo, pull_request_config: dict[str, dict[str, A  | 
51 | 52 | 
 
  | 
52 | 53 |             source_ref_name = f"refs/heads/{  | 
53 | 54 |                 repo.active_branch.name}"  | 
54 |  | -            target_ref_name: str = pull_request_payload['targetRefName']  | 
 | 55 | +            target_ref_name: str = pull_request_payload.get(  | 
 | 56 | +                'targetRefName', None)  | 
 | 57 | + | 
 | 58 | +            if not target_ref_name:  | 
 | 59 | +                default_branch_name = get_default_branch_name(repo=repo)  | 
 | 60 | +                _logger.info(f"Setting targetRefName to the default branch '{  | 
 | 61 | +                             default_branch_name}'")  | 
 | 62 | +                target_ref_name = default_branch_name  | 
55 | 63 | 
 
  | 
56 | 64 |             if not target_ref_name.startswith("refs/heads/"):  | 
57 | 65 |                 _logger.debug(  | 
@@ -104,7 +112,13 @@ def is_open_pull_requests(repo: Repo, pull_request_config: dict[str, dict[str, A  | 
104 | 112 | 
 
  | 
105 | 113 |             head_ref = f"refs/heads/{  | 
106 | 114 |                 repo.active_branch.name}"  | 
107 |  | -            base_ref: str = pull_request_payload['base']  | 
 | 115 | +            base_ref: str = pull_request_payload.get('base', None)  | 
 | 116 | + | 
 | 117 | +            if not base_ref:  | 
 | 118 | +                default_branch_name = get_default_branch_name(repo=repo)  | 
 | 119 | +                _logger.info(f"Setting base to the default branch '{  | 
 | 120 | +                             default_branch_name}'")  | 
 | 121 | +                base_ref = default_branch_name  | 
108 | 122 | 
 
  | 
109 | 123 |             if not base_ref.startswith("refs/heads/"):  | 
110 | 124 |                 _logger.debug(  | 
@@ -214,7 +228,14 @@ def raise_pull_request(repo: Repo, pull_request_config: dict[str, dict[str, Any]  | 
214 | 228 |                 pull_request_payload.get('description', []))  | 
215 | 229 |             pull_request_payload['sourceRefName'] = f"refs/heads/{  | 
216 | 230 |                 repo.active_branch.name}"  | 
217 |  | -            target_ref_name: str = pull_request_payload['targetRefName']  | 
 | 231 | +            target_ref_name: str = pull_request_payload.get(  | 
 | 232 | +                'targetRefName', None)  | 
 | 233 | + | 
 | 234 | +            if not target_ref_name:  | 
 | 235 | +                default_branch_name = get_default_branch_name(repo=repo)  | 
 | 236 | +                _logger.info(f"Setting targetRefName to the default branch '{  | 
 | 237 | +                             default_branch_name}'")  | 
 | 238 | +                target_ref_name = default_branch_name  | 
218 | 239 | 
 
  | 
219 | 240 |             if not target_ref_name.startswith("refs/heads/"):  | 
220 | 241 |                 _logger.debug(  | 
@@ -257,7 +278,13 @@ def raise_pull_request(repo: Repo, pull_request_config: dict[str, dict[str, Any]  | 
257 | 278 |                 pull_request_payload.get('body', []))  | 
258 | 279 |             pull_request_payload['head'] = f"refs/heads/{  | 
259 | 280 |                 repo.active_branch.name}"  | 
260 |  | -            base_ref: str = pull_request_payload['base']  | 
 | 281 | +            base_ref: str = pull_request_payload.get('base', None)  | 
 | 282 | + | 
 | 283 | +            if not base_ref:  | 
 | 284 | +                default_branch_name = get_default_branch_name(repo=repo)  | 
 | 285 | +                _logger.info(f"Setting base to the default branch '{  | 
 | 286 | +                             default_branch_name}'")  | 
 | 287 | +                base_ref = default_branch_name  | 
261 | 288 | 
 
  | 
262 | 289 |             if not base_ref.startswith("refs/heads/"):  | 
263 | 290 |                 _logger.debug(  | 
 | 
0 commit comments