您好,登錄后才能下訂單哦!
我的gitlab API版本是Gitlab API V4,運行的界面如下
代碼如下:
#/usr/bin/python
#coding=utf-8
import gitlab
plist = ''
def allprojects():
#######獲取gitlab的所有projects###
projects = gl.projects.list(all=True)
for project in projects:
print project.name,project.id
def allgroups():
#######獲取gitlab的所有group名稱以及ID###
all_groups = gl.groups.list(all=True)
for group in all_groups:
print group.name,group.id
def allusers():
#######獲取gitlab的所有user名稱以及ID###
users = gl.users.list(all=True)
for user in users:
print user.username,user.id,user.name,user.state
def assgroup():
#######獲取gitlab指定組內所有user以及project名稱以及ID信息,本例中組ID為58###
gid = int(raw_input('Input the group ID: '))
group = gl.groups.get(gid)
print group.name
#members = group.members.list(all=True)
#for me in members:
# print me.username,me.id
projects = group.projects.list(all=True)
for project in projects:
print group.name,project.name
#######################################
def projectinfo():
pid = int(raw_input('Input the project ID: '))
projects = gl.projects.get(pid)
print projects.name,projects.http_url_to_repo
def projectid():
gid = int(raw_input('Input the group ID: '))
group = gl.groups.get(gid)
repo = str(raw_input('Input your repo name: '))
project = gl.projects.get(group.name + '/' + repo)
print project.id
def assuser():
#######獲取gitlab指定user###
uid = int(raw_input('Input the user ID: '))
user = gl.users.get(uid)
print user.name
if __name__ == '__main__':
gl = gitlab.Gitlab('http://10.50.22.22/', private_token='xxxxxxxxxxj')
info = {1:'allprojects()',2:'allgroups()',3:'allusers()',4:'projectinfo()',5:'projectid()',6:'assuser()',7:'assgroup()'}
serp = '-' * 20
print '''%s
1. 列出所有的projects
2. 列出所有的groups
3. 列出所有的users
4. 根據project的ID列出project的所有信息
5. 列出指定的project ID
6. 列出指定的user
7. 列出指定的組內的信息
%s''' % (serp,serp)
num = int(raw_input('Input yout choice: '))
exec info[num]
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。