赞
踩
批量拉取gitlab上自己可访问的项目
路径:右上角头像 - profile settings - access tokens
import json import subprocess import shlex token = 'xxxx' //这里是gitlab上自己的token值 api_url = 'xxx' //贵司的gitlab地址 page = 1 //起始页码 url = api_url + '/api/v3/projects?private_token=' + token + '&per_page=100&page=' while True: cur = ("%s%s") % (url, str(page)) //拼接当前页url r = requests.get(url) //请求 data = r.json() if len(data) >= 0: //有记录则clone for i in data: pd = i['ssh_url_to_repo'] ret = subprocess.Popen(shlex.split('git clone {}'.format(pd)), shell=False, stdout=None) page = page + 1 //请求下一页 else: break
可根据自己需要的信息选择
{ 'id': 1915186, 'description': '这里是描述', 'default_branch': 'main', 'tag_list': [], 'public': False, 'archived': False, 'visibility_level': 0, 'ssh_url_to_repo': 'git@xxx.git', //clone地址 'http_url_to_repo': 'https://xxx.git', //下载地址 'web_url': 'https://xxxxx', 'name': 'abc', 'name_with_namespace': 'prefix / abc', 'path': 'abc', 'path_with_namespace': 'prefix/abc', 'container_registry_enabled': True, 'issues_enabled': True, 'merge_requests_enabled': True, 'wiki_enabled': True, 'builds_enabled': True,0 'snippets_enabled': False, 'created_at': '2020-11-01T11:44:57.000+08:00', 'last_activity_at': '2020-11-01T18:03:18.000+08:00', 'shared_runners_enabled': True, 'lfs_enabled': True, 'creator_id': 100001, 'namespace': { 'id': 5219, 'name': 'xxxx', 'path': 'xxxx', 'owner_id': None, 'created_at': '2020-11-01T11:05:06.000+08:00', 'updated_at': '2020-11-01T11:05:06.000+08:00', 'description': '', 'avatar': { 'url': None }, 'share_with_group_lock': False, 'visibility_level': 0, 'request_access_enabled': False, 'deleted_at': None, 'lfs_enabled': None, 'parent_id': None }, 'avatar_url': None, 'star_count': 0, 'forks_count': 0, 'open_issues_count': 0, 'public_builds': True, 'shared_with_groups': [], 'only_allow_merge_if_build_succeeds': False, 'request_access_enabled': False, 'only_allow_merge_if_all_discussions_are_resolved': False, 'permissions': { 'project_access': None, 'group_access': { 'access_level': 40, 'notification_level': 3 } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。