From 8dd92c32b1b9dc0f51e7fe1f1bfc7f9738dedbb8 Mon Sep 17 00:00:00 2001 From: saxenabhishek Date: Mon, 14 Mar 2022 05:17:08 +0530 Subject: [PATCH] feat: alternative request to validate branch --- bench/utils/__init__.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bench/utils/__init__.py b/bench/utils/__init__.py index ada125a82..84401203a 100644 --- a/bench/utils/__init__.py +++ b/bench/utils/__init__.py @@ -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