@@ -234,6 +234,22 @@ def find_pull_request(listing, source):
234
234
return entry
235
235
236
236
237
+ def find_default_branch ():
238
+ """Find default branch for a repo (only called if branch not provided)
239
+ """
240
+ response = requests .get (REPO_URL )
241
+
242
+ # Case 1: 404 might need a token
243
+ if response .status_code == 404 :
244
+ response = requests .get (REPO_URL , headers = HEADERS )
245
+ if response .status_code != 200 :
246
+ abort_if_fail (response , "Unable to retrieve default branch" )
247
+
248
+ default_branch = response .json ()["default_branch" ]
249
+ print ("Found default branch: %s" % default_branch )
250
+ return default_branch
251
+
252
+
237
253
def add_reviewers (entry , reviewers , team_reviewers ):
238
254
"""Given regular or team reviewers, add them to a PR.
239
255
@@ -343,8 +359,8 @@ def main():
343
359
if not branch_prefix :
344
360
print ("No branch prefix is set, all branches will be used." )
345
361
346
- # Default to master to support older, will eventually change to main
347
- pull_request_branch = os .environ .get ("PULL_REQUEST_BRANCH" , "master" )
362
+ # Default to project default branch if none provided
363
+ pull_request_branch = os .environ .get ("PULL_REQUEST_BRANCH" , find_default_branch () )
348
364
print ("Pull requests will go to %s" % pull_request_branch )
349
365
350
366
# Pull request draft
0 commit comments