@@ -62,6 +62,27 @@ def convert_to(output_type, value):
6262 return result , "OK"
6363
6464
65+ def parse_git_url (git_url ):
66+ """Parse the git url.
67+
68+ Args:
69+ git_url (str): url of a git repository (https or ssh)
70+
71+ Returns:
72+ (str, str, str): tupple of domain, user and project name parsed from url
73+ """
74+ import re
75+ regex = re .compile (r'(?:git@|https:\/\/)' # Prefix
76+ r'([\w\-_\.]+)' # Domain
77+ r'[:\/]' # Separator : or /
78+ r'([\w\-_\.\/]+)' # User or folders
79+ r'[\/]' # Separator /
80+ r'([\w\-_]+)' # Project name
81+ r'(?:.git)*$' ) # .git or nothing
82+ domain , user , project = regex .search (git_url ).groups ()
83+ return domain , user , project
84+
85+
6586class CmdResult :
6687 """A small container for command result."""
6788 SUCCESS = 0
@@ -153,7 +174,7 @@ def run_command(command, shell=True, cwd=path.curdir, env=environ, timeout=20):
153174 return CmdResult (returncode = 1 , stderr = output_text )
154175
155176
156- def __run_subprocess (* popenargs ,
177+ def __run_subprocess (command ,
157178 input = None ,
158179 timeout = None ,
159180 check = False ,
@@ -178,7 +199,7 @@ def __run_subprocess(*popenargs,
178199 import signal
179200 from subprocess import Popen , TimeoutExpired , CalledProcessError
180201 from subprocess import CompletedProcess
181- with Popen (* popenargs , preexec_fn = os .setsid , ** kwargs ) as process :
202+ with Popen (command , preexec_fn = os .setsid , ** kwargs ) as process :
182203 try :
183204 stdout , stderr = process .communicate (input , timeout = timeout )
184205 except TimeoutExpired :
0 commit comments