diff --git a/README.md b/README.md index 112fcc7..2140c83 100644 --- a/README.md +++ b/README.md @@ -231,10 +231,11 @@ COPYRIGHT: gitlab-go container-registry command [command options] [arguments...] COMMANDS: - list 列出仓库内存储库 - list-tags 列出仓库里存储库的标签 - get-tag 获取仓库里存储库的某个标签的详情 - help, h Shows a list of commands or help for one command + list 列出仓库内存储库 + list-tags 列出仓库里存储库的标签 + get-tag 获取仓库里存储库的某个标签的详情 + delete-tag, rm-tag 删除仓库里存储库的某个标签 + 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%] diff --git a/container_registry/container_registry.go b/container_registry/container_registry.go index 6f5589e..dde487f 100644 --- a/container_registry/container_registry.go +++ b/container_registry/container_registry.go @@ -261,6 +261,33 @@ func ContainerRegistry() *cli.Command { } } + return nil + }, + }, + { + Name: "delete-tag", + Aliases: []string{"rm-tag"}, + Usage: "删除仓库里存储库的某个标签", + Flags: append(flag.CommonTokenRequired(), + 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) + + gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl)) + if err != nil { + return err + } + + response, err := gitClient.ContainerRegistry.DeleteRegistryRepositoryTag(id, repository, tagName) + log.Printf("Response StatusCode: %d\n", response.Response.StatusCode) + if err != nil { + return err + } + return nil }, },