Last active
November 16, 2018 01:52
-
-
Save naderghanbari/d542ef7404235d25811ae6cc484e1edd to your computer and use it in GitHub Desktop.
Revisions
-
naderghanbari revised this gist
Nov 16, 2018 . No changes.There are no files selected for viewing
-
naderghanbari renamed this gist
Nov 16, 2018 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ #!/usr/bin/env python3 # Usage: ./gitlab_group_checkout_all.py -g group_name -d target_dir # Assumes there is a default configuration and python-gitlab is installed # https://python-gitlab.readthedocs.io/en/stable/cli.html#cli-configuration -
naderghanbari created this gist
Nov 16, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,46 @@ #!/usr/bin/env python3 # Usage: ./checkout_all -g group_name -d target_dir # Assumes there is a default configuration and python-gitlab is installed # https://python-gitlab.readthedocs.io/en/stable/cli.html#cli-configuration # Work with GitLab API V4 (gitlab-python version 1.6.x) import getopt, shlex, subprocess, sys, gitlab def clone_all_repos(group_name, directory): gl = gitlab.Gitlab.from_config() groups = gl.groups group_id = next(x.id for x in groups.list(as_list=False) if x.name == group_name) group = groups.get(group_id) projects = group.projects.list(as_list=False) clone_urls = (project.ssh_url_to_repo for project in projects) for clone_url in clone_urls: clone_repo(clone_url, directory) def clone_repo(clone_url, directory): try: command = shlex.split('git clone %s' % clone_url) return subprocess.Popen(command, cwd=directory) except Exception as e: print("Error on %s: %s" % (clone_url, e)) return 1 def main(argv): group_name = '' directory = '' try: opts, args = getopt.getopt(argv, "g:d:", ["group=", "dir="]) except getopt.GetoptError: print('tlm.py -g group -d dir') sys.exit(2) for opt, arg in opts: if opt in ("-g", "--group"): group_name = arg elif opt in ("-d", "--dir"): directory = arg clone_all_repos(group_name, directory) if __name__ == "__main__": main(sys.argv[1:])