✨ 项目 API: 列出所有项目: 增加参数
This commit is contained in:
parent
d800187847
commit
6fb1f377be
12
README.md
12
README.md
|
@ -366,10 +366,14 @@ COPYRIGHT:
|
|||
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
|
||||
--sort value 按照 asc 或者 desc 排序 (default: "desc")
|
||||
--help, -h show help
|
||||
--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
|
||||
--sort value 按照 asc 或者 desc 排序 (default: "desc")
|
||||
--page value 页码(默认:1),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 1)
|
||||
--per-page value 每页列出的项目数(默认:20;最大:100),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 20)
|
||||
--search value 根据 title 和 description 搜索议题。
|
||||
--search-namespaces 匹配搜索条件时包括上级命名空间。默认为 false。 (default: false)
|
||||
--help, -h show help
|
||||
```
|
||||
|
||||
### test
|
||||
|
|
|
@ -26,6 +26,7 @@ const (
|
|||
OrderBy = "order-by"
|
||||
Scope = "scope"
|
||||
Search = "search"
|
||||
SearchNamespaces = "search-namespaces"
|
||||
State = "state"
|
||||
UpdatedAfter = "updated-after"
|
||||
UpdatedBefore = "updated-before"
|
||||
|
|
|
@ -116,6 +116,14 @@ func Search() cli.Flag {
|
|||
}
|
||||
}
|
||||
|
||||
func SearchNamespaces() cli.Flag {
|
||||
return &cli.BoolFlag{
|
||||
Name: constant.SearchNamespaces,
|
||||
Value: false,
|
||||
Usage: "匹配搜索条件时包括上级命名空间。默认为 false。",
|
||||
}
|
||||
}
|
||||
|
||||
func State() cli.Flag {
|
||||
return &cli.StringFlag{
|
||||
Name: constant.State,
|
||||
|
|
|
@ -14,16 +14,20 @@ func Projects() *cli.Command {
|
|||
Name: "project",
|
||||
Aliases: []string{"projects", "p"},
|
||||
Usage: "项目 API,中文文档:https://docs.gitlab.cn/jh/api/projects.html",
|
||||
Flags: append(flag.Common(), flag.Sort()),
|
||||
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.Search(), flag.SearchNamespaces()),
|
||||
Subcommands: []*cli.Command{
|
||||
{
|
||||
Name: "list",
|
||||
Usage: "列出所有项目",
|
||||
Flags: append(flag.Common(), flag.Sort()),
|
||||
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.Search(), flag.SearchNamespaces()),
|
||||
Action: func(context *cli.Context) error {
|
||||
var baseUrl = context.String(constant.BaseUrl)
|
||||
var token = context.String(constant.Token)
|
||||
var sort = context.String(constant.Sort)
|
||||
var page = context.Int(constant.Page)
|
||||
var perPage = context.Int(constant.PerPage)
|
||||
var search = context.String(constant.Search)
|
||||
var searchNamespaces = context.Bool(constant.SearchNamespaces)
|
||||
|
||||
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl))
|
||||
if err != nil {
|
||||
|
@ -31,7 +35,13 @@ func Projects() *cli.Command {
|
|||
}
|
||||
|
||||
opt := &gitlab.ListProjectsOptions{
|
||||
Sort: &sort,
|
||||
ListOptions: gitlab.ListOptions{
|
||||
Page: page,
|
||||
PerPage: perPage,
|
||||
},
|
||||
Sort: &sort,
|
||||
Search: &search,
|
||||
SearchNamespaces: &searchNamespaces,
|
||||
}
|
||||
projects, response, err := gitClient.Projects.ListProjects(opt)
|
||||
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
|
||||
|
|
Loading…
Reference in New Issue