当前位置:网站首页>Python3 operating gitlab

Python3 operating gitlab

2020-11-06 22:38:00 Leaf blade

#coding=utf-8
import base64
# Import python-gitlab library 
import gitlab

url = 'http://192.168.x.xxx'
token = 'D98-t7HJpXxwhq8qbXcJ'

#  Sign in 
gl = gitlab.Gitlab(url, token)

# Get the project 
project = gl.projects.get('ZEP-BACKEND/ZEP-BACKEND-JAVA')
# obtain javademo/config Directory file list , Version is master
items = project.repository_tree(path='javademo', ref='master')

def get_all_files(path=None, ref='master'):
    items = project.repository_tree(path=path, ref=ref)
    for item in items:
        if item['mode'] == '040000':
            #  Call recursion , Achieve directory recursive output 
            get_all_files(item['path'], ref)
        if item['mode'] == '100644':
            print("===({})===".format(item['path']))

get_all_files(path='javademo', ref='master')

版权声明
本文为[Leaf blade]所创,转载请带上原文链接,感谢