Last active
August 16, 2020 10:05
-
-
Save maxgalbu/995a42a9a4e8594b4a628df93985fc2f to your computer and use it in GitHub Desktop.
Updated API version + Python 2 version of https://stackoverflow.com/a/34469893/2265500
This file contains 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 characters
import os | |
import errno | |
from subprocess import call | |
from gitlab import Gitlab | |
def mkdir_p(path): | |
try: | |
os.makedirs(path) | |
except OSError as exc: # Python >2.5 | |
if exc.errno == errno.EEXIST and os.path.isdir(path): | |
pass | |
else: | |
raise | |
# Register a connection to a gitlab instance, using its URL and a user private token | |
gl = Gitlab('http://gitlab.example.com', 'dasidIOsOJISI092812ihas') | |
groupsToSkip = ['youDontWantThisGroup'] | |
gl.auth() # Connect to get the current user | |
gitBasePathRelative = "git/" | |
gitBasePathRelativeAbsolut = os.path.expanduser("~/" + gitBasePathRelative) | |
mkdir_p(gitBasePathRelativeAbsolut) | |
for p in gl.projects.list(all=True): | |
if not any(p.namespace.path in s for s in groupsToSkip): | |
pathToFolder = gitBasePathRelative + p.namespace.name + "/" + p.name | |
commandArray = ["mr", "config", pathToFolder, "checkout=git clone '" + p.ssh_url_to_repo + "' '" + p.name + "'"] | |
call(commandArray) | |
os.chdir(gitBasePathRelativeAbsolut) | |
call(["mr", "update"]) |
This file contains 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 characters
import os | |
from subprocess import call | |
from gitlab import Gitlab | |
# Register a connection to a gitlab instance, using its URL and a user private token | |
gl = Gitlab('http://gitlab.example.com', 'dasidIOsOJISI092812ihas') | |
groupsToSkip = ['youDontWantThisGroup'] | |
gl.auth() # Connect to get the current user | |
gitBasePathRelative = "git/" | |
gitBasePathRelativeAbsolut = os.path.expanduser("~/" + gitBasePathRelative) | |
os.makedirs(gitBasePathRelativeAbsolut,exist_ok=True) | |
for p in gl.projects.list(all=True): | |
if not any(p.namespace.path in s for s in groupsToSkip): | |
pathToFolder = gitBasePathRelative + p.namespace.name + "/" + p.name | |
commandArray = ["mr", "config", pathToFolder, "checkout=git clone '" + p.ssh_url_to_repo + "' '" + p.name + "'"] | |
call(commandArray) | |
os.chdir(gitBasePathRelativeAbsolut) | |
call(["mr", "update"]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment