Skip to content

Commit

Permalink
Merge pull request #75 from Kong/feat/discover-default-branch
Browse files Browse the repository at this point in the history
Use repo's default branch if no branch specified
  • Loading branch information
vsoch authored Jun 21, 2021
2 parents 1cb1956 + c0bf768 commit 29dbfc0
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions pull-request.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,22 @@ def find_pull_request(listing, source):
return entry


def find_default_branch():
"""Find default branch for a repo (only called if branch not provided)
"""
response = requests.get(REPO_URL)

# Case 1: 404 might need a token
if response.status_code == 404:
response = requests.get(REPO_URL, headers=HEADERS)
if response.status_code != 200:
abort_if_fail(response, "Unable to retrieve default branch")

default_branch = response.json()["default_branch"]
print("Found default branch: %s" % default_branch)
return default_branch


def add_reviewers(entry, reviewers, team_reviewers):
"""Given regular or team reviewers, add them to a PR.
Expand Down Expand Up @@ -343,8 +359,8 @@ def main():
if not branch_prefix:
print("No branch prefix is set, all branches will be used.")

# Default to master to support older, will eventually change to main
pull_request_branch = os.environ.get("PULL_REQUEST_BRANCH", "master")
# Default to project default branch if none provided
pull_request_branch = os.environ.get("PULL_REQUEST_BRANCH", find_default_branch())
print("Pull requests will go to %s" % pull_request_branch)

# Pull request draft
Expand Down

0 comments on commit 29dbfc0

Please sign in to comment.