caizhiyuannn.github.io

nothing to say.. @caizhiyuannn@gmail.com

View the Project on GitHub

Table of Contents

  1. 流程(OAuth password授权方法)
    1. 认证获取Token
    2. 获取项目信息
    3. 获取项目Labels
    4. 新建Issue

流程(OAuth password授权方法)

认证获取Token

echo 'grant_type=password&username=<your_username>&password=<your_password>' > auth.txt
curl --data "@auth.txt" --request POST https://gitlab.example.com/oauth/token
// 新建表单数据

const formData = new FormData()
formData.append("grant_type", "password")
formData.append("username", "user1")
formData.append("password", "password")
fetch("https://gitlab.example.com/oauth/token", {method:"POST", body:formData}).then(res=>res.json()).then(response=>{
    console.log(response);
}).catch(err=>console.log(err))

Response:

{
  "access_token": "1f0af717251950dbd4d73154fdf0a474a5c5119adad999683f5b450c460726aa",
  "token_type": "bearer",
  "expires_in": 7200
}

获取项目信息

# 获取指定用户项目信息
curl --header "Authorization: Bearer <access_token>" https://gitlab.example.com/api/v4/users/:userid/projects

# 获取指定组的项目信息
curl --header "Authorization: Bearer <access_token>" https://gitlab.example.com/api/v4/groups/:userid/projects

获取项目Labels

获取指定项目的labels

curl --header "Authorization: Bearer <access_token>" https://gitlab.example.com/api/v4/projects/:id/labels

新建Issue

curl --request POST --header "Authorization: Bearer <access_token>" https://gitlab.example.com/api/v4/projects/4/issues?title=Issues%20with%20auth&labels=bug

# 或者提交表单数据
curl -d 'title=Issues2%20with%20auth&labels=bug' --request POST --header "Authorization: Bearer 5f3b9960d21507e12fc3119f88b874ba50a83f7a15b2eb3d78ccd00ec0f2dedc" 'https://gitlab.example.com/api/v4/projects/1/issues'

表单内容清单:

Attribute Type Required Description
id integer/string yes The ID or URL-encoded path of the project owned by the authenticated user
title string yes issue标题
description string no issue 描述内容,支持Markdown
labels string no 标签
等等。。。