提交 1a6fcee6 编写于 作者: 徐晓伟's avatar 徐晓伟

容器仓库 API: 列出仓库内存储库

上级 d3791657
......@@ -160,6 +160,7 @@ AUTHOR:
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
container-registry, cr 容器仓库 API,中文文档:https://docs.gitlab.cn/jh/api/container_registry.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
......@@ -219,6 +220,31 @@ COPYRIGHT:
--help, -h show help
```
- [container-registry - 容器仓库 API](https://docs.gitlab.cn/jh/api/container_registry.html)
```shell
$ go run main.go container-registry --help
NAME:
gitlab-go container-registry - 容器仓库 API,中文文档:https://docs.gitlab.cn/jh/api/container_registry.html
USAGE:
gitlab-go container-registry 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: 1)
--per-page value 每页列出的项目数(默认:20;最大:100),中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 20)
--print-json 打印 JSON (default: false)
--print-time 打印时间 (default: false)
--id value 项目 ID 或 URL 编码的路径
--help, -h show help
```
- [instance-level-ci-variable - 实例级 CI/CD 变量 API](https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html)
```shell
......
package container_registry
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"
)
// ContainerRegistry 容器仓库 API https://docs.gitlab.cn/jh/api/container_registry.html
func ContainerRegistry() *cli.Command {
return &cli.Command{
Name: "container-registry",
Aliases: []string{"cr"},
Usage: "容器仓库 API,中文文档:https://docs.gitlab.cn/jh/api/container_registry.html",
Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Id(false)),
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "列出仓库内存储库",
Flags: append(flag.CommonTokenRequired(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Id(true)),
Action: func(context *cli.Context) error {
var baseUrl = context.String(constant.BaseUrl)
var token = context.String(constant.Token)
var id = context.String(constant.Id)
var page = context.Int(constant.Page)
var perPage = context.Int(constant.PerPage)
var printJson = context.Bool(constant.PrintJson)
var printTime = context.Bool(constant.PrintTime)
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl))
if err != nil {
return err
}
opt := &gitlab.ListRegistryRepositoriesOptions{
ListOptions: gitlab.ListOptions{
Page: page,
PerPage: perPage,
},
}
registryRepositorys, response, err := gitClient.ContainerRegistry.ListProjectRegistryRepositories(id, opt)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
fmt.Println("")
if printJson {
if printTime {
for _, registryRepository := range registryRepositorys {
jsonData, err := json.Marshal(registryRepository)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, registryRepository := range registryRepositorys {
jsonData, err := json.Marshal(registryRepository)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, registryRepository := range registryRepositorys {
log.Printf("ID: %d\n", registryRepository.ID)
log.Printf("Name: %s\n", registryRepository.Name)
log.Printf("Path: %s\n", registryRepository.Path)
log.Printf("ProjectID: %d\n", registryRepository.ProjectID)
log.Printf("Location: %s\n", registryRepository.Location)
log.Printf("CreatedAt: %s\n", registryRepository.CreatedAt)
log.Printf("CleanupPolicyStartedAt: %s\n", registryRepository.CleanupPolicyStartedAt)
log.Printf("TagsCount: %d\n", registryRepository.TagsCount)
log.Printf("Tags: %s\n", registryRepository.Tags)
fmt.Println("")
}
} else {
for _, registryRepository := range registryRepositorys {
fmt.Printf("ID: %d\n", registryRepository.ID)
fmt.Printf("Name: %s\n", registryRepository.Name)
fmt.Printf("Path: %s\n", registryRepository.Path)
fmt.Printf("ProjectID: %d\n", registryRepository.ProjectID)
fmt.Printf("Location: %s\n", registryRepository.Location)
fmt.Printf("CreatedAt: %s\n", registryRepository.CreatedAt)
fmt.Printf("CleanupPolicyStartedAt: %s\n", registryRepository.CleanupPolicyStartedAt)
fmt.Printf("TagsCount: %d\n", registryRepository.TagsCount)
fmt.Printf("Tags: %s\n", registryRepository.Tags)
fmt.Println("")
}
}
}
return nil
},
},
},
}
}
......@@ -5,6 +5,7 @@ import (
"github.com/xuxiaowei-com-cn/git-go/buildinfo"
"github.com/xuxiaowei-com-cn/gitlab-go/access_requests"
"github.com/xuxiaowei-com-cn/gitlab-go/boards"
"github.com/xuxiaowei-com-cn/gitlab-go/container_registry"
"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"
......@@ -66,6 +67,7 @@ func main() {
Commands: []*cli.Command{
access_requests.AccessRequests(),
boards.Boards(),
container_registry.ContainerRegistry(),
instance_level_ci_variables.InstanceLevelCiVariables(),
issues.Issues(),
job_artifacts.JobsArtifacts(),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册