我的gitlab API版本是Gitlab API V4,运行的界面如下
代码如下:
#/usr/bin/python
#coding=utf-8import gitlabplist = ''def allprojects(): #######获取gitlab的所有projects### projects = gl.projects.list(all=True) for project in projects: print project.name,project.iddef allgroups(): #######获取gitlab的所有group名称以及ID### all_groups = gl.groups.list(all=True) for group in all_groups: print group.name,group.iddef allusers(): #######获取gitlab的所有user名称以及ID### users = gl.users.list(all=True) for user in users: print user.username,user.id,user.name,user.statedef 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_repodef 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.iddef assuser(): #######获取gitlab指定user### uid = int(raw_input('Input the user ID: ')) user = gl.users.get(uid) print user.nameif __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 '''%s1. 列出所有的projects2. 列出所有的groups3. 列出所有的users 4. 根据project的ID列出project的所有信息5. 列出指定的project ID6. 列出指定的user7. 列出指定的组内的信息 %s''' % (serp,serp) num = int(raw_input('Input yout choice: ')) exec info[num]