Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
徐晓伟工作室
gitlab-go
提交
02d1e0e4
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,发现更多精彩内容 >>
提交
02d1e0e4
编写于
1月 16, 2024
作者:
徐晓伟
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
✨
保护仓库分支:保护所有仓库分支
上级
2143aa29
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
137 addition
and
0 deletion
+137
-0
README.md
README.md
+57
-0
main.go
main.go
+1
-0
mix/mix_protect_branches.go
mix/mix_protect_branches.go
+21
-0
mix/protect_branches_all.go
mix/protect_branches_all.go
+58
-0
未找到文件。
README.md
浏览文件 @
02d1e0e4
...
...
@@ -207,6 +207,7 @@ COMMANDS:
mix-delete, mix-rm 删除(混合命令,多接口命令)
mix-create-environments, mix-create-environment, mix-create-env 创建新环境(混合命令,多接口命令)
mix-export 导出(混合命令,多接口命令)
mix-protect-branches 保护仓库分支(混合命令,多接口命令)
mix-transfer 转移(混合命令,多接口命令)
mix-unarchive 取消归档(混合命令,多接口命令)
help
, h Shows a list of commands or
help
for
one
command
...
...
@@ -752,6 +753,62 @@ COPYRIGHT:
--help, -h show help
```
-
保护仓库分支(混合命令,多接口命令)
```shell
$ go run main.go mix-protect-branches --help
NAME:
gitlab-go mix-protect-branches - 保护仓库分支(混合命令,多接口命令)
USAGE:
gitlab-go mix-protect-branches command [command options]
COMMANDS:
all, a 保护所有仓库分支
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)
--name value 分支或通配符的名称
--push-access-level value 允许推送的访问级别(默认值:40,维护者角色),合法值:
0:NoPermissions
5:MinimalAccessPermissions
10:GuestPermissions
20:ReporterPermissions
30:DeveloperPermissions
40:MaintainerPermissions
50:OwnerPermissions
60:AdminPermissions
(default: 40)
--merge-access-level value 允许合并的访问级别(默认值:40,维护者角色),合法值:
0:NoPermissions
5:MinimalAccessPermissions
10:GuestPermissions
20:ReporterPermissions
30:DeveloperPermissions
40:MaintainerPermissions
50:OwnerPermissions
60:AdminPermissions
(default: 40)
--unprotect-access-level value 允许取消保护的访问级别(默认值:40,维护者角色),合法值:
0:NoPermissions
5:MinimalAccessPermissions
10:GuestPermissions
20:ReporterPermissions
30:DeveloperPermissions
40:MaintainerPermissions
50:OwnerPermissions
60:AdminPermissions
(default: 40)
--allow-force-push 启用后,可以推送到该分支的成员也可以强制推送 (default: false)
--code-owner-approval-required 如果分支在 CODEOWNERS https://docs.gitlab.cn/jh/user/project/codeowners/index.html 文件中,则阻止推送到此分支。(默认值:false) (default: false)
--print-json 打印 JSON (default: false)
--print-time 打印时间 (default: false)
--help, -h show help
```
-
转移(混合命令,多接口命令)
```shell
...
...
main.go
浏览文件 @
02d1e0e4
...
...
@@ -87,6 +87,7 @@ func main() {
mix
.
Delete
(),
mix
.
Environments
(),
mix
.
Export
(),
mix
.
ProtectBranches
(),
mix
.
Transfer
(),
mix
.
Unarchive
(),
},
...
...
mix/mix_protect_branches.go
0 → 100644
浏览文件 @
02d1e0e4
package
mix
import
(
"github.com/urfave/cli/v2"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
)
// ProtectBranches 保护仓库分支
func
ProtectBranches
()
*
cli
.
Command
{
return
&
cli
.
Command
{
Name
:
"mix-protect-branches"
,
Usage
:
"保护仓库分支(混合命令,多接口命令)"
,
Flags
:
append
(
flag
.
Common
(),
flag
.
Owned
(
false
),
flag
.
BranchName
(
false
),
flag
.
PushAccessLevel
(),
flag
.
MergeAccessLevel
(),
flag
.
UnprotectAccessLevel
(),
flag
.
AllowForcePush
(),
flag
.
CodeOwnerApprovalRequired
(),
flag
.
PrintJson
(),
flag
.
PrintTime
()),
Subcommands
:
[]
*
cli
.
Command
{
ProtectBranchesAll
(),
},
}
}
mix/protect_branches_all.go
0 → 100644
浏览文件 @
02d1e0e4
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"
"github.com/xuxiaowei-com-cn/gitlab-go/protected_branches"
"log"
)
// ProtectBranchesAll 保护所有仓库分支
func
ProtectBranchesAll
()
*
cli
.
Command
{
return
&
cli
.
Command
{
Name
:
"all"
,
Aliases
:
[]
string
{
"a"
},
Usage
:
"保护所有仓库分支"
,
Flags
:
append
(
flag
.
CommonTokenRequired
(),
flag
.
Owned
(
true
),
flag
.
BranchName
(
true
),
flag
.
PushAccessLevel
(),
flag
.
MergeAccessLevel
(),
flag
.
UnprotectAccessLevel
(),
flag
.
AllowForcePush
(),
flag
.
CodeOwnerApprovalRequired
(),
flag
.
AllowFailure
(),
flag
.
PrintJson
(),
flag
.
PrintTime
()),
Action
:
func
(
context
*
cli
.
Context
)
error
{
var
baseUrl
=
context
.
String
(
constant
.
BaseUrl
)
var
token
=
context
.
String
(
constant
.
Token
)
var
owned
=
context
.
Bool
(
constant
.
Owned
)
var
name
=
context
.
String
(
constant
.
BranchName
)
var
pushAccessLevel
=
context
.
Int
(
constant
.
PushAccessLevel
)
var
mergeAccessLevel
=
context
.
Int
(
constant
.
MergeAccessLevel
)
var
unprotectAccessLevel
=
context
.
Int
(
constant
.
UnprotectAccessLevel
)
var
allowForcePush
=
context
.
Bool
(
constant
.
AllowForcePush
)
var
codeOwnerApprovalRequired
=
context
.
Bool
(
constant
.
CodeOwnerApprovalRequired
)
var
printJson
=
context
.
Bool
(
constant
.
PrintJson
)
var
printTime
=
context
.
Bool
(
constant
.
PrintTime
)
var
allowFailure
=
context
.
Bool
(
constant
.
AllowFailure
)
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
=
protected_branches
.
ProtectRepositoryBranches
(
baseUrl
,
token
,
project
.
ID
,
name
,
pushAccessLevel
,
mergeAccessLevel
,
unprotectAccessLevel
,
allowForcePush
,
codeOwnerApprovalRequired
,
printJson
,
printTime
,
allowFailure
)
if
err
!=
nil
{
return
err
}
}
return
nil
},
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录