Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徐晓伟工作室
gitlab-go
提交
97e1c5cc
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,发现更多精彩内容 >>
提交
97e1c5cc
编写于
12月 04, 2023
作者:
徐晓伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
归档所有项目(混合命令,多接口命令)
上级
9a0f73dd
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
147 addition
and
0 deletion
+147
-0
README.md
README.md
+22
-0
constant/common.go
constant/common.go
+1
-0
flag/flag.go
flag/flag.go
+8
-0
main.go
main.go
+1
-0
mix/archive_all.go
mix/archive_all.go
+40
-0
mix/mix_archive.go
mix/mix_archive.go
+18
-0
projects/projects.go
projects/projects.go
+57
-0
未找到文件。
README.md
浏览文件 @
97e1c5cc
...
...
@@ -197,6 +197,7 @@ COMMANDS:
pipeline, pipelines, pl 流水线 API,中文文档:https://docs.gitlab.cn/jh/api/pipelines.html
project, projects, p 项目 API,中文文档:https://docs.gitlab.cn/jh/api/projects.html
mix-delete, mix-rm 删除(混合命令,多接口命令)
mix-archive 归档(混合命令,多接口命令)
help
, h Shows a list of commands or
help
for
one
command
GLOBAL OPTIONS:
...
...
@@ -512,6 +513,27 @@ COPYRIGHT:
--help, -h show help
```
-
归档(混合命令,多接口命令)
```shell
$ go run main.go mix-archive --help
NAME:
gitlab-go mix-archive - 归档(混合命令,多接口命令)
USAGE:
gitlab-go mix-archive command [command options] [arguments...]
COMMANDS:
all 归档所有项目(混合命令,多接口命令)
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
--owned 当前用户明确拥有的项目。 (default: false)
--help, -h show help
```
### test
```
shell
...
...
constant/common.go
浏览文件 @
97e1c5cc
...
...
@@ -23,4 +23,5 @@ const (
IssueId
=
"issue-id"
IssueIdRange
=
"issue-id-range"
Recursion
=
"recursion"
Owned
=
"owned"
)
flag/flag.go
浏览文件 @
97e1c5cc
...
...
@@ -176,6 +176,14 @@ func Recursion() cli.Flag {
}
}
func
Owned
(
required
bool
)
cli
.
Flag
{
return
&
cli
.
BoolFlag
{
Name
:
constant
.
Owned
,
Usage
:
"当前用户明确拥有的项目。"
,
Required
:
required
,
}
}
func
IssueIdRange
(
required
bool
)
cli
.
Flag
{
return
&
cli
.
StringSliceFlag
{
Name
:
constant
.
IssueIdRange
,
...
...
main.go
浏览文件 @
97e1c5cc
...
...
@@ -77,6 +77,7 @@ func main() {
pipelines
.
Pipelines
(),
projects
.
Projects
(),
mix
.
Delete
(),
mix
.
Archive
(),
},
}
...
...
mix/archive_all.go
0 → 100644
浏览文件 @
97e1c5cc
package
mix
import
(
"github.com/urfave/cli/v2"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
"github.com/xuxiaowei-com-cn/gitlab-go/projects"
"log"
)
// ArchiveAll 归档所有项目
func
ArchiveAll
()
*
cli
.
Command
{
return
&
cli
.
Command
{
Name
:
"all"
,
Usage
:
"归档所有项目(混合命令,多接口命令)"
,
Flags
:
append
(
flag
.
CommonTokenRequired
(),
flag
.
Owned
(
true
)),
Action
:
func
(
context
*
cli
.
Context
)
error
{
var
baseUrl
=
context
.
String
(
constant
.
BaseUrl
)
var
token
=
context
.
String
(
constant
.
Token
)
var
owned
=
context
.
Bool
(
constant
.
Owned
)
projectList
,
err
:=
projects
.
ListProjects
(
&
owned
,
token
,
baseUrl
,
1
,
100
)
if
err
!=
nil
{
return
err
}
for
index
,
project
:=
range
projectList
{
log
.
Printf
(
"Project Index: %d, WebURL: %s"
,
index
,
project
.
WebURL
)
err
=
projects
.
ArchiveProject
(
token
,
baseUrl
,
project
.
PathWithNamespace
)
if
err
!=
nil
{
return
err
}
}
return
nil
},
}
}
mix/mix_archive.go
0 → 100644
浏览文件 @
97e1c5cc
package
mix
import
(
"github.com/urfave/cli/v2"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
)
// Archive 归档
func
Archive
()
*
cli
.
Command
{
return
&
cli
.
Command
{
Name
:
"mix-archive"
,
Usage
:
"归档(混合命令,多接口命令)"
,
Flags
:
append
(
flag
.
Common
(),
flag
.
Owned
(
false
)),
Subcommands
:
[]
*
cli
.
Command
{
ArchiveAll
(),
},
}
}
projects/projects.go
浏览文件 @
97e1c5cc
...
...
@@ -2,7 +2,9 @@ package projects
import
(
"github.com/urfave/cli/v2"
"github.com/xanzy/go-gitlab"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
"log"
)
const
(
...
...
@@ -23,3 +25,58 @@ func Projects() *cli.Command {
},
}
}
// ListProjects 列出群组 https://docs.gitlab.cn/jh/api/projects.html#%E5%88%97%E5%87%BA%E6%89%80%E6%9C%89%E9%A1%B9%E7%9B%AE
func
ListProjects
(
owned
*
bool
,
token
string
,
baseUrl
string
,
page
int
,
perPage
int
)
([]
*
gitlab
.
Project
,
error
)
{
var
results
[]
*
gitlab
.
Project
gitClient
,
err
:=
gitlab
.
NewClient
(
token
,
gitlab
.
WithBaseURL
(
baseUrl
))
if
err
!=
nil
{
return
nil
,
err
}
opt
:=
&
gitlab
.
ListProjectsOptions
{
ListOptions
:
gitlab
.
ListOptions
{
Page
:
page
,
PerPage
:
perPage
,
},
Owned
:
owned
,
}
projects
,
response
,
err
:=
gitClient
.
Projects
.
ListProjects
(
opt
)
if
err
!=
nil
{
return
nil
,
err
}
log
.
Printf
(
"ListProjects Page %d, PerPage: %d, Response StatusCode: %d
\n
"
,
page
,
perPage
,
response
.
Response
.
StatusCode
)
results
=
append
(
results
,
projects
...
)
if
len
(
projects
)
!=
0
{
projects
,
err
=
ListProjects
(
owned
,
token
,
baseUrl
,
page
+
1
,
perPage
)
if
err
!=
nil
{
return
nil
,
err
}
results
=
append
(
results
,
projects
...
)
}
return
results
,
err
}
func
ArchiveProject
(
token
string
,
baseUrl
string
,
pathWithNamespace
string
)
error
{
gitClient
,
err
:=
gitlab
.
NewClient
(
token
,
gitlab
.
WithBaseURL
(
baseUrl
))
if
err
!=
nil
{
return
err
}
_
,
response
,
err
:=
gitClient
.
Projects
.
ArchiveProject
(
pathWithNamespace
)
if
err
!=
nil
{
return
err
}
log
.
Printf
(
"ArchiveProject PathWithNamespace: %s, Response StatusCode: %d
\n
"
,
pathWithNamespace
,
response
.
Response
.
StatusCode
)
return
nil
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录