Compare commits

...

18 Commits

Author SHA1 Message Date
徐晓伟 9a00cb52ed 项目:列出所有项目:当前用户明确拥有的项目 2024-03-09 17:54:38 +08:00
徐晓伟 f2454e84f6 🐛 根据项目路径/ID、流水线IID范围删除作业产物和作业日志(混合命令,多接口命令,立即删除):允许失败 2024-01-22 13:14:47 +08:00
徐晓伟 02d1e0e4f4 保护仓库分支:保护所有仓库分支 2024-01-16 14:55:14 +08:00
徐晓伟 2143aa297a 受保护的分支 API:保护仓库分支 2024-01-16 14:29:02 +08:00
徐晓伟 6720210458 受保护的分支 API:列出受保护的分支 2024-01-16 13:49:51 +08:00
徐晓伟 6cff8dc2fa 👷 发布 framagit 2024-01-16 13:21:26 +08:00
徐晓伟 6f82a92961 📝 增加命令文档 2024-01-16 11:10:39 +08:00
徐晓伟 bfa8b974ea 创建项目级别 CI/CD 变量:所有项目创建新变量 2024-01-16 11:05:19 +08:00
徐晓伟 7ee5c0ade9 🐛 修正参数名 2024-01-16 11:03:52 +08:00
徐晓伟 741e281185 🐛 修正参数 2024-01-16 11:02:37 +08:00
徐晓伟 c63941d072 🐛 修正参数名 2024-01-16 11:00:17 +08:00
徐晓伟 25860b000e 项目级别 CI/CD 变量 API:创建变量 2024-01-16 10:21:14 +08:00
徐晓伟 0260f9bb39 项目级别 CI/CD 变量 API:列出项目变量 2024-01-16 09:32:49 +08:00
徐晓伟 026a48c896 🐛 Name、Aliases 2024-01-16 09:16:47 +08:00
徐晓伟 d2f80a1ee7 📝 调整顺序 2024-01-16 09:11:27 +08:00
徐晓伟 0fc7e38d58 增加 Aliases 2024-01-16 09:11:02 +08:00
徐晓伟 904ed2cf6a 📝 鸣谢 2024-01-16 08:46:23 +08:00
徐晓伟 54d084af8b 创建新环境:所有项目创建新环境 2024-01-15 17:44:11 +08:00
24 changed files with 1509 additions and 224 deletions

View File

