2
0
mirror of https://github.com/frappe/bench.git synced 2024-11-12 08:16:28 +00:00

Merge branch 'fixes' of github.com:Aradhya-Tripathi/bench into fixes

This commit is contained in:
Aradhya 2022-05-05 19:59:21 +05:30
commit 949e51a943
4 changed files with 33 additions and 35 deletions

View File

@ -60,21 +60,6 @@ matrix:
env: TEST=bench
script: python -m unittest -v bench.tests.test_utils && python -m unittest -v bench.tests.test_init
- name: "Python 3.7 Easy Install"
python: 3.7
env: TEST=easy_install
script: sudo python $TRAVIS_BUILD_DIR/install.py --user travis --run-travis --production --verbose
- name: "Python 3.8 Easy Install"
python: 3.8
env: TEST=easy_install
script: sudo python $TRAVIS_BUILD_DIR/install.py --user travis --run-travis --production --verbose
- name: "Python 3.9 Easy Install"
python: 3.9
env: TEST=easy_install
script: sudo python $TRAVIS_BUILD_DIR/install.py --user travis --run-travis --production --verbose
install:
- pip3 install urllib3 pyOpenSSL ndg-httpsclient pyasn1

View File

@ -115,7 +115,7 @@ class AppMeta:
name = url if url else self.name
if name.startswith("git@") or name.startswith("ssh://"):
self.use_ssh = True
_first_part, _second_part = name.split(":")
_first_part, _second_part = self.name.rsplit(":", 1)
self.remote_server = _first_part.split("@")[-1]
self.org, _repo = _second_part.rsplit("/", 1)
else:
@ -485,6 +485,13 @@ def new_app(app, no_git=None, bench_path="."):
# For backwards compatibility
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"))
args = ["make-app", apps, app]
if no_git:

View File

@ -73,3 +73,7 @@ class TestUtils(unittest.TestCase):
self.assertEqual("11.0", fake_bench.apps.states["frappe"]["version"])
shutil.rmtree(bench_dir)
def test_ssh_ports(self):
app = App("git@github.com:22:frappe/frappe")
self.assertEqual((app.use_ssh, app.org, app.repo), (True, "frappe", "frappe"))

View File

@ -51,10 +51,9 @@ def is_frappe_app(directory: str) -> bool:
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.
If rate limited by gitapi, requests are sent to github.com
Uses native git command to check for branches on a remote.
:param frappe_path: git url
:type frappe_path: str
@ -62,23 +61,26 @@ def is_valid_frappe_branch(frappe_path:str, frappe_branch:str):
:type frappe_branch: str
:raises InvalidRemoteException: branch for this repo doesn't exist
"""
if "http" in frappe_path and frappe_branch:
frappe_path = frappe_path.replace(".git", "")
import subprocess
if frappe_branch:
try:
owner, repo = frappe_path.split("/")[3], frappe_path.split("/")[4]
except IndexError:
raise InvalidRemoteException("Invalid git url")
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("Invalid git url")
elif frappe_branch not in [x["name"] for x in res]:
raise InvalidRemoteException("Frappe branch does not exist")
ret = subprocess.check_output(
(
"git",
"ls-remote",
"--heads",
frappe_path,
frappe_branch,
),
encoding="UTF-8",
)
if not ret:
raise InvalidRemoteException(
f"Invalid {frappe_branch} for the remote {frappe_path}"
)
except subprocess.CalledProcessError:
raise InvalidRemoteException(f"Invalid frappe path {frappe_path}")
def log(message, level=0, no_log=False):