提交 44b13338 编写于 作者: 徐晓伟's avatar 徐晓伟

容器仓库 API: 获取仓库里存储库的某个标签的详情

上级 4f96bed6
......@@ -233,6 +233,7 @@ COPYRIGHT:
COMMANDS:
list 列出仓库内存储库
list-tags 列出仓库里存储库的标签
get-tag 获取仓库里存储库的某个标签的详情
help, h Shows a list of commands or help for one command
OPTIONS:
......@@ -244,6 +245,7 @@ COPYRIGHT:
--print-time 打印时间 (default: false)
--id value 项目 ID 或 URL 编码的路径
--repository value 仓库里存储库的 ID
--tag-name value 标签的名称
--help, -h show help
```
......
......@@ -6,6 +6,7 @@ const (
BaseUrlDefault = "https://gitlab.com/api/v4"
Id = "id"
Repository = "repository"
TagName = "tag-name"
JobId = "job-id"
Sort = "sort"
SortDefault = "desc"
......
......@@ -17,7 +17,7 @@ func ContainerRegistry() *cli.Command {
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), flag.Repository(false)),
flag.Id(false), flag.Repository(false), flag.TagName(false)),
Subcommands: []*cli.Command{
{
Name: "list",
......@@ -189,6 +189,78 @@ func ContainerRegistry() *cli.Command {
}
}
return nil
},
},
{
Name: "get-tag",
Usage: "获取仓库里存储库的某个标签的详情",
Flags: append(flag.CommonTokenRequired(), flag.PrintJson(), flag.PrintTime(),
flag.Id(true), flag.Repository(true), flag.TagName(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 repository = context.Int(constant.Repository)
var tagName = context.String(constant.TagName)
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
}
registryRepositoryTag, response, err := gitClient.ContainerRegistry.GetRegistryRepositoryTagDetail(id, repository, tagName)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
fmt.Println("")
if printJson {
if printTime {
jsonData, err := json.Marshal(registryRepositoryTag)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
} else {
jsonData, err := json.Marshal(registryRepositoryTag)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
} else {
if printTime {
log.Printf("Name: %s\n", registryRepositoryTag.Name)
log.Printf("Path: %s\n", registryRepositoryTag.Path)
log.Printf("Location: %s\n", registryRepositoryTag.Location)
log.Printf("Revision: %s\n", registryRepositoryTag.Revision)
log.Printf("ShortRevision: %s\n", registryRepositoryTag.ShortRevision)
log.Printf("Digest: %s\n", registryRepositoryTag.Digest)
log.Printf("CreatedAt: %s\n", registryRepositoryTag.CreatedAt)
log.Printf("TotalSize: %d\n", registryRepositoryTag.TotalSize)
fmt.Println("")
} else {
fmt.Printf("Name: %s\n", registryRepositoryTag.Name)
fmt.Printf("Path: %s\n", registryRepositoryTag.Path)
fmt.Printf("Location: %s\n", registryRepositoryTag.Location)
fmt.Printf("Revision: %s\n", registryRepositoryTag.Revision)
fmt.Printf("ShortRevision: %s\n", registryRepositoryTag.ShortRevision)
fmt.Printf("Digest: %s\n", registryRepositoryTag.Digest)
fmt.Printf("CreatedAt: %s\n", registryRepositoryTag.CreatedAt)
fmt.Printf("TotalSize: %d\n", registryRepositoryTag.TotalSize)
fmt.Println("")
}
}
return nil
},
},
......
......@@ -76,6 +76,14 @@ func Repository(required bool) cli.Flag {
}
}
func TagName(required bool) cli.Flag {
return &cli.StringFlag{
Name: constant.TagName,
Usage: "标签的名称",
Required: required,
}
}
func JobId(required bool) cli.Flag {
return &cli.StringFlag{
Name: constant.JobId,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册