Skip to content

Commit

Permalink
[UP] To support SSH git and HTTPS
Browse files Browse the repository at this point in the history
  • Loading branch information
mostafabarmshory committed Feb 8, 2025
1 parent e81ba0a commit bd44584
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
13 changes: 9 additions & 4 deletions src/otoolbox/addons/repositories/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

_logger = logging.getLogger(__name__)

# GIT
GIT_ADDRESS_HTTPS = "https://github.com/{path}.git"
GIT_ADDRESS_SSH = "[email protected]:{path}.git"

GIT_ERROR_TABLE = {
2: {
'level': 'fatal',
Expand All @@ -18,6 +22,7 @@
}
}


def _rais_git_error(context, error_code):
if not error_code:
return
Expand All @@ -26,13 +31,13 @@ def _rais_git_error(context, error_code):
'message': "Unknown GIT error for distination path {path}. Error code is {error_code}. "
"See .otoolbox/logs.text for more information."
})
message = error['message'].format(error_code=error_code,**context.__dict__)
message = error['message'].format(error_code=error_code, **context.__dict__)
if env.context.get('continue_on_exception'):
_logger.error(message)
env.errors.append(message)
else:
raise RuntimeError(
error['message'].format(error_code=error_code,**context.__dict__)
error['message'].format(error_code=error_code, **context.__dict__)
)


Expand All @@ -48,13 +53,13 @@ def git_clone(context):
'clone',
'--branch', branch_name,
'--depth', depth,
f"[email protected]:{context.path}.git"
(GIT_ADDRESS_HTTPS if not env.context.get('ssh_git', False)
else GIT_ADDRESS_SSH).format(path=context.path),
], cwd=cwd)

_rais_git_error(context=context, error_code=result)



def git_pull(context):
"""Pull the git repository from github
"""
Expand Down
8 changes: 5 additions & 3 deletions src/otoolbox/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ def info():


@app.command()
def init():
def init(ssh_git: bool = False):
"""Initialize all resources from addons into the current workspace"""
env.context.update({
'ssh_git': ssh_git
})
return _filter_resources().build()


Expand All @@ -62,9 +65,8 @@ def list_repo():
console.print(table)



@app.command()
def add(organization:str, project:str, branch:str, title:str=None, description:str=None, tags:str=None):
def add(organization: str, project: str, branch: str, title: str = None, description: str = None, tags: str = None):
"""Add a new repository to the workspace"""
return _filter_resources().build()

Expand Down

0 comments on commit bd44584

Please sign in to comment.