其他分享
首页 > 其他分享> > gitlab接口调用

gitlab接口调用

作者:互联网

1.获取用户token

按需填写信息,然后点击创建token.

 

保存下token.

2.通过python第三方包gitlab调用接口

2.1 链接方式

import gitlab
# anonymous read-only access for public resources (GitLab.com)
gl = gitlab.Gitlab()
# anonymous read-only access for public resources (self-hosted GitLab instance)
gl = gitlab.Gitlab('https://gitlab.example.com')
# private token or personal token authentication (GitLab.com)
gl = gitlab.Gitlab(private_token='JVNSESs8EwWRx5yDxM5q')
# private token or personal token authentication (self-hosted GitLab instance)  (这里用这种即可)
gl = gitlab.Gitlab(url='https://gitlab.example.com', private_token='JVNSESs8EwWRx5yDxM5q')   
# oauth token authentication
gl = gitlab.Gitlab('https://gitlab.example.com', oauth_token='my_long_token_here')
# job token authentication (to be used in CI)
# bear in mind the limitations of the API endpoints it supports:
# https://docs.gitlab.com/ee/ci/jobs/ci_job_token.html
import os
gl = gitlab.Gitlab('https://gitlab.example.com', job_token=os.environ['CI_JOB_TOKEN'])
# Define your own custom user agent for requests
gl = gitlab.Gitlab('https://gitlab.example.com', user_agent='my-package/1.0.0')
# make an API request to create the gl.user object. This is mandatory if you
# use the username/password authentication - not required for token authentication,
# and will not work with job tokens.
gl.auth()

2.2 调用demo

# List all projects (default 20)
projects = gl.projects.list(all=True)
# Archived projects
projects = gl.projects.list(archived=1)
# Limit to projects with a defined visibility
projects = gl.projects.list(visibility='public')
# List owned projects
projects = gl.projects.list(owned=True)
# List starred projects
projects = gl.projects.list(starred=True)
# Search projects
projects = gl.projects.list(search='keyword')

2.3 授人以鱼不如授人以渔

最佳文档:https://python-gitlab.readthedocs.io/en/stable/index.html

 

3.通过原生接口访问

 3.1 直接调用

#获取所有project
https://gitlab.example.com/api/v4/projects?private_token=xxxxxxxxx

#获取指定条件的MR
https://gitlab.xiaopeng.us/api/v4/merge_requests?per_page=100&milestone=某某&state=opened&private_token=xxxxxxxx

3.2 授人以鱼不如授人以渔

最佳文档:https://docs.gitlab.com/ee/api/projects.html

 

4.go调用接口

待补充

标签:调用,gitlab,接口,token,https,gl,com,projects
来源: https://www.cnblogs.com/CGCong/p/16519731.html