Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徐晓伟工作室
gitlab-go
提交
d157259d
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,体验更适合开发者的 AI 搜索 >>
提交
d157259d
编写于
10月 26, 2023
作者:
徐晓伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
删除(混合命令): 根据项目路径/ID删除所有产物(混合命令,立即删除)
上级
ebd78c5e
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
111 addition
and
3 deletion
+111
-3
README.md
README.md
+4
-3
mix/delete_all_artifacts.go
mix/delete_all_artifacts.go
+106
-0
mix/mix_delete.go
mix/mix_delete.go
+1
-0
未找到文件。
README.md
浏览文件 @
d157259d
...
...
@@ -446,7 +446,7 @@ COPYRIGHT:
```
-
删除(混合命令)
```shell
$ go run main.go mix-delete --help
NAME:
...
...
@@ -456,8 +456,9 @@ COPYRIGHT:
gitlab-go mix-delete command [command options] [arguments...]
COMMANDS:
artifact, artifacts 根据项目路径/ID、流水线IID范围删除产物(混合命令,立即删除)
help
, h Shows a list of commands or
help
for
one
command
artifact, artifacts 根据项目路径/ID、流水线IID范围删除产物(混合命令,立即删除)
all-artifact, all-artifacts 根据项目路径/ID删除所有产物(混合命令,立即删除)
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%]
...
...
mix/delete_all_artifacts.go
0 → 100644
浏览文件 @
d157259d
package
mix
import
(
"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"
"github.com/xuxiaowei-com-cn/gitlab-go/pipelines"
"log"
)
// DeleteAllArtifacts 删除所有产物
func
DeleteAllArtifacts
()
*
cli
.
Command
{
return
&
cli
.
Command
{
Name
:
"all-artifact"
,
Aliases
:
[]
string
{
"all-artifacts"
},
Usage
:
"根据项目路径/ID删除所有产物(混合命令,立即删除)"
,
Flags
:
append
(
flag
.
CommonTokenRequired
(),
flag
.
Sort
(),
flag
.
Page
(),
flag
.
PerPage
(),
flag
.
Id
(
true
)),
Action
:
func
(
context
*
cli
.
Context
)
error
{
var
baseUrl
=
context
.
String
(
constant
.
BaseUrl
)
var
token
=
context
.
String
(
constant
.
Token
)
var
sortStr
=
context
.
String
(
constant
.
Sort
)
var
id
=
context
.
String
(
constant
.
Id
)
var
page
=
context
.
Int
(
constant
.
Page
)
var
perPage
=
context
.
Int
(
constant
.
PerPage
)
gitClient
,
err
:=
gitlab
.
NewClient
(
token
,
gitlab
.
WithBaseURL
(
baseUrl
))
if
err
!=
nil
{
return
err
}
err
=
DeleteAllArtifactsRecursion
(
gitClient
,
id
,
page
,
perPage
,
sortStr
)
if
err
!=
nil
{
return
err
}
return
nil
},
}
}
func
DeleteAllArtifactsRecursion
(
gitClient
*
gitlab
.
Client
,
id
interface
{},
page
int
,
perPage
int
,
sort
string
)
error
{
pipelineInfos
,
response
,
err
:=
pipelines
.
ListProjectPipelines
(
gitClient
,
id
,
page
,
perPage
,
sort
)
if
err
!=
nil
{
return
err
}
log
.
Printf
(
"Page %d, PerPage: %d, Response StatusCode: %d
\n
"
,
page
,
perPage
,
response
.
Response
.
StatusCode
)
for
_
,
pipelineInfo
:=
range
pipelineInfos
{
fmt
.
Printf
(
"%d
\n
"
,
pipelineInfo
.
IID
)
err
=
ExecuteDeleteAllArtifacts
(
gitClient
,
id
,
pipelineInfo
.
ID
,
1
,
100
)
if
err
!=
nil
{
return
err
}
}
if
len
(
pipelineInfos
)
>
0
{
err
:=
DeleteAllArtifactsRecursion
(
gitClient
,
id
,
page
+
1
,
perPage
,
sort
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
func
ExecuteDeleteAllArtifacts
(
gitClient
*
gitlab
.
Client
,
id
interface
{},
pipelineInfoId
int
,
page
int
,
perPage
int
)
error
{
fmt
.
Printf
(
"执行删除 %d
\n
"
,
pipelineInfoId
)
opt
:=
&
gitlab
.
ListJobsOptions
{
ListOptions
:
gitlab
.
ListOptions
{
Page
:
page
,
PerPage
:
perPage
,
},
}
jobs
,
response
,
err
:=
gitClient
.
Jobs
.
ListPipelineJobs
(
id
,
pipelineInfoId
,
opt
)
if
err
!=
nil
{
return
err
}
log
.
Printf
(
"List Project %s Pipeline %d Jobs Response StatusCode: %d
\n
"
,
id
,
pipelineInfoId
,
response
.
Response
.
StatusCode
)
for
_
,
job
:=
range
jobs
{
response
,
err
=
gitClient
.
Jobs
.
DeleteArtifacts
(
id
,
job
.
ID
)
if
err
!=
nil
{
return
err
}
log
.
Printf
(
"Delete Project %s Job %d Response StatusCode: %d
\n
"
,
id
,
job
.
ID
,
response
.
Response
.
StatusCode
)
}
if
len
(
jobs
)
==
perPage
{
err
=
ExecuteDeleteAllArtifacts
(
gitClient
,
id
,
pipelineInfoId
,
page
+
1
,
perPage
)
if
err
!=
nil
{
return
err
}
}
return
nil
}
mix/mix_delete.go
浏览文件 @
d157259d
...
...
@@ -14,6 +14,7 @@ func Delete() *cli.Command {
Flags
:
append
(
flag
.
Common
(),
flag
.
Sort
(),
flag
.
Page
(),
flag
.
PerPage
(),
flag
.
Id
(
false
),
flag
.
IIdRange
(
false
)),
Subcommands
:
[]
*
cli
.
Command
{
DeleteArtifacts
(),
DeleteAllArtifacts
(),
},
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录