提交 3616ccf5 编写于 作者: 徐晓伟's avatar 徐晓伟

议题 API: 列出议题

上级 c5b69a40
......@@ -161,6 +161,7 @@ COMMANDS:
access-request, access-requests, ar 群组和项目访问请求 API,中文文档:https://docs.gitlab.cn/jh/api/access_requests.html
board, boards 项目议题板 API,中文文档:https://docs.gitlab.cn/jh/api/boards.html
instance-level-ci-variable, instance-level-ci-variables, ilcv 实例级 CI/CD 变量 API,中文文档:https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html
issue, issues 议题 API,中文文档:https://docs.gitlab.cn/jh/api/issues.html
job-artifact, job-artifacts, ja 作业产物 API,中文文档:https://docs.gitlab.cn/jh/api/job_artifacts.html
job, jobs, j 作业 API,中文文档:https://docs.gitlab.cn/jh/api/jobs.html
pipeline, pipelines, pl 流水线 API,中文文档:https://docs.gitlab.cn/jh/api/pipelines.html
......@@ -238,6 +239,28 @@ COPYRIGHT:
--help, -h show help
```
- [issue - 议题 API](https://docs.gitlab.cn/jh/api/issues.html)
```shell
$ go run main.go issue --help
NAME:
gitlab-go issue - 议题 API,中文文档:https://docs.gitlab.cn/jh/api/issues.html
USAGE:
gitlab-go issue command [command options] [arguments...]
COMMANDS:
list 列出议题
help, h Shows a list of commands or help for one command
OPTIONS:
--base-url value 实例地址,例如:https://gitlab.xuxiaowei.com.cn/api/v4 (default: "https://gitlab.com/api/v4") [%CI_API_V4_URL%]
--token value your_access_token
--page value 页码(默认:1),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 0)
--per-page value 每页列出的项目数(默认:20;最大:100),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 0)
--help, -h show help
```
- [job-artifact - 作业产物 API](https://docs.gitlab.cn/jh/api/job_artifacts.html)
```shell
......
......@@ -8,4 +8,6 @@ const (
JobId = "job-id"
Sort = "sort"
SortDefault = "desc"
PAGE = "page"
PerPage = "per-page"
)
......@@ -59,3 +59,17 @@ func JobId(required bool) cli.Flag {
Required: required,
}
}
func Page() cli.Flag {
return &cli.UintFlag{
Name: constant.PAGE,
Usage: "页码(默认:1),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination",
}
}
func PerPage() cli.Flag {
return &cli.UintFlag{
Name: constant.PerPage,
Usage: "每页列出的项目数(默认:20;最大:100),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination",
}
}
package issues
import (
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"github.com/xanzy/go-gitlab"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
"log"
)
// Issues 议题 API https://docs.gitlab.cn/jh/api/issues.html
func Issues() *cli.Command {
return &cli.Command{
Name: "issue",
Aliases: []string{"issues"},
Usage: "议题 API,中文文档:https://docs.gitlab.cn/jh/api/issues.html",
Flags: append(flag.Common(), flag.Page(), flag.PerPage()),
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "列出议题",
Flags: append(flag.CommonTokenRequired(), flag.Page(), flag.PerPage()),
Action: func(context *cli.Context) error {
var baseUrl = context.String(constant.BaseUrl)
var token = context.String(constant.Token)
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl))
if err != nil {
return err
}
opt := &gitlab.ListIssuesOptions{}
issues, response, err := gitClient.Issues.ListIssues(opt)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
fmt.Println("")
for index, issue := range issues {
jsonData, err := json.Marshal(issue)
if err != nil {
panic(err)
}
log.Printf("Index: %d: \n%s\n", index, string(jsonData))
fmt.Println("")
}
return nil
},
},
},
}
}
......@@ -6,6 +6,7 @@ import (
"github.com/xuxiaowei-com-cn/gitlab-go/access_requests"
"github.com/xuxiaowei-com-cn/gitlab-go/boards"
"github.com/xuxiaowei-com-cn/gitlab-go/instance_level_ci_variables"
"github.com/xuxiaowei-com-cn/gitlab-go/issues"
"github.com/xuxiaowei-com-cn/gitlab-go/job_artifacts"
"github.com/xuxiaowei-com-cn/gitlab-go/jobs"
"github.com/xuxiaowei-com-cn/gitlab-go/pipelines"
......@@ -66,6 +67,7 @@ func main() {
access_requests.AccessRequests(),
boards.Boards(),
instance_level_ci_variables.InstanceLevelCiVariables(),
issues.Issues(),
job_artifacts.JobsArtifacts(),
jobs.Jobs(),
pipelines.Pipelines(),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册