python-gitlab 模块

 安装:pip install python-gitlab

import gitlab
import base64
# 登录 gl = gitlab.Gitlab('http://127.0.0.1', private_token='JVNSESs8EwWRx5yDxM5q') # 列出所有的项目 projects = gl.projects.list(all=True) 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')
respsons: { "file_name": "key.rb", "file_path": "app/models/key.rb", "size": 1476, "encoding": "base64", "content": "IyA9PSBTY2hlbWEgSW5mb3...", "content_sha256": "4c294617b60715c1d218e61164a3abd4808a4284cbc30e6728a01ad9aada4481", "ref": "master", "blob_id": "79f7bbd25901e8334750839545a9bd021f0e4c83", "commit_id": "d5a3ff139356ce33e37e73add446f16869741b50", "last_commit_id": "570e7b2abdd848b95f2f578043fc23bd6f6fd24d" }

 参考:http://python-gitlab.readthedocs.io/en/stable/cli.html 

posted on 2018-08-10 14:13  蜗牛也是妞  阅读(1629)  评论(0编辑  收藏  举报