@ -210,7 +210,14 @@ jobs:
- name: Release GitLab - name: Release GitLab
run: | run: |
./cicd-release-linux-amd64 pre-release gitlab --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitlab-repository=$GITHUB_REPOSITORY --gitlab-username=$GITHUB_ACTOR --gitlab-token=${{ secrets.PRIVATE_GITLAB_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --package-name=cicd-release --artifacts=gitlab-go-windows-amd64.exe --artifacts=gitlab-go-windows-arm64.exe --artifacts=gitlab-go-linux-amd64 --artifacts=gitlab-go-linux-arm64 --artifacts=gitlab-go-darwin-amd64 --artifacts=gitlab-go-darwin-arm64 --artifacts=gitlab-go-loong64 ./cicd-release-linux-amd64 pre-release gitlab --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitlab-repository=$GITHUB_REPOSITORY --gitlab-username=$GITHUB_ACTOR --gitlab-token=${{ secrets.PRIVATE_GITLAB_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --package-name=cicd-release --artifacts=gitlab-go-windows-amd64.exe --artifacts=gitlab-go-windows-arm64.exe --artifacts=gitlab-go-linux-amd64 --artifacts=gitlab-go-linux-arm64 --artifacts=gitlab-go-darwin-amd64 --artifacts=gitlab-go-darwin-arm64 --artifacts=gitlab-go-loong64 --gitlab-export-assets-file-name=gitlab-release-assets.json
- name: Upload Artifactsgitlab-release-assets.json
uses: actions/upload-artifact@v3
with:
name: gitlab-release-assets
path: |
gitlab-release-assets.json
release-gitlink: release-gitlink:
needs: build needs: build
@ -246,14 +253,58 @@ jobs:
- name: Release GitLink - name: Release GitLink
run: | run: |
./cicd-release-linux-amd64 pre-release gitlink --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitlink-repository=$GITHUB_REPOSITORY --gitlink-username=${{ secrets.PRIVATE_GITLINK_USERNAME }} --gitlink-token=${{ secrets.PRIVATE_GITLINK_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --artifacts=gitlab-go-windows-amd64.exe --artifacts=gitlab-go-windows-arm64.exe --artifacts=gitlab-go-linux-amd64 --artifacts=gitlab-go-linux-arm64 --artifacts=gitlab-go-darwin-amd64 --artifacts=gitlab-go-darwin-arm64 --artifacts=gitlab-go-loong64 --gitlink-cookie=${{ secrets.PRIVATE_GITLINK_COOKIE }} --gitlink-export-assets-file-name=cicd-release-assets.json ./cicd-release-linux-amd64 pre-release gitlink --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitlink-repository=$GITHUB_REPOSITORY --gitlink-username=${{ secrets.PRIVATE_GITLINK_USERNAME }} --gitlink-token=${{ secrets.PRIVATE_GITLINK_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --artifacts=gitlab-go-windows-amd64.exe --artifacts=gitlab-go-windows-arm64.exe --artifacts=gitlab-go-linux-amd64 --artifacts=gitlab-go-linux-arm64 --artifacts=gitlab-go-darwin-amd64 --artifacts=gitlab-go-darwin-arm64 --artifacts=gitlab-go-loong64 --gitlink-cookie=${{ secrets.PRIVATE_GITLINK_COOKIE }} --gitlink-export-assets-file-name=gitlink-release-assets.json
- name: Upload Artifactscicd-release-assets.json - name: Upload Artifactsgitlink-release-assets.json
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: cicd-release-assets name: gitlink-release-assets
path: | path: |
cicd-release-assets.json gitlink-release-assets.json
release-framagit:
needs:
- build
- release-gitlab
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# 获取所有的代码历史记录,包括分支和标签
fetch-depth: 0
- name: Download Artifactsxuxiaowei-com-cn/cicd-release
uses: actions/download-artifact@v3
with:
name: cicd-release
path: .
- name: Download Artifacts
uses: actions/download-artifact@v3
with:
name: gitlab-go
path: .
- name: ls -l
run: ls -l
- name: chmod +x cicd-release-linux-amd64
run: chmod +x cicd-release-linux-amd64
- name: ls -l
run: ls -l
- name: Download Artifactsgitlab-release-assets.json
uses: actions/download-artifact@v3
with:
name: gitlab-release-assets
path: .
- name: Release FramaGit
run: |
./cicd-release-linux-amd64 pre-release gitlab --gitlab-instance=https://framagit.org --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitlab-repository=$GITHUB_REPOSITORY --gitlab-username=xuxiaowei --gitlab-token=${{ secrets.PRIVATE_FRAMAGIT_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --gitlab-import-assets-file-name=gitlab-release-assets.json
release-gitee: release-gitee:
needs: needs:
@ -289,12 +340,12 @@ jobs:
- name: ls -l - name: ls -l
run: ls -l run: ls -l
- name: Download Artifactscicd-release-assets.json - name: Download Artifactsgitlink-release-assets.json
uses: actions/download-artifact@v3 uses: actions/download-artifact@v3
with: with:
name: cicd-release-assets name: gitlink-release-assets
path: . path: .
- name: Release Gitee - name: Release Gitee
run: | run: |
./cicd-release-linux-amd64 pre-release gitee --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitee-repository=$GITHUB_REPOSITORY --gitee-username=$GITHUB_ACTOR --gitee-token=${{ secrets.PRIVATE_GITEE_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --gitlink-export-assets-file-name=cicd-release-assets.json ./cicd-release-linux-amd64 pre-release gitee --release-name=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --tag=v0.0.0-${{ needs.build.outputs.YEAR_MONTH_DAY_HOUR_MINUTE }} --auto-create-tag --gitee-repository=$GITHUB_REPOSITORY --gitee-username=$GITHUB_ACTOR --gitee-token=${{ secrets.PRIVATE_GITEE_TOKEN }} --release-body=${{ needs.build.outputs.RELEASE_BODY }} --gitlink-export-assets-file-name=gitlink-release-assets.json

405
README.md
View File

@ -190,22 +190,27 @@ AUTHOR:
徐晓伟 <xuxiaowei@xuxiaowei.com.cn> 徐晓伟 <xuxiaowei@xuxiaowei.com.cn>
COMMANDS: COMMANDS:
access-request, access-requests, ar 群组和项目访问请求 API中文文档https://docs.gitlab.cn/jh/api/access_requests.html 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 board, boards 项目议题板 API中文文档https://docs.gitlab.cn/jh/api/boards.html
container-registry, cr 容器仓库 API中文文档https://docs.gitlab.cn/jh/api/container_registry.html container-registry, cr 容器仓库 API中文文档https://docs.gitlab.cn/jh/api/container_registry.html
environments, env 环境 API中文文档https://docs.gitlab.cn/jh/api/environments.html environments, environment, env 环境 API中文文档https://docs.gitlab.cn/jh/api/environments.html
instance-level-ci-variable, instance-level-ci-variables, ilcv 实例级 CI/CD 变量 API中文文档https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html instance-level-ci-variables, instance-level-ci-variable, 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 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 job-artifact, job-artifacts, ja 作业产物 API中文文档https://docs.gitlab.cn/jh/api/job_artifacts.html
job, jobs, j 作业 API中文文档https://docs.gitlab.cn/jh/api/jobs.html job, jobs, j 作业 API中文文档https://docs.gitlab.cn/jh/api/jobs.html
pipeline, pipelines, pl 流水线 API中文文档https://docs.gitlab.cn/jh/api/pipelines.html pipeline, pipelines, pl 流水线 API中文文档https://docs.gitlab.cn/jh/api/pipelines.html
project, projects, p 项目 API中文文档https://docs.gitlab.cn/jh/api/projects.html project-level-variables, project-level-variable, plv 项目级别 CI/CD 变量 API中文文档https://docs.gitlab.cn/jh/api/project_level_variables.html
mix-delete, mix-rm 删除(混合命令,多接口命令) project, projects, p 项目 API中文文档https://docs.gitlab.cn/jh/api/projects.html
mix-archive 归档(混合命令,多接口命令) protected-branches, pb 受保护的分支 API中文文档https://docs.gitlab.cn/jh/api/protected_branches.html
mix-unarchive 取消归档(混合命令,多接口命令) mix-archive 归档(混合命令,多接口命令)
mix-export 导出(混合命令,多接口命令) mix-create-project-level-variables 创建项目级别 CI/CD 变量(混合命令,多接口命令)
mix-transfer 转移(混合命令,多接口命令) mix-delete, mix-rm 删除(混合命令,多接口命令)
help, h Shows a list of commands or help for one command 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
GLOBAL OPTIONS: GLOBAL OPTIONS:
--help, -h show help --help, -h show help
@ -223,7 +228,7 @@ COPYRIGHT:
gitlab-go access-request - 群组和项目访问请求 API中文文档https://docs.gitlab.cn/jh/api/access_requests.html gitlab-go access-request - 群组和项目访问请求 API中文文档https://docs.gitlab.cn/jh/api/access_requests.html
USAGE: USAGE:
gitlab-go access-request command [command options] [arguments...] gitlab-go access-request command [command options]
COMMANDS: COMMANDS:
group, groups 为群组列出访问请求 group, groups 为群组列出访问请求
@ -249,7 +254,7 @@ COPYRIGHT:
gitlab-go board - 项目议题板 API中文文档https://docs.gitlab.cn/jh/api/boards.html gitlab-go board - 项目议题板 API中文文档https://docs.gitlab.cn/jh/api/boards.html
USAGE: USAGE:
gitlab-go board command [command options] [arguments...] gitlab-go board command [command options]
COMMANDS: COMMANDS:
list 列出项目议题板 list 列出项目议题板
@ -266,6 +271,36 @@ COPYRIGHT:
--help, -h show help --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]
COMMANDS:
list 列出仓库内存储库
list-tags 列出仓库里存储库的标签
get-tag 获取仓库里存储库的某个标签的详情
delete-tag, rm-tag 删除仓库里存储库的某个标签
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 编码的路径
--repository value 仓库里存储库的 ID
--tag-name value 标签的名称
--help, -h show help
```
- [environments 环境 API](https://docs.gitlab.cn/jh/api/environments.html) - [environments 环境 API](https://docs.gitlab.cn/jh/api/environments.html)
```shell ```shell
@ -286,7 +321,7 @@ COPYRIGHT:
--token value your_access_token --token value your_access_token
--id value 项目 ID 或 URL 编码的路径 --id value 项目 ID 或 URL 编码的路径
--name value 环境名称 --name value 环境名称
--external_url value 该环境的链接位置 --external-url value 该环境的链接位置
--tier value 新环境的层级。允许设置的值为 production staging testing development 和 other --tier value 新环境的层级。允许设置的值为 production staging testing development 和 other
--page value 页码默认1中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 1) --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) --per-page value 每页列出的项目数默认20最大100中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 20)
@ -295,45 +330,15 @@ COPYRIGHT:
--help, -h show help --help, -h show help
``` ```
- [container-registry - 容器仓库 API](https://docs.gitlab.cn/jh/api/container_registry.html) - [instance-level-ci-variables - 实例级 CI/CD 变量 API](https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html)
```shell ```shell
$ go run main.go container-registry --help $ go run main.go instance-level-ci-variables --help
NAME: NAME:
gitlab-go container-registry - 容器仓库 API中文文档https://docs.gitlab.cn/jh/api/container_registry.html gitlab-go instance-level-ci-variables - 实例级 CI/CD 变量 API中文文档https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html
USAGE: USAGE:
gitlab-go container-registry command [command options] [arguments...] gitlab-go instance-level-ci-variables command [command options]
COMMANDS:
list 列出仓库内存储库
list-tags 列出仓库里存储库的标签
get-tag 获取仓库里存储库的某个标签的详情
delete-tag, rm-tag 删除仓库里存储库的某个标签
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 编码的路径
--repository value 仓库里存储库的 ID
--tag-name value 标签的名称
--help, -h show help
```
- [instance-level-ci-variable - 实例级 CI/CD 变量 API](https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html)
```shell
$ go run main.go instance-level-ci-variable --help
NAME:
gitlab-go instance-level-ci-variable - 实例级 CI/CD 变量 API中文文档https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html
USAGE:
gitlab-go instance-level-ci-variable command [command options] [arguments...]
COMMANDS: COMMANDS:
list 列出所有实例变量 list 列出所有实例变量
@ -357,7 +362,7 @@ COPYRIGHT:
gitlab-go issue - 议题 API中文文档https://docs.gitlab.cn/jh/api/issues.html gitlab-go issue - 议题 API中文文档https://docs.gitlab.cn/jh/api/issues.html
USAGE: USAGE:
gitlab-go issue command [command options] [arguments...] gitlab-go issue command [command options]
COMMANDS: COMMANDS:
list 列出议题 list 列出议题
@ -410,7 +415,7 @@ COPYRIGHT:
gitlab-go job-artifact - 作业产物 API中文文档https://docs.gitlab.cn/jh/api/job_artifacts.html gitlab-go job-artifact - 作业产物 API中文文档https://docs.gitlab.cn/jh/api/job_artifacts.html
USAGE: USAGE:
gitlab-go job-artifact command [command options] [arguments...] gitlab-go job-artifact command [command options]
COMMANDS: COMMANDS:
get 获取(下载)作业产物 get 获取(下载)作业产物
@ -436,7 +441,7 @@ COPYRIGHT:
gitlab-go job - 作业 API中文文档https://docs.gitlab.cn/jh/api/jobs.html gitlab-go job - 作业 API中文文档https://docs.gitlab.cn/jh/api/jobs.html
USAGE: USAGE:
gitlab-go job command [command options] [arguments...] gitlab-go job command [command options]
COMMANDS: COMMANDS:
list 列出项目作业 list 列出项目作业
@ -470,7 +475,7 @@ COPYRIGHT:
gitlab-go pipeline - 流水线 API中文文档https://docs.gitlab.cn/jh/api/pipelines.html gitlab-go pipeline - 流水线 API中文文档https://docs.gitlab.cn/jh/api/pipelines.html
USAGE: USAGE:
gitlab-go pipeline command [command options] [arguments...] gitlab-go pipeline command [command options]
COMMANDS: COMMANDS:
list 列出项目流水线 list 列出项目流水线
@ -489,6 +494,39 @@ COPYRIGHT:
--help, -h show help --help, -h show help
``` ```
- [project-level-variables 项目级别 CI/CD 变量 API](https://docs.gitlab.cn/jh/api/project_level_variables.html)
```shell
$ go run main.go project-level-variables --help
NAME:
gitlab-go project-level-variables - 项目级别 CI/CD 变量 API中文文档https://docs.gitlab.cn/jh/api/project_level_variables.html
USAGE:
gitlab-go project-level-variables command [command options]
COMMANDS:
list 列出项目变量
create 创建变量
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
--id value 项目 ID 或 URL 编码的路径
--key value 变量的 key。不能超过 255 个字符。仅支持 A-Z、a-z、0-9 和 _
--value value 变量的 value
--variable-type value 变量类型。可用类型为env_var 和 file (default: "env_var")
--protected 变量是否受保护。 (default: false)
--masked 变量是否隐藏。 (default: false)
--raw 变量是否被视为原始字符串。当为 true 时,值中的变量不会扩展 (default: false)
--environment-scope value 变量的 environment_scope。 (default: "*")
--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)
--help, -h show help
```
- [project - 项目 API](https://docs.gitlab.cn/jh/api/projects.html) - [project - 项目 API](https://docs.gitlab.cn/jh/api/projects.html)
```shell ```shell
@ -497,7 +535,7 @@ COPYRIGHT:
gitlab-go project - 项目 API中文文档https://docs.gitlab.cn/jh/api/projects.html gitlab-go project - 项目 API中文文档https://docs.gitlab.cn/jh/api/projects.html
USAGE: USAGE:
gitlab-go project command [command options] [arguments...] gitlab-go project command [command options]
COMMANDS: COMMANDS:
list 列出所有项目 list 列出所有项目
@ -506,6 +544,7 @@ COPYRIGHT:
OPTIONS: OPTIONS:
--base-url value 实例地址例如https://gitlab.xuxiaowei.com.cn/api/v4 (default: "https://gitlab.com/api/v4") [%CI_API_V4_URL%] --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 --token value your_access_token
--owned 当前用户明确拥有的项目。 (default: false)
--sort value 按照 asc 或者 desc 排序 (default: "desc") --sort value 按照 asc 或者 desc 排序 (default: "desc")
--page value 页码默认1中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 1) --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) --per-page value 每页列出的项目数默认20最大100中文文档 https://docs.gitlab.cn/jh/api/rest/index.html#pagination (default: 20)
@ -517,7 +556,117 @@ COPYRIGHT:
--help, -h show help --help, -h show help
``` ```
- 删除(混合命令,多接口命令) - [protected-branches 受保护的分支 API](https://docs.gitlab.cn/jh/api/protected_branches.html)
```shell
$ go run main.go protected-branches --help
NAME:
gitlab-go protected-branches - 受保护的分支 API中文文档https://docs.gitlab.cn/jh/api/protected_branches.html
USAGE:
gitlab-go protected-branches command [command options]
COMMANDS:
list 列出受保护的分支
protect 保护仓库分支
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
--id value 项目 ID 或 URL 编码的路径
--search value 要搜索的受保护分支的名称或部分名称
--name value 分支或通配符的名称
--push-access-level value 允许推送的访问级别默认值40维护者角色合法值
0NoPermissions
5MinimalAccessPermissions
10GuestPermissions
20ReporterPermissions
30DeveloperPermissions
40MaintainerPermissions
50OwnerPermissions
60AdminPermissions
(default: 40)
--merge-access-level value 允许合并的访问级别默认值40维护者角色合法值
0NoPermissions
5MinimalAccessPermissions
10GuestPermissions
20ReporterPermissions
30DeveloperPermissions
40MaintainerPermissions
50OwnerPermissions
60AdminPermissions
(default: 40)
--unprotect-access-level value 允许取消保护的访问级别默认值40维护者角色合法值
0NoPermissions
5MinimalAccessPermissions
10GuestPermissions
20ReporterPermissions
30DeveloperPermissions
40MaintainerPermissions
50OwnerPermissions
60AdminPermissions
(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)
--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)
--help, -h show help
```
- mix-archive 归档(混合命令,多接口命令)
```shell
$ go run main.go mix-archive --help
NAME:
gitlab-go mix-archive - 归档(混合命令,多接口命令)
USAGE:
gitlab-go mix-archive command [command options]
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
```
- mix-create-project-level-variables 创建项目级别 CI/CD 变量(混合命令,多接口命令)
```shell
$ go run main.go mix-create-project-level-variables --help
NAME:
gitlab-go mix-create-project-level-variables - 创建项目级别 CI/CD 变量(混合命令,多接口命令)
USAGE:
gitlab-go mix-create-project-level-variables 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
--key value 变量的 key。不能超过 255 个字符。仅支持 A-Z、a-z、0-9 和 _
--value value 变量的 value
--variable-type value 变量类型。可用类型为env_var 和 file (default: "env_var")
--protected 变量是否受保护。 (default: false)
--masked 变量是否隐藏。 (default: false)
--raw 变量是否被视为原始字符串。当为 true 时,值中的变量不会扩展 (default: false)
--environment-scope value 变量的 environment_scope。 (default: "*")
--print-json 打印 JSON (default: false)
--print-time 打印时间 (default: false)
--help, -h show help
```
- mix-delete 删除(混合命令,多接口命令)
```shell ```shell
$ go run main.go mix-delete --help $ go run main.go mix-delete --help
@ -525,7 +674,7 @@ COPYRIGHT:
gitlab-go mix-delete - 删除(混合命令,多接口命令) gitlab-go mix-delete - 删除(混合命令,多接口命令)
USAGE: USAGE:
gitlab-go mix-delete command [command options] [arguments...] gitlab-go mix-delete command [command options]
COMMANDS: COMMANDS:
artifact, artifacts 根据项目路径/ID、流水线IID范围删除产物混合命令多接口命令立即删除 artifact, artifacts 根据项目路径/ID、流水线IID范围删除产物混合命令多接口命令立即删除
@ -546,49 +695,35 @@ COPYRIGHT:
多个数字使用英文逗号隔开1,2,3,7,8,15 多个数字使用英文逗号隔开1,2,3,7,8,15
支持范围5-10, 支持范围5-10,
支持范围方向选择:-10小于等于10从 0 到 10214-大于等于214从 214 到 214 + 10000数据范围不超过 10000 支持范围方向选择:-10小于等于10从 0 到 10214-大于等于214从 214 到 214 + 10000数据范围不超过 10000
--allow-failure 允许失败 (default: false)
--help, -h show help --help, -h show help
``` ```
- 归档(混合命令,多接口命令) - mix-create-environments 创建新环境(混合命令,多接口命令)
```shell ```shell
$ go run main.go mix-archive --help $ go run main.go mix-create-environments --help
NAME: NAME:
gitlab-go mix-archive - 归档(混合命令,多接口命令) gitlab-go mix-create-environments - 创建新环境(混合命令,多接口命令)
USAGE: USAGE:
gitlab-go mix-archive command [command options] [arguments...] gitlab-go mix-create-environments command [command options]
COMMANDS: COMMANDS:
all 归档所有项目(混合命令,多接口命令) all, a 所有项目创建新环境
help, h Shows a list of commands or help for one command help, h Shows a list of commands or help for one command
OPTIONS: OPTIONS:
--base-url value 实例地址例如https://gitlab.xuxiaowei.com.cn/api/v4 (default: "https://gitlab.com/api/v4") [%CI_API_V4_URL%] --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 --token value your_access_token
--owned 当前用户明确拥有的项目。 (default: false) --owned 当前用户明确拥有的项目。 (default: false)
--help, -h show help --name value 环境名称
``` --external-url value 该环境的链接位置
--tier value 新环境的层级。允许设置的值为 production staging testing development 和 other
- 取消归档(混合命令,多接口命令) --allow-failure 允许失败 (default: false)
--print-json 打印 JSON (default: false)
```shell --print-time 打印时间 (default: false)
$ go run main.go mix-unarchive --help --help, -h show help
NAME:
gitlab-go mix-unarchive - 取消归档(混合命令,多接口命令)
USAGE:
gitlab-go mix-unarchive 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
``` ```
- 导出(混合命令,多接口命令) - 导出(混合命令,多接口命令)
@ -599,7 +734,7 @@ COPYRIGHT:
gitlab-go mix-export - 导出(混合命令,多接口命令) gitlab-go mix-export - 导出(混合命令,多接口命令)
USAGE: USAGE:
gitlab-go mix-export command [command options] [arguments...] gitlab-go mix-export command [command options]
COMMANDS: COMMANDS:
all, a 导出所有(混合命令,多接口命令) all, a 导出所有(混合命令,多接口命令)
@ -620,6 +755,62 @@ COPYRIGHT:
--help, -h show help --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维护者角色合法值
0NoPermissions
5MinimalAccessPermissions
10GuestPermissions
20ReporterPermissions
30DeveloperPermissions
40MaintainerPermissions
50OwnerPermissions
60AdminPermissions
(default: 40)
--merge-access-level value 允许合并的访问级别默认值40维护者角色合法值
0NoPermissions
5MinimalAccessPermissions
10GuestPermissions
20ReporterPermissions
30DeveloperPermissions
40MaintainerPermissions
50OwnerPermissions
60AdminPermissions
(default: 40)
--unprotect-access-level value 允许取消保护的访问级别默认值40维护者角色合法值
0NoPermissions
5MinimalAccessPermissions
10GuestPermissions
20ReporterPermissions
30DeveloperPermissions
40MaintainerPermissions
50OwnerPermissions
60AdminPermissions
(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 ```shell
@ -628,7 +819,7 @@ COPYRIGHT:
gitlab-go mix-transfer - 转移(混合命令,多接口命令) gitlab-go mix-transfer - 转移(混合命令,多接口命令)
USAGE: USAGE:
gitlab-go mix-transfer command [command options] [arguments...] gitlab-go mix-transfer command [command options]
COMMANDS: COMMANDS:
all, a 将一个命令空间的项目转移到新的命名空间 all, a 将一个命令空间的项目转移到新的命名空间
@ -644,6 +835,27 @@ COPYRIGHT:
--help, -h show help --help, -h show help
``` ```
- 取消归档(混合命令,多接口命令)
```shell
$ go run main.go mix-unarchive --help
NAME:
gitlab-go mix-unarchive - 取消归档(混合命令,多接口命令)
USAGE:
gitlab-go mix-unarchive command [command options]
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 ### test
```shell ```shell
@ -708,3 +920,12 @@ go build
go build -o buildinfo/buildinfo buildinfo/buildinfo.go go build -o buildinfo/buildinfo buildinfo/buildinfo.go
GOOS=darwin GOARCH=arm64 go build -v -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$(buildinfo/buildinfo commitBranch) -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=darwin/arm64 -X main.CiPipelineId= -X main.CiJobId=" -trimpath -o gitlab-go-darwin-arm64 . GOOS=darwin GOARCH=arm64 go build -v -ldflags "-s -w -buildid= -X main.BuildDate=$(buildinfo/buildinfo now) -X main.Compiler= -X main.GitCommitBranch=$(buildinfo/buildinfo commitBranch) -X main.GitCommitSha=$(buildinfo/buildinfo commitSha) -X main.GitCommitShortSha=$(buildinfo/buildinfo commitShortSha) -X main.GitCommitTag=$(buildinfo/buildinfo commitTag) -X main.GitCommitTimestamp=$(buildinfo/buildinfo commitTimestamp) -X main.GitTreeState=$(buildinfo/buildinfo git-tree-state) -X main.GitVersion=$(buildinfo/buildinfo commitTag) -X main.GoVersion=$(buildinfo/buildinfo goShortVersion) -X main.Major= -X main.Minor= -X main.Revision= -X main.Platform=darwin/arm64 -X main.CiPipelineId= -X main.CiJobId=" -trimpath -o gitlab-go-darwin-arm64 .
``` ```
## 鸣谢
1. 感谢 [![jetbrains](./static/jb_beam.svg)](https://www.jetbrains.com/)
提供开发工具 [![IDEA](./static/IntelliJ_IDEA_icon.svg)](https://www.jetbrains.com/idea) 的免费授权
## Stargazers over time
[![Stargazers over time](https://starchart.cc/xuxiaowei-com-cn/gitlab-go.svg)](https://starchart.cc/xuxiaowei-com-cn/gitlab-go)

View File

@ -1,37 +1,51 @@
package constant package constant
const ( const (
Token = "token" Token = "token"
BaseUrl = "base-url" BaseUrl = "base-url"
BaseUrlDefault = "https://gitlab.com/api/v4" BaseUrlDefault = "https://gitlab.com/api/v4"
Id = "id" Id = "id"
JobIdRange = "job-id-range" JobIdRange = "job-id-range"
IIdRange = "iid-range" IIdRange = "iid-range"
Repository = "repository" Repository = "repository"
TagName = "tag-name" TagName = "tag-name"
JobId = "job-id" JobId = "job-id"
ArtifactsName = "artifacts-name" ArtifactsName = "artifacts-name"
Sort = "sort" Sort = "sort"
SortDefault = "desc" SortDefault = "desc"
Page = "page" Page = "page"
PerPage = "per-page" PerPage = "per-page"
PrintJson = "print-json" PrintJson = "print-json"
PrintJsonDefault = false PrintJsonDefault = false
PrintTime = "print-time" PrintTime = "print-time"
PrintTimeDefault = false PrintTimeDefault = false
Scope = "scope" Scope = "scope"
IssueId = "issue-id" IssueId = "issue-id"
IssueIdRange = "issue-id-range" IssueIdRange = "issue-id-range"
Recursion = "recursion" Recursion = "recursion"
Owned = "owned" Owned = "owned"
NamespaceSource = "namespace-source" NamespaceSource = "namespace-source"
NamespaceTarget = "namespace-target" NamespaceTarget = "namespace-target"
ExportFolder = "export-folder" ExportFolder = "export-folder"
SkipProjectPath = "skip-project-path" SkipProjectPath = "skip-project-path"
SkipProjectWikiPath = "skip-project-wiki-path" SkipProjectWikiPath = "skip-project-wiki-path"
AutoSkipExistFolder = "auto-skip-exist-folder" AutoSkipExistFolder = "auto-skip-exist-folder"
AllowFailure = "allow-failure" AllowFailure = "allow-failure"
EnvName = "name" EnvName = "name"
EnvExternalUrl = "external_url" EnvExternalUrl = "external-url"
EnvTier = "tier" EnvTier = "tier"
VariableKey = "key"
VariableValue = "value"
VariableType = "variable-type"
VariableProtected = "protected"
VariableMasked = "masked"
VariableRaw = "raw"
VariableEnvironmentScope = "environment-scope"
ProtectedBranchesSearch = "search"
BranchName = "name"
PushAccessLevel = "push-access-level"
MergeAccessLevel = "merge-access-level"
UnprotectAccessLevel = "unprotect-access-level"
AllowForcePush = "allow-force-push"
CodeOwnerApprovalRequired = "code-owner-approval-required"
) )

View File

@ -27,75 +27,82 @@ func Create() *cli.Command {
var printJson = context.Bool(constant.PrintJson) var printJson = context.Bool(constant.PrintJson)
var printTime = context.Bool(constant.PrintTime) var printTime = context.Bool(constant.PrintTime)
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl)) return CreateEnvironment(baseUrl, token, id, name, externalURL, tier, printJson, printTime, false)
if err != nil {
return err
}
opt := &gitlab.CreateEnvironmentOptions{
Name: &name,
ExternalURL: &externalURL,
}
if tier != "" {
opt.Tier = &tier
}
environment, response, err := gitClient.Environments.CreateEnvironment(id, opt)
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
fmt.Println("")
if printJson {
if printTime {
jsonData, err := json.Marshal(environment)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
} else {
jsonData, err := json.Marshal(environment)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
} else {
if printTime {
log.Printf("ID: %d\n", environment.ID)
log.Printf("Name: %s\n", environment.Name)
log.Printf("Slug: %s\n", environment.Slug)
log.Printf("State: %s\n", environment.State)
log.Printf("Tier: %s\n", environment.Tier)
log.Printf("ExternalURL: %s\n", environment.ExternalURL)
log.Printf("CreatedAt: %s\n", environment.CreatedAt)
log.Printf("UpdatedAt: %s\n", environment.UpdatedAt)
fmt.Println("")
} else {
fmt.Printf("ID: %d\n", environment.ID)
fmt.Printf("Name: %s\n", environment.Name)
fmt.Printf("Slug: %s\n", environment.Slug)
fmt.Printf("State: %s\n", environment.State)
fmt.Printf("Tier: %s\n", environment.Tier)
fmt.Printf("ExternalURL: %s\n", environment.ExternalURL)
fmt.Printf("CreatedAt: %s\n", environment.CreatedAt)
fmt.Printf("UpdatedAt: %s\n", environment.UpdatedAt)
fmt.Println("")
}
}
return nil
}, },
} }
} }
func CreateEnvironment(baseUrl string, token string, id interface{}, name string, externalURL string, tier string, printJson bool, printTime bool, allowFailure bool) error {
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl))
if err != nil {
return err
}
opt := &gitlab.CreateEnvironmentOptions{
Name: &name,
ExternalURL: &externalURL,
}
if tier != "" {
opt.Tier = &tier
}
environment, response, err := gitClient.Environments.CreateEnvironment(id, opt)
if err != nil {
if allowFailure {
return nil
}
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
fmt.Println("")
if printJson {
if printTime {
jsonData, err := json.Marshal(environment)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
} else {
jsonData, err := json.Marshal(environment)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
} else {
if printTime {
log.Printf("ID: %d\n", environment.ID)
log.Printf("Name: %s\n", environment.Name)
log.Printf("Slug: %s\n", environment.Slug)
log.Printf("State: %s\n", environment.State)
log.Printf("Tier: %s\n", environment.Tier)
log.Printf("ExternalURL: %s\n", environment.ExternalURL)
log.Printf("CreatedAt: %s\n", environment.CreatedAt)
log.Printf("UpdatedAt: %s\n", environment.UpdatedAt)
fmt.Println("")
} else {
fmt.Printf("ID: %d\n", environment.ID)
fmt.Printf("Name: %s\n", environment.Name)
fmt.Printf("Slug: %s\n", environment.Slug)
fmt.Printf("State: %s\n", environment.State)
fmt.Printf("Tier: %s\n", environment.Tier)
fmt.Printf("ExternalURL: %s\n", environment.ExternalURL)
fmt.Printf("CreatedAt: %s\n", environment.CreatedAt)
fmt.Printf("UpdatedAt: %s\n", environment.UpdatedAt)
fmt.Println("")
}
}
return nil
}

View File

@ -9,7 +9,7 @@ import (
func Environments() *cli.Command { func Environments() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "environments", Name: "environments",
Aliases: []string{"env"}, Aliases: []string{"environment", "env"},
Usage: "环境 API中文文档https://docs.gitlab.cn/jh/api/environments.html", Usage: "环境 API中文文档https://docs.gitlab.cn/jh/api/environments.html",
Flags: append(flag.Common(), flag.Id(false), flag.EnvName(false), flag.EnvExternalUrl(), flag.EnvTier(), Flags: append(flag.Common(), flag.Id(false), flag.EnvName(false), flag.EnvExternalUrl(), flag.EnvTier(),
flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime()), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime()),

View File

@ -271,3 +271,138 @@ func EnvTier() cli.Flag {
Usage: "新环境的层级。允许设置的值为 production staging testing development 和 other", Usage: "新环境的层级。允许设置的值为 production staging testing development 和 other",
} }
} }
func VariableKey(required bool) cli.Flag {
return &cli.StringFlag{
Name: constant.VariableKey,
Usage: "变量的 key。不能超过 255 个字符。仅支持 A-Z、a-z、0-9 和 _",
Required: required,
}
}
func VariableValue(required bool) cli.Flag {
return &cli.StringFlag{
Name: constant.VariableValue,
Usage: "变量的 value",
Required: required,
}
}
func VariableType() cli.Flag {
return &cli.StringFlag{
Name: constant.VariableType,
Usage: "变量类型。可用类型为env_var 和 file",
Value: "env_var",
}
}
func VariableProtected() cli.Flag {
return &cli.BoolFlag{
Name: constant.VariableProtected,
Usage: "变量是否受保护。",
Value: false,
}
}
func VariableMasked() cli.Flag {
return &cli.BoolFlag{
Name: constant.VariableMasked,
Usage: "变量是否隐藏。",
Value: false,
}
}
func VariableRaw() cli.Flag {
return &cli.BoolFlag{
Name: constant.VariableRaw,
Usage: "变量是否被视为原始字符串。当为 true 时,值中的变量不会扩展",
Value: false,
}
}
func VariableEnvironmentScope() cli.Flag {
return &cli.StringFlag{
Name: constant.VariableEnvironmentScope,
Usage: "变量的 environment_scope。",
Value: "*",
}
}
func ProtectedBranchesSearch() cli.Flag {
return &cli.StringFlag{
Name: constant.ProtectedBranchesSearch,
Usage: "要搜索的受保护分支的名称或部分名称",
}
}
func BranchName(required bool) cli.Flag {
return &cli.StringFlag{
Name: constant.BranchName,
Usage: "分支或通配符的名称",
Required: required,
}
}
func PushAccessLevel() cli.Flag {
return &cli.IntFlag{
Name: constant.PushAccessLevel,
Usage: "允许推送的访问级别默认值40维护者角色合法值\n\t" +
"0NoPermissions\n\t" +
"5MinimalAccessPermissions\n\t" +
"10GuestPermissions\n\t" +
"20ReporterPermissions\n\t" +
"30DeveloperPermissions\n\t" +
"40MaintainerPermissions\n\t" +
"50OwnerPermissions\n\t" +
"60AdminPermissions\n\t",
Value: 40,
}
}
func MergeAccessLevel() cli.Flag {
return &cli.IntFlag{
Name: constant.MergeAccessLevel,
Usage: "允许合并的访问级别默认值40维护者角色合法值\n\t" +
"0NoPermissions\n\t" +
"5MinimalAccessPermissions\n\t" +
"10GuestPermissions\n\t" +
"20ReporterPermissions\n\t" +
"30DeveloperPermissions\n\t" +
"40MaintainerPermissions\n\t" +
"50OwnerPermissions\n\t" +
"60AdminPermissions\n\t",
Value: 40,
}
}
func UnprotectAccessLevel() cli.Flag {
return &cli.IntFlag{
Name: constant.UnprotectAccessLevel,
Usage: "允许取消保护的访问级别默认值40维护者角色合法值\n\t" +
"0NoPermissions\n\t" +
"5MinimalAccessPermissions\n\t" +
"10GuestPermissions\n\t" +
"20ReporterPermissions\n\t" +
"30DeveloperPermissions\n\t" +
"40MaintainerPermissions\n\t" +
"50OwnerPermissions\n\t" +
"60AdminPermissions\n\t",
Value: 40,
}
}
func AllowForcePush() cli.Flag {
return &cli.BoolFlag{
Name: constant.AllowForcePush,
Usage: "启用后,可以推送到该分支的成员也可以强制推送",
Value: false,
}
}
func CodeOwnerApprovalRequired() cli.Flag {
return &cli.BoolFlag{
Name: constant.CodeOwnerApprovalRequired,
Usage: "如果分支在 CODEOWNERS https://docs.gitlab.cn/jh/user/project/codeowners/index.html 文件中则阻止推送到此分支。默认值false",
Value: false,
}
}

View File

@ -8,8 +8,8 @@ import (
// InstanceLevelCiVariables 实例级 CI/CD 变量 API https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html // InstanceLevelCiVariables 实例级 CI/CD 变量 API https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html
func InstanceLevelCiVariables() *cli.Command { func InstanceLevelCiVariables() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "instance-level-ci-variable", Name: "instance-level-ci-variables",
Aliases: []string{"instance-level-ci-variables", "ilcv"}, Aliases: []string{"instance-level-ci-variable", "ilcv"},
Usage: "实例级 CI/CD 变量 API中文文档https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html", Usage: "实例级 CI/CD 变量 API中文文档https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html",
Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime()), Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime()),
Subcommands: []*cli.Command{ Subcommands: []*cli.Command{

11
main.go
View File

@ -13,7 +13,9 @@ import (
"github.com/xuxiaowei-com-cn/gitlab-go/jobs" "github.com/xuxiaowei-com-cn/gitlab-go/jobs"
"github.com/xuxiaowei-com-cn/gitlab-go/mix" "github.com/xuxiaowei-com-cn/gitlab-go/mix"
"github.com/xuxiaowei-com-cn/gitlab-go/pipelines" "github.com/xuxiaowei-com-cn/gitlab-go/pipelines"
"github.com/xuxiaowei-com-cn/gitlab-go/project_level_variables"
"github.com/xuxiaowei-com-cn/gitlab-go/projects" "github.com/xuxiaowei-com-cn/gitlab-go/projects"
"github.com/xuxiaowei-com-cn/gitlab-go/protected_branches"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
"log" "log"
"os" "os"
@ -77,12 +79,17 @@ func main() {
job_artifacts.JobsArtifacts(), job_artifacts.JobsArtifacts(),
jobs.Jobs(), jobs.Jobs(),
pipelines.Pipelines(), pipelines.Pipelines(),
project_level_variables.ProjectLevelVariables(),
projects.Projects(), projects.Projects(),
mix.Delete(), protected_branches.ProtectedBranches(),
mix.Archive(), mix.Archive(),
mix.Unarchive(), mix.CreateProjectLevelVariables(),
mix.Delete(),
mix.Environments(),
mix.Export(), mix.Export(),
mix.ProtectBranches(),
mix.Transfer(), mix.Transfer(),
mix.Unarchive(),
}, },
} }

View File

@ -18,7 +18,8 @@ func DeleteJobs() *cli.Command {
Name: "job", Name: "job",
Aliases: []string{"jobs"}, Aliases: []string{"jobs"},
Usage: "根据项目路径/ID、流水线IID范围删除作业产物和作业日志混合命令多接口命令立即删除", Usage: "根据项目路径/ID、流水线IID范围删除作业产物和作业日志混合命令多接口命令立即删除",
Flags: append(flag.CommonTokenRequired(), flag.Sort(), flag.Page(), flag.PerPage(), flag.Id(true), flag.IIdRange(true)), Flags: append(flag.CommonTokenRequired(), flag.Sort(), flag.Page(), flag.PerPage(), flag.Id(true),
flag.IIdRange(true), flag.AllowFailure()),
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
var baseUrl = context.String(constant.BaseUrl) var baseUrl = context.String(constant.BaseUrl)
var token = context.String(constant.Token) var token = context.String(constant.Token)
@ -27,6 +28,7 @@ func DeleteJobs() *cli.Command {
var page = context.Int(constant.Page) var page = context.Int(constant.Page)
var perPage = context.Int(constant.PerPage) var perPage = context.Int(constant.PerPage)
var iidRanges = context.StringSlice(constant.IIdRange) var iidRanges = context.StringSlice(constant.IIdRange)
var allowFailure = context.Bool(constant.AllowFailure)
fmt.Println(iidRanges) fmt.Println(iidRanges)
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl)) gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl))
@ -45,7 +47,7 @@ func DeleteJobs() *cli.Command {
return nil return nil
} }
err = DeleteJobsRecursion(gitClient, id, page, perPage, sortStr, iids) err = DeleteJobsRecursion(gitClient, id, page, perPage, sortStr, iids, allowFailure)
if err != nil { if err != nil {
return err return err
} }
@ -55,7 +57,7 @@ func DeleteJobs() *cli.Command {
} }
} }
func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, perPage int, sort string, iids []int) error { func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, perPage int, sort string, iids []int, allowFailure bool) error {
pipelineInfos, response, err := pipelines.ListProjectPipelines(gitClient, id, page, perPage, sort) pipelineInfos, response, err := pipelines.ListProjectPipelines(gitClient, id, page, perPage, sort)
@ -78,26 +80,26 @@ func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, per
if iidsMin == pipelineInfo.IID { if iidsMin == pipelineInfo.IID {
// 等于最小值,删除最小值 // 等于最小值,删除最小值
iids = iids[1:] iids = iids[1:]
err = ExecuteDeleteJobs(gitClient, id, pipelineInfo.ID, 1, 100) err = ExecuteDeleteJobs(gitClient, id, pipelineInfo.ID, 1, 100, allowFailure)
if err != nil { if err != nil {
return err return err
} }
} else if pipelineInfo.IID == iidsMax { } else if pipelineInfo.IID == iidsMax {
// 等于最大值 // 等于最大值
iids = iids[:len(iids)-1] iids = iids[:len(iids)-1]
err = ExecuteDeleteJobs(gitClient, id, pipelineInfo.ID, 1, 100) err = ExecuteDeleteJobs(gitClient, id, pipelineInfo.ID, 1, 100, allowFailure)
if err != nil { if err != nil {
return err return err
} }
} else if iidsMin < pipelineInfo.IID { } else if iidsMin < pipelineInfo.IID {
// 大于最小值 // 大于最小值
err = jobsForExecute(&iids, pipelineInfo.IID, gitClient, id, pipelineInfo.ID) err = jobsForExecute(&iids, pipelineInfo.IID, gitClient, id, pipelineInfo.ID, allowFailure)
if err != nil { if err != nil {
return err return err
} }
} else if pipelineInfo.IID < iidsMax { } else if pipelineInfo.IID < iidsMax {
// 小于最大值 // 小于最大值
err = jobsForExecute(&iids, pipelineInfo.IID, gitClient, id, pipelineInfo.ID) err = jobsForExecute(&iids, pipelineInfo.IID, gitClient, id, pipelineInfo.ID, allowFailure)
if err != nil { if err != nil {
return err return err
} }
@ -115,7 +117,7 @@ func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, per
} }
if len(pipelineInfos) > 0 { if len(pipelineInfos) > 0 {
err := DeleteJobsRecursion(gitClient, id, page+1, perPage, sort, iids) err := DeleteJobsRecursion(gitClient, id, page+1, perPage, sort, iids, allowFailure)
if err != nil { if err != nil {
return err return err
} }
@ -124,13 +126,16 @@ func DeleteJobsRecursion(gitClient *gitlab.Client, id interface{}, page int, per
return nil return nil
} }
func jobsForExecute(iids *[]int, pipelineInfoIId int, gitClient *gitlab.Client, id interface{}, pipelineInfoId int) error { func jobsForExecute(iids *[]int, pipelineInfoIId int, gitClient *gitlab.Client, id interface{}, pipelineInfoId int, allowFailure bool) error {
for i := 0; i < len(*iids); i++ { for i := 0; i < len(*iids); i++ {
if (*iids)[i] == pipelineInfoIId { if (*iids)[i] == pipelineInfoIId {
fmt.Printf("数组中包含%d\n", pipelineInfoIId) fmt.Printf("数组中包含%d\n", pipelineInfoIId)
*iids = append((*iids)[:i], (*iids)[i+1:]...) *iids = append((*iids)[:i], (*iids)[i+1:]...)
err := ExecuteDeleteJobs(gitClient, id, pipelineInfoId, 1, 100) err := ExecuteDeleteJobs(gitClient, id, pipelineInfoId, 1, 100, allowFailure)
if err != nil { if err != nil {
if allowFailure {
return nil
}
return err return err
} }
break break
@ -139,7 +144,7 @@ func jobsForExecute(iids *[]int, pipelineInfoIId int, gitClient *gitlab.Client,
return nil return nil
} }
func ExecuteDeleteJobs(gitClient *gitlab.Client, id interface{}, pipelineInfoId int, page int, perPage int) error { func ExecuteDeleteJobs(gitClient *gitlab.Client, id interface{}, pipelineInfoId int, page int, perPage int, allowFailure bool) error {
fmt.Printf("执行删除 %d \n", pipelineInfoId) fmt.Printf("执行删除 %d \n", pipelineInfoId)
opt := &gitlab.ListJobsOptions{ opt := &gitlab.ListJobsOptions{
@ -160,13 +165,16 @@ func ExecuteDeleteJobs(gitClient *gitlab.Client, id interface{}, pipelineInfoId
_, response, err = gitClient.Jobs.EraseJob(id, job.ID) _, response, err = gitClient.Jobs.EraseJob(id, job.ID)
if err != nil { if err != nil {
if allowFailure {
return nil
}
return err return err
} }
log.Printf("Delete Project %s Job %d Response StatusCode: %d\n", id, job.ID, response.Response.StatusCode) log.Printf("Delete Project %s Job %d Response StatusCode: %d\n", id, job.ID, response.Response.StatusCode)
} }
if len(jobs) == perPage { if len(jobs) == perPage {
err = ExecuteDeleteJobs(gitClient, id, pipelineInfoId, page+1, perPage) err = ExecuteDeleteJobs(gitClient, id, pipelineInfoId, page+1, perPage, allowFailure)
if err != nil { if err != nil {
return err return err
} }

View File

@ -0,0 +1,49 @@
package mix
import (
"github.com/urfave/cli/v2"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
"github.com/xuxiaowei-com-cn/gitlab-go/environments"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
"github.com/xuxiaowei-com-cn/gitlab-go/projects"
"log"
)
// EnvironmentsCreateAll 所有项目创建新环境
func EnvironmentsCreateAll() *cli.Command {
return &cli.Command{
Name: "all",
Aliases: []string{"a"},
Usage: "所有项目创建新环境",
Flags: append(flag.CommonTokenRequired(), flag.Owned(true),
flag.EnvName(false), flag.EnvExternalUrl(), flag.EnvTier(), 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.EnvName)
var externalURL = context.String(constant.EnvExternalUrl)
var tier = context.String(constant.EnvTier)
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 = environments.CreateEnvironment(baseUrl, token, project.ID, name, externalURL, tier, printJson, printTime, allowFailure)
if err != nil {
return err
}
}
return nil
},
}
}

View File

@ -11,7 +11,8 @@ func Delete() *cli.Command {
Name: "mix-delete", Name: "mix-delete",
Aliases: []string{"mix-rm"}, Aliases: []string{"mix-rm"},
Usage: "删除(混合命令,多接口命令)", Usage: "删除(混合命令,多接口命令)",
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.Id(false), flag.IIdRange(false)), Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.Id(false),
flag.IIdRange(false), flag.AllowFailure()),
Subcommands: []*cli.Command{ Subcommands: []*cli.Command{
DeleteArtifacts(), DeleteArtifacts(),
DeleteAllArtifacts(), DeleteAllArtifacts(),

20
mix/mix_environments.go Normal file
View File

@ -0,0 +1,20 @@
package mix
import (
"github.com/urfave/cli/v2"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
)
func Environments() *cli.Command {
return &cli.Command{
Name: "mix-create-environments",
Aliases: []string{"mix-create-environment", "mix-create-env"},
Usage: "创建新环境(混合命令,多接口命令)",
Flags: append(flag.Common(), flag.Owned(false),
flag.EnvName(false), flag.EnvExternalUrl(), flag.EnvTier(), flag.AllowFailure(),
flag.PrintJson(), flag.PrintTime()),
Subcommands: []*cli.Command{
EnvironmentsCreateAll(),
},
}
}

View File

@ -0,0 +1,21 @@
package mix
import (
"github.com/urfave/cli/v2"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
)
// CreateProjectLevelVariables 创建项目级别 CI/CD 变量
func CreateProjectLevelVariables() *cli.Command {
return &cli.Command{
Name: "mix-create-project-level-variables",
Usage: "创建项目级别 CI/CD 变量(混合命令,多接口命令)",
Flags: append(flag.Common(),
flag.VariableKey(false), flag.VariableValue(false), flag.VariableType(), flag.VariableProtected(),
flag.VariableMasked(), flag.VariableRaw(), flag.VariableEnvironmentScope(),
flag.PrintJson(), flag.PrintTime()),
Subcommands: []*cli.Command{
ProjectLevelVariablesCreateAll(),
},
}
}

View File

@ -0,0 +1,21 @@
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(),
},
}
}

View File

@ -0,0 +1,57 @@
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/project_level_variables"
"github.com/xuxiaowei-com-cn/gitlab-go/projects"
"log"
)
// ProjectLevelVariablesCreateAll 所有项目创建新变量
func ProjectLevelVariablesCreateAll() *cli.Command {
return &cli.Command{
Name: "all",
Aliases: []string{"a"},
Usage: "所有项目创建新变量",
Flags: append(flag.CommonTokenRequired(), flag.Owned(true),
flag.VariableKey(true), flag.VariableValue(true), flag.VariableType(), flag.VariableProtected(),
flag.VariableMasked(), flag.VariableRaw(), flag.VariableEnvironmentScope(), 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 key = context.String(constant.VariableKey)
var value = context.String(constant.VariableValue)
var variableType = context.String(constant.VariableType)
var protected = context.Bool(constant.VariableProtected)
var masked = context.Bool(constant.VariableMasked)
var raw = context.Bool(constant.VariableRaw)
var environmentScope = context.String(constant.VariableEnvironmentScope)
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 = project_level_variables.CreateVariable(baseUrl, token, project.ID, key, value, protected, masked, raw, environmentScope, variableType,
printJson, printTime, allowFailure)
if err != nil {
return err
}
}
return nil
},
}
}

View File

@ -0,0 +1,58 @@
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
},
}
}

View File

@ -0,0 +1,123 @@
package project_level_variables
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"
)
// Create 创建变量 https://docs.gitlab.cn/jh/api/project_level_variables.html#%E5%88%9B%E5%BB%BA%E5%8F%98%E9%87%8F
func Create() *cli.Command {
return &cli.Command{
Name: "create",
Usage: "创建变量",
Flags: append(flag.CommonTokenRequired(), flag.Id(true),
flag.VariableKey(true), flag.VariableValue(true), flag.VariableType(), flag.VariableProtected(),
flag.VariableMasked(), flag.VariableRaw(), flag.VariableEnvironmentScope(),
flag.PrintJson(), flag.PrintTime()),
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 key = context.String(constant.VariableKey)
var value = context.String(constant.VariableValue)
var variableType = context.String(constant.VariableType)
var protected = context.Bool(constant.VariableProtected)
var masked = context.Bool(constant.VariableMasked)
var raw = context.Bool(constant.VariableRaw)
var environmentScope = context.String(constant.VariableEnvironmentScope)
var printJson = context.Bool(constant.PrintJson)
var printTime = context.Bool(constant.PrintTime)
return CreateVariable(baseUrl, token, id, key, value, protected, masked, raw, environmentScope, variableType,
printJson, printTime, false)
},
}
}
func CreateVariable(baseUrl string, token string, id interface{}, key string, value string, protected bool, masked bool, raw bool, environmentScope string, variableType string,
printJson bool, printTime bool, allowFailure bool) error {
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl))
if err != nil {
return err
}
opt := &gitlab.CreateProjectVariableOptions{
Key: &key,
Value: &value,
Protected: &protected,
Masked: &masked,
Raw: &raw,
EnvironmentScope: &environmentScope,
}
if variableType == "env_var" {
opt.VariableType = gitlab.Ptr(gitlab.EnvVariableType)
} else if variableType == "file" {
opt.VariableType = gitlab.Ptr(gitlab.FileVariableType)
}
projectVariable, response, err := gitClient.ProjectVariables.CreateVariable(id, opt)
if err != nil {
if allowFailure {
return nil
}
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
fmt.Println("")
if printJson {
if printTime {
jsonData, err := json.Marshal(projectVariable)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
} else {
jsonData, err := json.Marshal(projectVariable)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
} else {
if printTime {
log.Printf("Key: %s\n", projectVariable.Key)
log.Printf("Value: %s\n", projectVariable.Value)
log.Printf("VariableType: %s\n", projectVariable.VariableType)
log.Printf("Protected: %t\n", projectVariable.Protected)
log.Printf("Masked: %t\n", projectVariable.Masked)
log.Printf("Raw: %t\n", projectVariable.Raw)
log.Printf("EnvironmentScope: %s\n", projectVariable.EnvironmentScope)
fmt.Println("")
} else {
fmt.Printf("Key: %s\n", projectVariable.Key)
fmt.Printf("Value: %s\n", projectVariable.Value)
fmt.Printf("VariableType: %s\n", projectVariable.VariableType)
fmt.Printf("Protected: %t\n", projectVariable.Protected)
fmt.Printf("Masked: %t\n", projectVariable.Masked)
fmt.Printf("Raw: %t\n", projectVariable.Raw)
fmt.Printf("EnvironmentScope: %s\n", projectVariable.EnvironmentScope)
fmt.Println("")
}
}
return nil
}

View File

@ -0,0 +1,98 @@
package project_level_variables
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"
)
// List 列出项目变量 https://docs.gitlab.cn/jh/api/project_level_variables.html#%E5%88%97%E5%87%BA%E9%A1%B9%E7%9B%AE%E5%8F%98%E9%87%8F
func List() *cli.Command {
return &cli.Command{
Name: "list",
Usage: "列出项目变量",
Flags: append(flag.CommonTokenRequired(), flag.Id(true), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime()),
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.ListProjectVariablesOptions{
Page: page,
PerPage: perPage,
}
projectVariables, response, err := gitClient.ProjectVariables.ListVariables(id, opt)
if err != nil {
return err
}
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
fmt.Println("")
if printJson {
if printTime {
for _, projectVariable := range projectVariables {
jsonData, err := json.Marshal(projectVariable)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, projectVariable := range projectVariables {
jsonData, err := json.Marshal(projectVariable)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, projectVariable := range projectVariables {
log.Printf("Key: %s\n", projectVariable.Key)
log.Printf("Value: %s\n", projectVariable.Value)
log.Printf("VariableType: %s\n", projectVariable.VariableType)
log.Printf("Protected: %t\n", projectVariable.Protected)
log.Printf("Masked: %t\n", projectVariable.Masked)
log.Printf("Raw: %t\n", projectVariable.Raw)
log.Printf("EnvironmentScope: %s\n", projectVariable.EnvironmentScope)
fmt.Println("")
}
} else {
for _, projectVariable := range projectVariables {
fmt.Printf("Key: %s\n", projectVariable.Key)
fmt.Printf("Value: %s\n", projectVariable.Value)
fmt.Printf("VariableType: %s\n", projectVariable.VariableType)
fmt.Printf("Protected: %t\n", projectVariable.Protected)
fmt.Printf("Masked: %t\n", projectVariable.Masked)
fmt.Printf("Raw: %t\n", projectVariable.Raw)
fmt.Printf("EnvironmentScope: %s\n", projectVariable.EnvironmentScope)
fmt.Println("")
}
}
}
return nil
},
}
}

View File

@ -0,0 +1,23 @@
package project_level_variables
import (
"github.com/urfave/cli/v2"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
)
// ProjectLevelVariables 项目级别 CI/CD 变量 API https://docs.gitlab.cn/jh/api/project_level_variables.html
func ProjectLevelVariables() *cli.Command {
return &cli.Command{
Name: "project-level-variables",
Aliases: []string{"project-level-variable", "plv"},
Usage: "项目级别 CI/CD 变量 API中文文档https://docs.gitlab.cn/jh/api/project_level_variables.html",
Flags: append(flag.Common(), flag.Id(false),
flag.VariableKey(false), flag.VariableValue(false), flag.VariableType(), flag.VariableProtected(),
flag.VariableMasked(), flag.VariableRaw(), flag.VariableEnvironmentScope(),
flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime()),
Subcommands: []*cli.Command{
List(),
Create(),
},
}
}

View File

@ -15,12 +15,13 @@ func List() *cli.Command {
return &cli.Command{ return &cli.Command{
Name: "list", Name: "list",
Usage: "列出所有项目", Usage: "列出所有项目",
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(), Flags: append(flag.Common(), flag.Owned(true), flag.Sort(), flag.Page(), flag.PerPage(),
flag.Search(), flag.SearchNamespaces(), flag.PrintJson(), flag.PrintTime(), flag.Search(), flag.SearchNamespaces(),
flag.OrderBy(OrderByUsage)), flag.OrderBy(OrderByUsage)),
Action: func(context *cli.Context) error { Action: func(context *cli.Context) error {
var baseUrl = context.String(constant.BaseUrl) var baseUrl = context.String(constant.BaseUrl)
var token = context.String(constant.Token) var token = context.String(constant.Token)
var owned = context.Bool(constant.Owned)
var sort = context.String(constant.Sort) var sort = context.String(constant.Sort)
var page = context.Int(constant.Page) var page = context.Int(constant.Page)
var perPage = context.Int(constant.PerPage) var perPage = context.Int(constant.PerPage)
@ -43,6 +44,7 @@ func List() *cli.Command {
Sort: &sort, Sort: &sort,
Search: &search, Search: &search,
SearchNamespaces: &searchNamespaces, SearchNamespaces: &searchNamespaces,
Owned: &owned,
OrderBy: &orderBy, OrderBy: &orderBy,
} }
projects, response, err := gitClient.Projects.ListProjects(opt) projects, response, err := gitClient.Projects.ListProjects(opt)

View File

@ -18,8 +18,8 @@ func Projects() *cli.Command {
Name: "project", Name: "project",
Aliases: []string{"projects", "p"}, Aliases: []string{"projects", "p"},
Usage: "项目 API中文文档https://docs.gitlab.cn/jh/api/projects.html", Usage: "项目 API中文文档https://docs.gitlab.cn/jh/api/projects.html",
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(), Flags: append(flag.Common(), flag.Owned(false), flag.Sort(), flag.Page(), flag.PerPage(),
flag.Search(), flag.SearchNamespaces(), flag.PrintJson(), flag.PrintTime(), flag.Search(), flag.SearchNamespaces(),
flag.OrderBy(OrderByUsage)), flag.OrderBy(OrderByUsage)),
Subcommands: []*cli.Command{ Subcommands: []*cli.Command{
List(), List(),

151
protected_branches/list.go Normal file
View File

@ -0,0 +1,151 @@
package protected_branches
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"
)
// List 列出受保护的分支 https://docs.gitlab.cn/jh/api/protected_branches.html#%E5%88%97%E5%87%BA%E5%8F%97%E4%BF%9D%E6%8A%A4%E7%9A%84%E5%88%86%E6%94%AF
func List() *cli.Command {
return &cli.Command{
Name: "list",
Usage: "列出受保护的分支",
Flags: append(flag.CommonTokenRequired(), flag.Id(true), flag.ProtectedBranchesSearch(),
flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime()),
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 search = context.String(constant.Search)
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.ListProtectedBranchesOptions{
Search: &search,
ListOptions: gitlab.ListOptions{
Page: page,
PerPage: perPage,
},
}
protectedBranchs, response, err := gitClient.ProtectedBranches.ListProtectedBranches(id, opt)
if err != nil {
return err
}
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
fmt.Println("")
if printJson {
if printTime {
for _, protectedBranch := range protectedBranchs {
jsonData, err := json.Marshal(protectedBranch)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, protectedBranch := range protectedBranchs {
jsonData, err := json.Marshal(protectedBranch)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, protectedBranch := range protectedBranchs {
log.Printf("ID: %d\n", protectedBranch.ID)
log.Printf("Name: %s\n", protectedBranch.Name)
log.Printf("AllowForcePush: %t\n", protectedBranch.AllowForcePush)
log.Printf("CodeOwnerApprovalRequired: %t\n", protectedBranch.CodeOwnerApprovalRequired)
log.Printf("PushAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.PushAccessLevels {
log.Printf("PushAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
log.Printf("PushAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
log.Printf("PushAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
log.Printf("PushAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
log.Printf("PushAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
log.Printf("MergeAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.MergeAccessLevels {
log.Printf("MergeAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
log.Printf("MergeAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
log.Printf("MergeAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
log.Printf("MergeAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
log.Printf("MergeAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
log.Printf("UnprotectAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.UnprotectAccessLevels {
log.Printf("UnprotectAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
log.Printf("UnprotectAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
log.Printf("UnprotectAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
log.Printf("UnprotectAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
log.Printf("UnprotectAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
fmt.Println("")
}
} else {
for _, protectedBranch := range protectedBranchs {
fmt.Printf("ID: %d\n", protectedBranch.ID)
fmt.Printf("Name: %s\n", protectedBranch.Name)
fmt.Printf("AllowForcePush: %t\n", protectedBranch.AllowForcePush)
fmt.Printf("CodeOwnerApprovalRequired: %t\n", protectedBranch.CodeOwnerApprovalRequired)
fmt.Printf("PushAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.PushAccessLevels {
fmt.Printf("PushAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
fmt.Printf("PushAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
fmt.Printf("PushAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
fmt.Printf("PushAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
fmt.Printf("PushAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
fmt.Printf("MergeAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.MergeAccessLevels {
fmt.Printf("MergeAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
fmt.Printf("MergeAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
fmt.Printf("MergeAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
fmt.Printf("MergeAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
fmt.Printf("MergeAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
fmt.Printf("UnprotectAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.UnprotectAccessLevels {
fmt.Printf("UnprotectAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
fmt.Printf("UnprotectAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
fmt.Printf("UnprotectAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
fmt.Printf("UnprotectAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
fmt.Printf("UnprotectAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
fmt.Println("")
}
}
}
return nil
},
}
}

View File

@ -0,0 +1,195 @@
package protected_branches
import (
"encoding/json"
"errors"
"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"
)
// Protect 保护仓库分支 https://docs.gitlab.cn/jh/api/protected_branches.html#%E4%BF%9D%E6%8A%A4%E4%BB%93%E5%BA%93%E5%88%86%E6%94%AF
func Protect() *cli.Command {
return &cli.Command{
Name: "protect",
Usage: "保护仓库分支",
Flags: append(flag.CommonTokenRequired(), flag.Id(true),
flag.BranchName(true), flag.PushAccessLevel(), flag.MergeAccessLevel(),
flag.UnprotectAccessLevel(), flag.AllowForcePush(), flag.CodeOwnerApprovalRequired(),
flag.PrintJson(), flag.PrintTime()),
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 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)
return ProtectRepositoryBranches(baseUrl, token, id, name,
pushAccessLevel, mergeAccessLevel, unprotectAccessLevel, allowForcePush, codeOwnerApprovalRequired,
printJson, printTime, false)
},
}
}
func ProtectRepositoryBranches(baseUrl string, token string, id interface{}, name string,
pushAccessLevel int, mergeAccessLevel int, unprotectAccessLevel int, allowForcePush bool, codeOwnerApprovalRequired bool,
printJson bool, printTime bool, allowFailure bool) error {
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl))
if err != nil {
return err
}
var pushAccessLevelValue gitlab.AccessLevelValue
switch pushAccessLevel {
case 0, 5, 10, 20, 30, 40, 50, 60:
pushAccessLevelValue = gitlab.AccessLevelValue(pushAccessLevel)
default:
return errors.New(fmt.Sprintf("pushAccessLevel%d 不合法", pushAccessLevel))
}
var mergeAccessLevelValue gitlab.AccessLevelValue
switch mergeAccessLevel {
case 0, 5, 10, 20, 30, 40, 50, 60:
mergeAccessLevelValue = gitlab.AccessLevelValue(mergeAccessLevel)
default:
return errors.New(fmt.Sprintf("mergeAccessLevel%d 不合法", mergeAccessLevel))
}
var unprotectAccessLevelValue gitlab.AccessLevelValue
switch unprotectAccessLevel {
case 0, 5, 10, 20, 30, 40, 50, 60:
unprotectAccessLevelValue = gitlab.AccessLevelValue(unprotectAccessLevel)
default:
return errors.New(fmt.Sprintf("unprotectAccessLevel%d 不合法", unprotectAccessLevel))
}
opt := &gitlab.ProtectRepositoryBranchesOptions{
Name: &name,
PushAccessLevel: &pushAccessLevelValue,
MergeAccessLevel: &mergeAccessLevelValue,
UnprotectAccessLevel: &unprotectAccessLevelValue,
AllowForcePush: &allowForcePush,
//AllowedToPush: &allowedToPush,
//AllowedToMerge: &allowedToMerge,
//AllowedToUnprotect: &allowedToUnprotect,
CodeOwnerApprovalRequired: &codeOwnerApprovalRequired,
}
protectedBranch, response, err := gitClient.ProtectedBranches.ProtectRepositoryBranches(id, opt)
if err != nil {
if allowFailure {
return nil
}
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
fmt.Println("")
if printJson {
if printTime {
jsonData, err := json.Marshal(protectedBranch)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
} else {
jsonData, err := json.Marshal(protectedBranch)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
} else {
if printTime {
log.Printf("ID: %d\n", protectedBranch.ID)
log.Printf("Name: %s\n", protectedBranch.Name)
log.Printf("AllowForcePush: %t\n", protectedBranch.AllowForcePush)
log.Printf("CodeOwnerApprovalRequired: %t\n", protectedBranch.CodeOwnerApprovalRequired)
log.Printf("PushAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.PushAccessLevels {
log.Printf("PushAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
log.Printf("PushAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
log.Printf("PushAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
log.Printf("PushAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
log.Printf("PushAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
log.Printf("MergeAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.MergeAccessLevels {
log.Printf("MergeAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
log.Printf("MergeAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
log.Printf("MergeAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
log.Printf("MergeAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
log.Printf("MergeAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
log.Printf("UnprotectAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.UnprotectAccessLevels {
log.Printf("UnprotectAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
log.Printf("UnprotectAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
log.Printf("UnprotectAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
log.Printf("UnprotectAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
log.Printf("UnprotectAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
fmt.Println("")
} else {
fmt.Printf("ID: %d\n", protectedBranch.ID)
fmt.Printf("Name: %s\n", protectedBranch.Name)
fmt.Printf("AllowForcePush: %t\n", protectedBranch.AllowForcePush)
fmt.Printf("CodeOwnerApprovalRequired: %t\n", protectedBranch.CodeOwnerApprovalRequired)
fmt.Printf("PushAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.PushAccessLevels {
fmt.Printf("PushAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
fmt.Printf("PushAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
fmt.Printf("PushAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
fmt.Printf("PushAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
fmt.Printf("PushAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
fmt.Printf("MergeAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.MergeAccessLevels {
fmt.Printf("MergeAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
fmt.Printf("MergeAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
fmt.Printf("MergeAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
fmt.Printf("MergeAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
fmt.Printf("MergeAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
fmt.Printf("UnprotectAccessLevels: \n")
for index, branchAccessDescription := range protectedBranch.UnprotectAccessLevels {
fmt.Printf("UnprotectAccessLevels[%d] ID: %d\n", index, branchAccessDescription.ID)
fmt.Printf("UnprotectAccessLevels[%d] AccessLevel: %d\n", index, branchAccessDescription.AccessLevel)
fmt.Printf("UnprotectAccessLevels[%d] AccessLevelDescription: %s\n", index, branchAccessDescription.AccessLevelDescription)
fmt.Printf("UnprotectAccessLevels[%d] UserID: %d\n", index, branchAccessDescription.UserID)
fmt.Printf("UnprotectAccessLevels[%d] GroupID: %d\n", index, branchAccessDescription.GroupID)
}
fmt.Println("")
}
}
return nil
}

View File

@ -0,0 +1,23 @@
package protected_branches
import (
"github.com/urfave/cli/v2"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
)
// ProtectedBranches 受保护的分支 API https://docs.gitlab.cn/jh/api/protected_branches.html
func ProtectedBranches() *cli.Command {
return &cli.Command{
Name: "protected-branches",
Aliases: []string{"pb"},
Usage: "受保护的分支 API中文文档https://docs.gitlab.cn/jh/api/protected_branches.html",
Flags: append(flag.Common(), flag.Id(false), flag.ProtectedBranchesSearch(),
flag.BranchName(false), flag.PushAccessLevel(), flag.MergeAccessLevel(),
flag.UnprotectAccessLevel(), flag.AllowForcePush(), flag.CodeOwnerApprovalRequired(),
flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime()),
Subcommands: []*cli.Command{
List(),
Protect(),
},
}
}