Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徐晓伟工作室
gitlab-go
提交
44b13338
G
gitlab-go
项目概览
徐晓伟工作室
/
gitlab-go
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-go
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
44b13338
编写于
10月 15, 2023
作者:
徐晓伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
容器仓库 API: 获取仓库里存储库的某个标签的详情
上级
4f96bed6
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
84 addition
and
1 deletion
+84
-1
README.md
README.md
+2
-0
constant/common.go
constant/common.go
+1
-0
container_registry/container_registry.go
container_registry/container_registry.go
+73
-1
flag/flag.go
flag/flag.go
+8
-0
未找到文件。
README.md
浏览文件 @
44b13338
...
...
@@ -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
```
...
...
constant/common.go
浏览文件 @
44b13338
...
...
@@ -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"
...
...
container_registry/container_registry.go
浏览文件 @
44b13338
...
...
@@ -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
},
},
...
...
flag/flag.go
浏览文件 @
44b13338
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录