python爬取git上有權(quán)限訪問(wèn)的代碼

Gitlab權(quán)限管理

Gitlab權(quán)限管理

Gitlab用戶(hù)在組中有五種權(quán)限:
Guest、Reporter、Developer、Master、Owner

  • Guest:可以創(chuàng)建issue、發(fā)表評(píng)論,不能讀寫(xiě)版本庫(kù)
  • Reporter:可以克隆代碼,不能提交,QA、PM可以賦予這個(gè)權(quán)限
  • Developer:可以克隆代碼、開(kāi)發(fā)、提交、push,RD可以賦予這個(gè)權(quán)限
  • Master:可以創(chuàng)建項(xiàng)目、添加tag、保護(hù)分支、添加項(xiàng)目成員、編輯項(xiàng)目,核心RD負(fù)責(zé)人可以賦予這個(gè)權(quán)限
  • Owner:可以設(shè)置項(xiàng)目訪問(wèn)權(quán)限 - Visibility Level、刪除項(xiàng)目、遷移項(xiàng)目、管理組成員,開(kāi)發(fā)組leader可以賦予這個(gè)權(quán)限
    Gitlab中的組和項(xiàng)目有三種訪問(wèn)權(quán)限:Private、Internal、Public

Visibility Level

  • Private:只有組成員才能看到
  • Internal:只要登錄的用戶(hù)就能看到
  • Public:所有人都能看到

開(kāi)源項(xiàng)目和組設(shè)置的是Internal

批量導(dǎo)出所有項(xiàng)目

# -*- coding: UTF-8 -*-
 
# 在Python3.0測(cè)試通過(guò)
# 需要在gitlab里面新建一個(gè)AccessToken填入gitlabToken
 
import sys
if sys.version_info < (3, 0):
    import urllib
else:
    from urllib.request import urlopen
 
import json
import subprocess, shlex
import time
import os
 
gitlabAddr  = '192.168.20.15:9222'
# gitlabToken獲取
gitlabToken = 'G2FQENzmN_fjPF2RAJtb'
 
for index in range(10):
    url= "http://%s/api/v4/projects?private_token=%s&per_page=100&page=%d&order_by=name" % (gitlabAddr, gitlabToken, index)
    print(url)
    
    if sys.version_info < (3, 0):
        allProjects = urllib.urlopen(url)
    else:
        allProjects = urlopen(url)
        
    allProjectsDict = json.loads(allProjects.read().decode(encoding='UTF-8'))
    if len(allProjectsDict) == 0:
        break
    for thisProject in allProjectsDict: 
        try:
            thisProjectURL  = thisProject['http_url_to_repo']
            thisProjectPath = thisProject['path_with_namespace']
            print(thisProjectURL + ' ' + thisProjectPath)
            
            if os.path.exists(thisProjectPath):
                command     = shlex.split('git -C "%s" pull' % (thisProjectPath))
            else:
                command     = shlex.split('git clone %s %s' % (thisProjectURL, thisProjectPath))
            
            resultCode  = subprocess.Popen(command)
            time.sleep(0.5)
        except Exception as e:
            print("Error on %s: %s" % (thisProjectURL, e.strerror))

gitlabToken獲取

image-20220323133710235.png
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容