mirror of
https://github.com/frappe/bench.git
synced 2025-01-08 16:14:12 +00:00
perf: Using github API
This commit is contained in:
parent
de315f27ad
commit
b0ae3ae359
21
bench/app.py
21
bench/app.py
@ -215,17 +215,26 @@ class App(AppMeta):
|
||||
self.bench.run(f"{self.bench.python} -m pip uninstall -y {self.repo}")
|
||||
|
||||
def _get_dependencies(self):
|
||||
from bench.utils.app import get_required_deps_url
|
||||
from bench.utils.app import get_required_deps
|
||||
|
||||
required_url = get_required_deps_url(git_url=self.url, repo_name=self.repo, branch=self.tag)
|
||||
try:
|
||||
f = requests.get(required_url).text
|
||||
lines = [x for x in f.split("\n") if x.strip().startswith("required_apps")]
|
||||
required_apps = eval(lines[0].strip("required_apps").strip().lstrip("=").strip())
|
||||
return required_apps
|
||||
required_deps = get_required_deps(
|
||||
self.org, self.repo, self.tag or self.branch
|
||||
)
|
||||
lines = [
|
||||
x
|
||||
for x in required_deps.split("\n")
|
||||
if x.strip().startswith("required_apps")
|
||||
]
|
||||
required_apps = eval(
|
||||
lines[0].strip("required_apps").strip().lstrip("=").strip()
|
||||
)
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
return required_apps
|
||||
|
||||
|
||||
def make_resolution_plan(app: App, bench: "Bench"):
|
||||
"""
|
||||
decide what apps and versions to install and in what order
|
||||
|
@ -164,13 +164,15 @@ def get_current_branch(app, bench_path="."):
|
||||
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
||||
return get_cmd_output("basename $(git symbolic-ref -q HEAD)", cwd=repo_dir)
|
||||
|
||||
def get_required_deps_url(git_url, repo_name, branch, deps="hooks.py"):
|
||||
git_url = (
|
||||
git_url.replace(".git", "").replace("github.com", "raw.github.com")
|
||||
)
|
||||
branch = branch if branch else "develop"
|
||||
git_url += f"/{branch}/{repo_name}/{deps}"
|
||||
return git_url
|
||||
def get_required_deps(org, name, branch, deps="hooks.py"):
|
||||
import requests
|
||||
import base64
|
||||
|
||||
url = f"https://api.github.com/repos/{org}/{name}/contents/{name}/{deps}"
|
||||
params = {"branch": branch or "develop"}
|
||||
res = requests.get(url=url, params=params).json()
|
||||
return base64.decodebytes(res["content"].encode()).decode()
|
||||
|
||||
|
||||
def get_remote(app, bench_path="."):
|
||||
repo_dir = get_repo_dir(app, bench_path=bench_path)
|
||||
|
Loading…
Reference in New Issue
Block a user