Skip to content

Commit

Permalink
feat: add git-host and use-ssh option to get-app command for using na…
Browse files Browse the repository at this point in the history
…me tag format

currently only github and gitlab are supported as git hosts via the git-host option
  • Loading branch information
phot0n committed Dec 13, 2021
1 parent 0423cb0 commit 555b33d
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 5 deletions.
22 changes: 18 additions & 4 deletions bench/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@


class AppMeta:
def __init__(self, name: str, branch: str = None, to_clone: bool = True):
def __init__(
self,
name: str,
branch: str = None,
host: str = None,
to_clone: bool = True,
use_ssh: bool = False
):
"""
name (str): This could look something like
1. https://github.com/frappe/healthcare.git
Expand All @@ -63,9 +70,10 @@ class Healthcare(AppConfig):
self.to_clone = to_clone
# NOTE: keeping this here in lieu of:
# https://github.com/frappe/bench/pull/1233#discussion_r766489037
self.remote_git_host = "github.com"
self.on_disk = False
self.from_name_tag = False
self.remote_git_host_for_name_tag = host
self.use_ssh_for_name_tag = use_ssh
self.from_apps = False
self.branch = branch
self.setup_details()
Expand Down Expand Up @@ -119,14 +127,18 @@ def url(self):
return os.path.abspath(self.name)

if self.from_name_tag:
if self.use_ssh_for_name_tag:
return self.get_ssh_url()
return self.get_http_url()

# return the git url when it's valid
return self.name

def get_http_url(self):
return f"https://{self.remote_git_host}/{self.org}/{self.repo}.git"
return f"https://{self.remote_git_host_for_name_tag}.com/{self.org}/{self.repo}.git"

def get_ssh_url(self):
return f"git@{self.remote_git_host_for_name_tag}.com:{self.org}/{self.repo}.git"

@functools.lru_cache(maxsize=None)
class App(AppMeta):
Expand Down Expand Up @@ -275,6 +287,8 @@ def setup_app_dependencies(

def get_app(
git_url,
git_host=None,
use_ssh=False,
branch=None,
bench_path=".",
skip_assets=False,
Expand All @@ -294,7 +308,7 @@ def get_app(
import bench.cli as bench_cli

bench = Bench(bench_path)
app = App(git_url, branch=branch, bench=bench)
app = App(git_url, branch=branch, bench=bench, host=git_host, use_ssh=use_ssh)
git_url = app.url
repo_name = app.repo
branch = app.tag
Expand Down
20 changes: 19 additions & 1 deletion bench/commands/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,24 @@ def drop(path):
@click.option(
"--init-bench", is_flag=True, default=False, help="Initialize Bench if not in one"
)
@click.option(
"--use-ssh", is_flag=True, default=False, help="Use SSH when using name-tag format"
)
@click.option(
"--git-host",
type=click.Choice(["github", "gitlab"], case_sensitive=False),
default="github",
help="Git remote server from where to fetch the app (to be used with name-tag format)"
)
def get_app(
git_url, branch, name=None, overwrite=False, skip_assets=False, init_bench=False
git_url,
branch,
name=None,
git_host=None,
overwrite=False,
skip_assets=False,
init_bench=False,
use_ssh=False,
):
"clone an app from the internet and set it up in your bench"
from bench.app import get_app
Expand All @@ -145,6 +161,8 @@ def get_app(
skip_assets=skip_assets,
overwrite=overwrite,
init_bench=init_bench,
git_host=git_host,
use_ssh=use_ssh
)


Expand Down

0 comments on commit 555b33d

Please sign in to comment.