mirror of
https://github.com/frappe/bench.git
synced 2025-01-24 15:38:25 +00:00
fix: Misc fixes (#1294)
* fix: use better api endpoint for is_valid_frappe_branch * fix: dont allow appnames starting with number and/or dot in them * fix: dont convert response to json * fix: using ls-remote to check for valid branches * refactor: changed the message displayed on invalid branch and invalid frappe path Co-authored-by: Aradhya <aradhyatripathi51@gmail.com> Co-authored-by: Aradhya Tripathi <67282231+Aradhya-Tripathi@users.noreply.github.com>
This commit is contained in:
parent
d4ae743d10
commit
eb715735bb
@ -486,6 +486,13 @@ def new_app(app, no_git=None, bench_path="."):
|
|||||||
|
|
||||||
# For backwards compatibility
|
# For backwards compatibility
|
||||||
app = app.lower().replace(" ", "_").replace("-", "_")
|
app = app.lower().replace(" ", "_").replace("-", "_")
|
||||||
|
if app[0].isdigit() or "." in app:
|
||||||
|
click.secho(
|
||||||
|
"App names cannot start with numbers(digits) or have dot(.) in them",
|
||||||
|
fg="red"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
apps = os.path.abspath(os.path.join(bench_path, "apps"))
|
apps = os.path.abspath(os.path.join(bench_path, "apps"))
|
||||||
args = ["make-app", apps, app]
|
args = ["make-app", apps, app]
|
||||||
if no_git:
|
if no_git:
|
||||||
|
@ -51,10 +51,9 @@ def is_frappe_app(directory: str) -> bool:
|
|||||||
|
|
||||||
|
|
||||||
def is_valid_frappe_branch(frappe_path:str, frappe_branch:str):
|
def is_valid_frappe_branch(frappe_path:str, frappe_branch:str):
|
||||||
""" Check if a branch exists in a repo. Throws InvalidRemoteException if branch is not found
|
"""Check if a branch exists in a repo. Throws InvalidRemoteException if branch is not found
|
||||||
|
|
||||||
Uses github's api without auth to query branch.
|
Uses native git command to check for branches on a remote.
|
||||||
If rate limited by gitapi, requests are sent to github.com
|
|
||||||
|
|
||||||
:param frappe_path: git url
|
:param frappe_path: git url
|
||||||
:type frappe_path: str
|
:type frappe_path: str
|
||||||
@ -62,23 +61,26 @@ def is_valid_frappe_branch(frappe_path:str, frappe_branch:str):
|
|||||||
:type frappe_branch: str
|
:type frappe_branch: str
|
||||||
:raises InvalidRemoteException: branch for this repo doesn't exist
|
:raises InvalidRemoteException: branch for this repo doesn't exist
|
||||||
"""
|
"""
|
||||||
if "http" in frappe_path and frappe_branch:
|
import subprocess
|
||||||
frappe_path = frappe_path.replace(".git", "")
|
|
||||||
|
if frappe_branch:
|
||||||
try:
|
try:
|
||||||
owner, repo = frappe_path.split("/")[3], frappe_path.split("/")[4]
|
ret = subprocess.check_output(
|
||||||
except IndexError:
|
(
|
||||||
raise InvalidRemoteException("Invalid git url")
|
"git",
|
||||||
git_api_req = f"https://api.github.com/repos/{owner}/{repo}/branches"
|
"ls-remote",
|
||||||
res = requests.get(git_api_req).json()
|
"--heads",
|
||||||
|
frappe_path,
|
||||||
if "message" in res:
|
frappe_branch,
|
||||||
# slower alternative with no rate limit
|
),
|
||||||
github_req = f'https://github.com/{owner}/{repo}/tree/{frappe_branch}'
|
encoding="UTF-8",
|
||||||
if requests.get(github_req).status_code != 200:
|
)
|
||||||
raise InvalidRemoteException("Invalid git url")
|
if not ret:
|
||||||
|
raise InvalidRemoteException(
|
||||||
elif frappe_branch not in [x["name"] for x in res]:
|
f"Invalid {frappe_branch} for the remote {frappe_path}"
|
||||||
raise InvalidRemoteException("Frappe branch does not exist")
|
)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
raise InvalidRemoteException(f"Invalid frappe path {frappe_path}")
|
||||||
|
|
||||||
|
|
||||||
def log(message, level=0, no_log=False):
|
def log(message, level=0, no_log=False):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user