Skip to content

Commit c0bf768

Browse files
committed
Use repo's default branch if no branch specified
1 parent 1cb1956 commit c0bf768

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

pull-request.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,22 @@ def find_pull_request(listing, source):
234234
return entry
235235

236236

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+
237253
def add_reviewers(entry, reviewers, team_reviewers):
238254
"""Given regular or team reviewers, add them to a PR.
239255
@@ -343,8 +359,8 @@ def main():
343359
if not branch_prefix:
344360
print("No branch prefix is set, all branches will be used.")
345361

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())
348364
print("Pull requests will go to %s" % pull_request_branch)
349365

350366
# Pull request draft

0 commit comments

Comments
 (0)