Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徐晓伟工作室
gitlab-go
提交
1a6fcee6
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,发现更多精彩内容 >>
提交
1a6fcee6
编写于
10月 15, 2023
作者:
徐晓伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
容器仓库 API: 列出仓库内存储库
上级
d3791657
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
140 addition
and
0 deletion
+140
-0
README.md
README.md
+26
-0
container_registry/container_registry.go
container_registry/container_registry.go
+112
-0
main.go
main.go
+2
-0
未找到文件。
README.md
浏览文件 @
1a6fcee6
...
...
@@ -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
...
...
container_registry/container_registry.go
0 → 100644
浏览文件 @
1a6fcee6
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
},
},
},
}
}
main.go
浏览文件 @
1a6fcee6
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录