gitlab pythonAPI操作

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)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值