Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徐晓伟工作室
gitlab-go
提交
b9d2f2d9
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,发现更多精彩内容 >>
提交
b9d2f2d9
编写于
11月 24, 2023
作者:
徐晓伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
删除作业(删除作业产物和作业日志)
上级
aeaa157e
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
90 addition
and
13 deletion
+90
-13
README.md
README.md
+18
-12
constant/common.go
constant/common.go
+1
-0
flag/flag.go
flag/flag.go
+12
-0
jobs/erase.go
jobs/erase.go
+57
-0
jobs/jobs.go
jobs/jobs.go
+2
-1
未找到文件。
README.md
浏览文件 @
b9d2f2d9
...
...
@@ -140,7 +140,7 @@ go run main.go
-
Linux 环境为 $xxx
```
shell
go run main.go
help
go run main.go
--
help
```
```
shell
...
...
@@ -374,20 +374,26 @@ COPYRIGHT:
COMMANDS:
list 列出项目作业
erase 删除作业(删除作业产物和作业日志)
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)
--recursion 递归 (default: false)
--sort value 按照 asc 或者 desc 排序 (default: "desc")
--id value 项目 ID 或 URL 编码的路径
--scope value 要显示的作业范围。以下之一或数组:created、pending、running、failed、success、canceled、skipped、waiting_for_resource 或 manual。范围如果未提供,则返回所有作业。
--help, -h show help
--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)
--recursion 递归 (default: false)
--sort value 按照 asc 或者 desc 排序 (default: "desc")
--id value 项目 ID 或 URL 编码的路径
--job-id-range value [ --job-id-range value ] Job ID的范围,支持范围如下:
单数:1
多个数字(使用英文逗号隔开):1,2,3,7,8,15
支持范围:5-10,
支持范围方向选择:-10(小于等于10,即:从 0 到 10),214-(大于等于214,即:从 214 到 214 + 10000,数据范围不超过 10000)
--scope value 要显示的作业范围。以下之一或数组:created、pending、running、failed、success、canceled、skipped、waiting_for_resource 或 manual。范围如果未提供,则返回所有作业。
--help, -h show help
```
-
[
pipeline - 流水线 API
](
https://docs.gitlab.cn/jh/api/pipelines.html
)
...
...
constant/common.go
浏览文件 @
b9d2f2d9
...
...
@@ -5,6 +5,7 @@ const (
BaseUrl
=
"base-url"
BaseUrlDefault
=
"https://gitlab.com/api/v4"
Id
=
"id"
JobIdRange
=
"job-id-range"
IIdRange
=
"iid-range"
Repository
=
"repository"
TagName
=
"tag-name"
...
...
flag/flag.go
浏览文件 @
b9d2f2d9
...
...
@@ -73,6 +73,18 @@ func Id(required bool) cli.Flag {
}
}
func
JobIdRange
(
required
bool
)
cli
.
Flag
{
return
&
cli
.
StringSliceFlag
{
Name
:
constant
.
JobIdRange
,
Usage
:
"Job ID的范围,支持范围如下:
\n\t
"
+
"单数:1
\n\t
"
+
"多个数字(使用英文逗号隔开):1,2,3,7,8,15
\n\t
"
+
"支持范围:5-10,
\n\t
"
+
fmt
.
Sprintf
(
"支持范围方向选择:-10(小于等于10,即:从 0 到 10),214-(大于等于214,即:从 214 到 214 + %d,数据范围不超过 %d)"
,
RangeMaxInterval
,
RangeMaxInterval
),
Required
:
required
,
}
}
func
IIdRange
(
required
bool
)
cli
.
Flag
{
return
&
cli
.
StringSliceFlag
{
Name
:
constant
.
IIdRange
,
...
...
jobs/erase.go
0 → 100644
浏览文件 @
b9d2f2d9
package
jobs
import
(
"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/utils"
"log"
"sort"
)
// Erase 删除作业 https://docs.gitlab.cn/jh/api/jobs.html#%E5%88%A0%E9%99%A4%E4%BD%9C%E4%B8%9A
func
Erase
()
*
cli
.
Command
{
return
&
cli
.
Command
{
Name
:
"erase"
,
Usage
:
"删除作业(删除作业产物和作业日志)"
,
Flags
:
append
(
flag
.
CommonTokenRequired
(),
flag
.
Id
(
true
),
flag
.
JobIdRange
(
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
jobIdRanges
=
context
.
StringSlice
(
constant
.
JobIdRange
)
gitClient
,
err
:=
gitlab
.
NewClient
(
token
,
gitlab
.
WithBaseURL
(
baseUrl
))
if
err
!=
nil
{
return
err
}
jobIds
:=
utils
.
Unique
(
utils
.
RangeInt
(
jobIdRanges
))
sort
.
Ints
(
jobIds
)
err
=
EraseJobsPrintln
(
gitClient
,
id
,
jobIds
)
if
err
!=
nil
{
return
err
}
return
nil
},
}
}
func
EraseJobsPrintln
(
gitClient
*
gitlab
.
Client
,
id
string
,
jobIds
[]
int
)
error
{
// 数字在上方已排序
for
_
,
jobId
:=
range
jobIds
{
job
,
response
,
err
:=
gitClient
.
Jobs
.
EraseJob
(
id
,
jobId
)
if
err
!=
nil
{
log
.
Println
(
err
)
continue
}
log
.
Printf
(
"Delete %s Job %d Response %v:
\n
%v"
,
id
,
jobId
,
response
,
job
)
}
return
nil
}
jobs/jobs.go
浏览文件 @
b9d2f2d9
...
...
@@ -17,9 +17,10 @@ func Jobs() *cli.Command {
Aliases
:
[]
string
{
"jobs"
,
"j"
},
Usage
:
"作业 API,中文文档:https://docs.gitlab.cn/jh/api/jobs.html"
,
Flags
:
append
(
flag
.
Common
(),
flag
.
Page
(),
flag
.
PerPage
(),
flag
.
PrintJson
(),
flag
.
PrintTime
(),
flag
.
Recursion
(),
flag
.
Sort
(),
flag
.
Id
(
false
),
flag
.
Scope
(
ScopeValue
,
ScopeUsage
)),
flag
.
Sort
(),
flag
.
Id
(
false
),
flag
.
JobIdRange
(
false
),
flag
.
Scope
(
ScopeValue
,
ScopeUsage
)),
Subcommands
:
[]
*
cli
.
Command
{
List
(),
Erase
(),
},
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录