diff --git a/pwm b/pwm old mode 100644 new mode 100755 index 73ed9e902f1c2b6cc09dc020ea8de1d321b37a7f..d51ca87c1a7eb0912698cd3d6dc68147248f579a --- a/pwm +++ b/pwm @@ -168,7 +168,7 @@ def get_projects(token: str, id: str, source: str = 'group') -> List: 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 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 print('Web url: ' + web_url) print('Cloning in "' + directory + '/' + repo_local_name + '"') - subprocess.run(["git", "clone", "-q", ssh_url_to_repo, - directory + '/' + repo_local_name]) + if use_http: + 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: commit_id = subprocess.check_output([ "git", "rev-list", "-n", "1", "--before=\"" + until_date + "\"", @@ -298,9 +304,9 @@ def command_clone_all(args): """ if args.forks: clone_all(args.token, args.id, args.directory, - args.until_date, 'forks') + args.until_date, 'forks', args.use_http) 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): @@ -415,6 +421,7 @@ if __name__ == '__main__': "directory", metavar="DIRECTORY", help="Local directory where clone all repositories.") 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).") + 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_list = subparsers.add_parser(