安装:pip install python-gitlab
import gitlab # 登录 gl = gitlab.Gitlab('http://127.0.0.1', private_token='JVNSESs8EwWRx5yDxM5q') # 列出所有的项目 projects = gl.projects.list() for project in projects: print(project) # 通过id获取项目 project = gl.projects.get(1) print(project.name,project.id,project.attributes) issues = project.issues.list() print(issues) # 列出所有的组 all_groups = gl.groups.list(all=True) for group in all_groups: print(group.name,group.id) #获取某文件的内容: f = project.files.get(file_path='src/README.rst', ref='master')
content_base = base64.b64decode(f.content)
content = str(content_base, 'utf-8')
}
参考:http://python-gitlab.readthedocs.io/en/stable/cli.html