@@ -7,8 +7,10 @@ GitLab 用户和项目自动化管理工具,基于官方 GitLab Go SDK 开发
77- ✅ ** 官方 SDK** : 使用 GitLab 官方 Go SDK (` gitlab.com/gitlab-org/api/client-go ` )
88- ✅ ** 纯 Go 实现** : 无需外部依赖,类型安全的 API 调用
99- ✅ ** 批量管理** : 支持批量创建和管理 GitLab 用户、组和项目
10- - ✅ ** Token 管理** : 自动创建 Personal Access Token,支持自定义权限和过期时间
11- - ✅ ** 灵活输出** : 支持默认 YAML 格式和自定义模板输出
10+ - ✅ ** Token 自动创建** : 为用户自动创建 Personal Access Token,支持自定义权限和过期时间
11+ - ✅ ** 智能默认值** : Token 过期时间默认为第2天(从当天算起)
12+ - ✅ ** 灵活输出** : 支持默认 YAML 格式和自定义 Go Template 模板输出
13+ - ✅ ** 完整结果** : 输出包含 Token 值、用户 ID、组 ID、项目 ID、Web URL 等完整信息
1214- ✅ ** 模块化设计** : 易于维护和扩展
1315
1416## 🚀 快速开始
@@ -74,9 +76,9 @@ export GITLAB_TOKEN=your-personal-access-token
7476``` yaml
7577# test-users.yaml
7678users :
77- - username : testuser
78- email : testuser@ example.com
79- name : Test User
79+ - username : tektoncd
80+ email : tektoncd001@test. example.com
81+ name : tektoncd-test
8082 password : " MyStr0ng!Pass2024"
8183
8284 # Personal Access Token 配置(可选)
@@ -86,17 +88,35 @@ users:
8688 - read_user
8789 - read_repository
8890 - write_repository
89- expires_at : 2026-01-01 # 可选,不指定则默认为第2天
91+ - read_api
92+ - create_runner
93+ # expires_at: 2026-01-01 # 可选,不指定则默认为第2天
9094
9195 # 组和项目配置
9296 groups :
93- - name : my -group
94- path : my -group
97+ - name : tektoncd-frontend -group
98+ path : tektoncd-frontend -group
9599 visibility : private
96100 projects :
97- - name : my-project
98- path : my-project
99- description : 我的项目
101+ - name : test-e2e-demo
102+ path : test-e2e-demo
103+ description : 测试前端应用
104+ visibility : private
105+ - name : test-vue-app
106+ path : test-vue-app
107+ description : Vue.js 测试应用
108+ visibility : private
109+ - name : tektoncd-backend-group
110+ path : tektoncd-backend-group
111+ visibility : private
112+ projects :
113+ - name : test-java
114+ path : test-java-e2e-demo
115+ description : 测试后端 API
116+ visibility : public
117+ - name : test-go-api
118+ path : test-go-api
119+ description : Go API 服务
100120 visibility : private
101121` ` `
102122
@@ -115,22 +135,35 @@ users:
115135# ### 过期时间
116136
117137- **指定过期时间**: `expires_at: 2026-01-01` (格式: YYYY-MM-DD)
118- - **不指定**: 自动设置为第2天过期(从今天算起 )
138+ - **不指定**: 自动设置为第2天过期(从当天算起,即今天 + 2 天 )
119139
140+ **示例**:
120141` ` ` yaml
121- # 示例 1: 指定过期时间
142+ # 方式 1: 指定过期时间
122143token:
123144 scope:
124145 - api
125146 expires_at: 2026-01-01
126147
127- # 示例 2: 使用默认过期时间(第2天)
148+ # 方式 2: 使用默认过期时间(第2天)
128149token:
129150 scope:
130151 - api
131- # 不指定 expires_at,自动设为第2天
152+ # 不指定 expires_at,系统自动设为第2天
153+
154+ # 方式 3: 注释掉 expires_at(推荐用于测试)
155+ token:
156+ scope:
157+ - api
158+ - read_user
159+ # expires_at: 2026-01-01 # 注释掉则使用默认值
132160` ` `
133161
162+ **默认过期时间说明**:
163+ - 如果今天是 2025-10-27,默认过期时间为 2025-10-29
164+ - Token 会在过期时间当天结束时失效
165+ - 日志会显示 : ` 未指定过期时间,使用默认值: 2025-10-29 (第2天)`
166+
134167# # 📤 输出功能
135168
136169# ## 默认 YAML 输出
@@ -143,31 +176,62 @@ token:
143176
144177` ` ` yaml
145178users:
146- - username: testuser
147- email: testuser@ example.com
148- name: Test User
149- user_id: 123
179+ - username: tektoncd
180+ email: tektoncd001@test. example.com
181+ name: tektoncd-test
182+ user_id: 24
150183 token:
151- value: glpat-xxxxxxxxxxxxxxxxxxxx
184+ value: glpat-TXLgrsMwyVt5obFqkDny
152185 scope:
153186 - api
154187 - read_user
155- expires_at: "2026-01-01"
188+ - read_repository
189+ - write_repository
190+ - read_api
191+ - create_runner
192+ expires_at: "2025-10-29"
156193 groups:
157- - name: my -group
158- path: my -group
159- group_id: 456
194+ - name: tektoncd-frontend -group
195+ path: tektoncd-frontend -group
196+ group_id: 1506
160197 visibility: private
161198 projects:
162- - name: my-project
163- path: my-group/my-project
164- project_id: 789
165- web_url: https://gitlab.com/my-group/my-project
199+ - name: test-e2e-demo
200+ path: tektoncd-frontend-group/test-e2e-demo
201+ project_id: 1434
202+ description: 测试前端应用
203+ visibility: private
204+ web_url: https://devops-gitlab.alaudatech.net/tektoncd-frontend-group/test-e2e-demo
205+ - name: test-vue-app
206+ path: tektoncd-frontend-group/test-vue-app
207+ project_id: 1435
208+ description: Vue.js 测试应用
209+ visibility: private
210+ web_url: https://devops-gitlab.alaudatech.net/tektoncd-frontend-group/test-vue-app
211+ - name: tektoncd-backend-group
212+ path: tektoncd-backend-group
213+ group_id: 1507
214+ visibility: private
215+ projects:
216+ - name: test-java
217+ path: tektoncd-backend-group/test-java-e2e-demo
218+ project_id: 1436
219+ description: 测试后端 API
220+ visibility: public
221+ web_url: https://devops-gitlab.alaudatech.net/tektoncd-backend-group/test-java-e2e-demo
222+ - name: test-go-api
223+ path: tektoncd-backend-group/test-go-api
224+ project_id: 1437
225+ description: Go API 服务
226+ visibility: private
227+ web_url: https://devops-gitlab.alaudatech.net/tektoncd-backend-group/test-go-api
166228` ` `
167229
168230# ## 自定义模板输出
169231
170- 创建模板文件 `template.yaml`:
232+ 项目提供了模板示例文件 **template-example.yaml**,展示了如何使用 Go template 语法自定义输出格式。
233+
234+ 使用模板:
171235
172236` ` ` yaml
173237# 使用 Go template 语法
0 commit comments