1.获取用户token

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

 

保存下token.

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

2.1 下载第三方包

pip install --upgrade python-gitlab

2.2 链接方式

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.3 调用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.4 授人以鱼不如授人以渔

最佳文档: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调用接口

待补充

posted on 2022-07-26 09:51  聪神carry  阅读(1417)  评论(0编辑  收藏  举报