Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions docs/TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ GitLab CLI 支持使用自定义模板来格式化输出结果,让你可以按

模板使用 Go 的 `text/template` 语法,支持访问以下数据结构:

### 重要说明:Path 与 ProjectPath 字段

在输出数据中,项目有两个路径字段:

- **Path**: 完整路径,包含 group 或 username 前缀
- 组级项目:`backend-group-20251105112212/demo-20251105112213`
- 用户级项目:`tektoncd-20251105112211/my-personal-project-20251105112216`

- **ProjectPath**: 项目本身的路径,不包含前缀
- 组级项目:`demo-20251105112213`
- 用户级项目:`my-personal-project-20251105112216`

**关于时间戳后缀**:
- 当使用 `nameMode: prefix` 时(默认),路径会自动添加时间戳后缀
- 当使用 `nameMode: name` 时,路径保持与配置文件中一致,不添加时间戳
- **注意**:nameMode 只影响路径(Path),不影响项目的显示名称(Name)

### 可用数据

```go
Expand All @@ -50,14 +67,16 @@ GitLab CLI 支持使用自定义模板来格式化输出结果,让你可以按
│ ├── .Visibility // 可见性
│ └── .Projects // 组下的项目数组
│ ├── .Name // 项目名
│ ├── .Path // 项目路径
│ ├── .Path // 完整路径,如 group/project
│ ├── .ProjectPath // 项目本身的路径,不含 group
│ ├── .ProjectID // 项目 ID
│ ├── .Description // 描述
│ ├── .Visibility // 可见性
│ └── .WebURL // Web URL
└── .Projects // 用户级项目数组(不属于任何组)
├── .Name // 项目名
├── .Path // 项目路径
├── .Path // 完整路径,如 username/project
├── .ProjectPath // 项目本身的路径,不含 username
├── .ProjectID // 项目 ID
├── .Description // 描述
├── .Visibility // 可见性
Expand Down Expand Up @@ -175,6 +194,8 @@ toolchains:
projects:
{{- range .Projects }}
- name: {{ .Name }}
path: {{ .Path }} # 完整路径,如 group/project
project_path: {{ .ProjectPath }} # 项目本身的路径,不含 group
project_id: {{ .ProjectID }}
web_url: {{ .WebURL }}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions examples/template-example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ toolchains:
projects:
{{- range .Projects }}
- name: {{ .Name }}
path: {{ .Path }} # 完整路径,如 group/project
project_path: {{ .ProjectPath }} # 项目本身的路径,不含 group
{{- end }}
{{- end }}
{{- end }}
Expand Down
2 changes: 2 additions & 0 deletions internal/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ func (p *ResourceProcessor) createUserProjectsWithOutput(username string, projec
projectOutputs = append(projectOutputs, types.ProjectOutput{
Name: projSpec.Name,
Path: fullPath,
ProjectPath: actualProjectPath,
ProjectID: projectID,
Description: projSpec.Description,
Visibility: projSpec.Visibility,
Expand Down Expand Up @@ -379,6 +380,7 @@ func (p *ResourceProcessor) createProjectsWithOutput(username string, groupID in
projectOutputs = append(projectOutputs, types.ProjectOutput{
Name: projSpec.Name,
Path: fullPath,
ProjectPath: actualProjectPath,
ProjectID: projectID,
Description: projSpec.Description,
Visibility: projSpec.Visibility,
Expand Down
3 changes: 2 additions & 1 deletion pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ type GroupOutput struct {
// ProjectOutput 项目输出结果
type ProjectOutput struct {
Name string `yaml:"name"`
Path string `yaml:"path"`
Path string `yaml:"path"` // 完整路径,如 group/project 或 username/project
ProjectPath string `yaml:"project_path"` // 项目本身的路径,不包含 group 或 username
ProjectID int `yaml:"project_id"`
Description string `yaml:"description"`
Visibility string `yaml:"visibility"`
Expand Down