Skip to content
Snippets Groups Projects
Verified Commit c2e4b4ce authored by Théo Pirkl's avatar Théo Pirkl :nail_care:
Browse files

Adds the possiblity to pull over HTTP (useful for private repos)

parent 8cf19539
Branches
No related tags found
No related merge requests found
Pipeline #15427 passed
pwm 100644 → 100755
...@@ -168,7 +168,7 @@ def get_projects(token: str, id: str, source: str = 'group') -> List: ...@@ -168,7 +168,7 @@ def get_projects(token: str, id: str, source: str = 'group') -> List:
return projects return projects
def clone_all(token: str, id: str, directory: str, until_date: Optional[str], source: str = 'group'): def clone_all(token: str, id: str, directory: str, until_date: Optional[str], source: str = 'group', use_http: bool = True):
""" """
Clone all repositories (from a group or "forks of") from id (group or Clone all repositories (from a group or "forks of") from id (group or
project id) in directory (created in function). project id) in directory (created in function).
...@@ -206,8 +206,14 @@ def clone_all(token: str, id: str, directory: str, until_date: Optional[str], so ...@@ -206,8 +206,14 @@ def clone_all(token: str, id: str, directory: str, until_date: Optional[str], so
print('Web url: ' + web_url) print('Web url: ' + web_url)
print('Cloning in "' + directory + '/' + repo_local_name + '"') print('Cloning in "' + directory + '/' + repo_local_name + '"')
subprocess.run(["git", "clone", "-q", ssh_url_to_repo, if use_http:
directory + '/' + repo_local_name]) subprocess.run(["git", "clone", "-q", ssh_url_to_repo,
directory + '/' + repo_local_name])
else:
url = "{}:{}@{}".format("gitlab-ci-token", token, BASE_URL)
subprocess.run(["git", "clone", "-q", web_url.replace(BASE_URL, url),
directory + '/' + repo_local_name])
if until_date: if until_date:
commit_id = subprocess.check_output([ commit_id = subprocess.check_output([
"git", "rev-list", "-n", "1", "--before=\"" + until_date + "\"", "git", "rev-list", "-n", "1", "--before=\"" + until_date + "\"",
...@@ -298,9 +304,9 @@ def command_clone_all(args): ...@@ -298,9 +304,9 @@ def command_clone_all(args):
""" """
if args.forks: if args.forks:
clone_all(args.token, args.id, args.directory, clone_all(args.token, args.id, args.directory,
args.until_date, 'forks') args.until_date, 'forks', args.use_http)
else: else:
clone_all(args.token, args.id, args.directory, args.until_date) clone_all(args.token, args.id, args.directory, args.until_date, args.use_http)
def command_list(args): def command_list(args):
...@@ -415,6 +421,7 @@ if __name__ == '__main__': ...@@ -415,6 +421,7 @@ if __name__ == '__main__':
"directory", metavar="DIRECTORY", help="Local directory where clone all repositories.") "directory", metavar="DIRECTORY", help="Local directory where clone all repositories.")
parser_clone.add_argument( parser_clone.add_argument(
"-u", "--until_date", help="Do a git checkout for all repositories at given date, format \"YYYY-MM-DD hh:mm\" (optional).") "-u", "--until_date", help="Do a git checkout for all repositories at given date, format \"YYYY-MM-DD hh:mm\" (optional).")
parser_clone.add_argument("--use_http", help="Use the HTTP client instead of SSH. False by default.", action='store_true')
parser_clone.set_defaults(func=command_clone_all) parser_clone.set_defaults(func=command_clone_all)
parser_list = subparsers.add_parser( parser_list = subparsers.add_parser(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment