Skip to content

Commit

Permalink
feat: alternative request to validate branch
Browse files Browse the repository at this point in the history
  • Loading branch information
saxenabhishek committed Mar 13, 2022
1 parent bb16b73 commit 8dd92c3
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions bench/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,22 @@ def is_frappe_app(directory: str) -> bool:


def is_valid_frappe_branch(frappe_path, frappe_branch):
if "http" in frappe_path:
if "http" in frappe_path and frappe_branch:
frappe_path = frappe_path.replace(".git", "")
try:
owner, repo = frappe_path.split("/")[3], frappe_path.split("/")[4]
except IndexError:
raise InvalidRemoteException
git_api = f"https://api.github.com/repos/{owner}/{repo}/branches"
res = requests.get(git_api).json()
if "message" in res or (frappe_branch and frappe_branch not in [x["name"] for x in res]):
git_api_req = f"https://api.github.com/repos/{owner}/{repo}/branches"
res = requests.get(git_api_req).json()

if "message" in res:
# slower alternative with no rate limit
github_req = f'https://github.com/{owner}/{repo}/tree/{frappe_branch}'
if requests.get(github_req).status_code != 200:
raise InvalidRemoteException

elif frappe_branch not in [x["name"] for x in res]:
raise InvalidRemoteException


Expand Down

0 comments on commit 8dd92c3

Please sign in to comment.