module:gitlab,git
获取gitlab的操作对象
_gl = gitlab.Gitlab("http://gitlab.com", private_token="GIEYANLB_WY")
通过projectid获取仓库的操作对象:
proj = _gl.projects.get(gl_proj_id)
#proj 的各种属性
pro_kind = proj.namespace['kind']
获取本地仓库对象
repo = git.Repo(os.curdir)
拿到仓库的commit对象
#commit的byte
lastest_binsha = bytes.fromhex(latest_commit_sha)
latest_commit = git.objects.Commit(repo, lastest_binsha)
#最后commit对象的之前commit对象
parent_commits = latest_commit.iter_parents()
拿到commit对象的父commit
commit.parents
区别于commit.iter_parents(),parent属性:当merge提交时,len(commit.parent),iter_parents()函数:他之前的提交的对象
通过用户名拿到用户对象
author = gl.users.list(username="zhubing")
创建MR
#mr_body是一个字典,包含属性
# mr_body['source_branch']
# mr_body['target_branch']
# mr_body['title'] = title
# mr_body['reviewer_ids']
# mr_body['target_project_id']
# mr_body['description']
mr = src_proj.mergerequests.create(mr_body)