Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save zh4n7wm/e9876805068018b30f9ae4b5c51d2499 to your computer and use it in GitHub Desktop.
Save zh4n7wm/e9876805068018b30f9ae4b5c51d2499 to your computer and use it in GitHub Desktop.
import requests
import sys
import os
import json
MAX_PAGE = 10
if __name__ == "__main__":
'''https://<your_gitlab_site_address>/profile/personal_access_tokens'''
git_urls = []
if len(sys.argv) != 3:
print("Usage {} <gitlab_site> <token>".format(sys.argv[0]))
exit(-1)
gitlab_site = sys.argv[1]
private_token = sys.argv[2]
for i in range(0, MAX_PAGE):
url = '{}/api/v3/projects?private_token={}&per_page=200&page={}' \
.format( gitlab_site, private_token, i)
r = requests.get(url)
items = r.json()
if len(items) > 0:
for item in items:
with open(item['name'] + ".json", "w") as meta_file:
meta_file.write(json.dumps(item, indent=2))
git_url = item['ssh_url_to_repo']
git_urls.append(git_url)
for git_url in git_urls:
os.system('git clone ' + git_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment