补充参数,优化日志

This commit is contained in:
徐晓伟 2023-10-17 14:18:38 +08:00
parent 5257cbd489
commit 11ed3e194c
9 changed files with 379 additions and 41 deletions

View File

@ -195,6 +195,10 @@ COPYRIGHT:
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 编码的路径
--help, -h show help
```
@ -216,6 +220,10 @@ COPYRIGHT:
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 编码的路径
--help, -h show help
```
@ -267,6 +275,10 @@ COPYRIGHT:
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)
--help, -h show help
```
@ -385,6 +397,10 @@ COPYRIGHT:
--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
--sort value 按照 asc 或者 desc 排序 (default: "desc")
--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 编码的路径
--help, -h show help
```
@ -409,6 +425,8 @@ COPYRIGHT:
--sort value 按照 asc 或者 desc 排序 (default: "desc")
--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)
--search value 根据 title 和 description 搜索议题。
--search-namespaces 匹配搜索条件时包括上级命名空间。默认为 false。 (default: false)
--order-by value 返回按 id、name、path、created_at、updated_at、last_activity_at 或 similarity 字段排序的项目。repository_size、storage_size、packages_size 或 wiki_size 字段只允许管理员使用。similarity引入于 14.1 版本)仅在搜索 时可用并且仅限于当前用户所属的项目。默认是created_at。 (default: "created_at")

View File

@ -1,6 +1,8 @@
package access_requests
import (
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"github.com/xanzy/go-gitlab"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
@ -14,32 +16,89 @@ func AccessRequests() *cli.Command {
Name: "access-request",
Aliases: []string{"access-requests", "ar"},
Usage: "群组和项目访问请求 API中文文档https://docs.gitlab.cn/jh/api/access_requests.html",
Flags: append(flag.Common(), flag.Id(false)),
Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Id(false)),
Subcommands: []*cli.Command{
{
Name: "group",
Aliases: []string{"groups"},
Usage: "为群组列出访问请求",
Flags: append(flag.Common(), flag.Id(true)),
Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Id(true)),
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.ListAccessRequestsOptions{}
opt := &gitlab.ListAccessRequestsOptions{
Page: page,
PerPage: perPage,
}
accessRequests, response, err := gitClient.AccessRequests.ListGroupAccessRequests(id, opt)
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
for index, accessRequest := range accessRequests {
log.Printf("Index: %d,\t ID: %d,\t Username: %s,\t Name: %s,\t State: %s,\t CreatedAt: %s,\t RequestedAt: %s,\t AccessLevel: %d\n", index, accessRequest.ID, accessRequest.Username, accessRequest.Name, accessRequest.State, accessRequest.CreatedAt, accessRequest.RequestedAt, accessRequest.AccessLevel)
fmt.Println("")
if printJson {
if printTime {
for _, accessRequest := range accessRequests {
jsonData, err := json.Marshal(accessRequest)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, accessRequest := range accessRequests {
jsonData, err := json.Marshal(accessRequest)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, accessRequest := range accessRequests {
log.Printf("ID: %d\n", accessRequest.ID)
log.Printf("Username: %s\n", accessRequest.Username)
log.Printf("Name: %s\n", accessRequest.Name)
log.Printf("State: %s\n", accessRequest.State)
log.Printf("CreatedAt: %s\n", accessRequest.CreatedAt)
log.Printf("RequestedAt: %s\n", accessRequest.RequestedAt)
log.Printf("AccessLevel: %d\n", accessRequest.AccessLevel)
fmt.Println("")
}
} else {
for _, accessRequest := range accessRequests {
fmt.Printf("ID: %d\n", accessRequest.ID)
fmt.Printf("Username: %s\n", accessRequest.Username)
fmt.Printf("Name: %s\n", accessRequest.Name)
fmt.Printf("State: %s\n", accessRequest.State)
fmt.Printf("CreatedAt: %s\n", accessRequest.CreatedAt)
fmt.Printf("RequestedAt: %s\n", accessRequest.RequestedAt)
fmt.Printf("AccessLevel: %d\n", accessRequest.AccessLevel)
fmt.Println("")
}
}
}
return nil
@ -49,26 +108,81 @@ func AccessRequests() *cli.Command {
Name: "project",
Aliases: []string{"projects"},
Usage: "为项目列出访问请求",
Flags: append(flag.Common(), flag.Id(true)),
Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(), flag.Id(true)),
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.ListAccessRequestsOptions{}
opt := &gitlab.ListAccessRequestsOptions{
Page: page,
PerPage: perPage,
}
accessRequests, response, err := gitClient.AccessRequests.ListProjectAccessRequests(id, opt)
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
for index, accessRequest := range accessRequests {
log.Printf("Index: %d,\t ID: %d,\t Username: %s,\t Name: %s,\t State: %s,\t CreatedAt: %s,\t RequestedAt: %s,\t AccessLevel: %d\n", index, accessRequest.ID, accessRequest.Username, accessRequest.Name, accessRequest.State, accessRequest.CreatedAt, accessRequest.RequestedAt, accessRequest.AccessLevel)
fmt.Println("")
if printJson {
if printTime {
for _, accessRequest := range accessRequests {
jsonData, err := json.Marshal(accessRequest)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, accessRequest := range accessRequests {
jsonData, err := json.Marshal(accessRequest)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, accessRequest := range accessRequests {
log.Printf("ID: %d\n", accessRequest.ID)
log.Printf("Username: %s\n", accessRequest.Username)
log.Printf("Name: %s\n", accessRequest.Name)
log.Printf("State: %s\n", accessRequest.State)
log.Printf("CreatedAt: %s\n", accessRequest.CreatedAt)
log.Printf("RequestedAt: %s\n", accessRequest.RequestedAt)
log.Printf("AccessLevel: %d\n", accessRequest.AccessLevel)
fmt.Println("")
}
} else {
for _, accessRequest := range accessRequests {
fmt.Printf("ID: %d\n", accessRequest.ID)
fmt.Printf("Username: %s\n", accessRequest.Username)
fmt.Printf("Name: %s\n", accessRequest.Name)
fmt.Printf("State: %s\n", accessRequest.State)
fmt.Printf("CreatedAt: %s\n", accessRequest.CreatedAt)
fmt.Printf("RequestedAt: %s\n", accessRequest.RequestedAt)
fmt.Printf("AccessLevel: %d\n", accessRequest.AccessLevel)
fmt.Println("")
}
}
}
return nil

View File

@ -2,6 +2,7 @@ package boards
import (
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"github.com/xanzy/go-gitlab"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
@ -15,16 +16,22 @@ func Boards() *cli.Command {
Name: "board",
Aliases: []string{"boards"},
Usage: "项目议题板 API中文文档https://docs.gitlab.cn/jh/api/boards.html",
Flags: append(flag.Common(), flag.Id(false)),
Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Id(false)),
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "列出项目议题板",
Flags: append(flag.Common(), flag.Id(true)),
Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Id(true)),
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 {
@ -36,14 +43,56 @@ func Boards() *cli.Command {
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
for index, issueBoard := range issueBoards {
fmt.Println("")
if printJson {
if printTime {
for _, issueBoard := range issueBoards {
jsonData, err := json.Marshal(issueBoard)
if err != nil {
panic(err)
}
log.Printf("Index: %d: %s\n", index, string(jsonData))
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, issueBoard := range issueBoards {
jsonData, err := json.Marshal(issueBoard)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, issueBoard := range issueBoards {
log.Printf("ID: %d\n", issueBoard.ID)
log.Printf("Name: %s\n", issueBoard.Name)
log.Printf("Project.ID: %d\n", issueBoard.Project.ID)
// log.Printf("Project: %s\n", issueBoard.Project)
// log.Printf("User: %s\n", issueBoard.User)
fmt.Println("")
}
} else {
for _, issueBoard := range issueBoards {
fmt.Printf("ID: %d\n", issueBoard.ID)
fmt.Printf("Name: %s\n", issueBoard.Name)
fmt.Printf("Project.ID: %d\n", issueBoard.Project.ID)
// log.Printf("Project: %s\n", issueBoard.Project)
// log.Printf("User: %s\n", issueBoard.User)
fmt.Println("")
}
}
}
return nil

View File

@ -48,7 +48,7 @@ func ContainerRegistry() *cli.Command {
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
fmt.Println("")
@ -135,7 +135,7 @@ func ContainerRegistry() *cli.Command {
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
fmt.Println("")

View File

@ -1,6 +1,8 @@
package instance_level_ci_variables
import (
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"github.com/xanzy/go-gitlab"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
@ -14,30 +16,83 @@ func InstanceLevelCiVariables() *cli.Command {
Name: "instance-level-ci-variable",
Aliases: []string{"instance-level-ci-variables", "ilcv"},
Usage: "实例级 CI/CD 变量 API中文文档https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html",
Flags: append(flag.Common()),
Flags: append(flag.Common(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime()),
Subcommands: []*cli.Command{
{
Name: "get",
Usage: "列出所有实例变量",
Flags: flag.CommonTokenRequired(),
Flags: append(flag.CommonTokenRequired(), 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 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.ListInstanceVariablesOptions{}
opt := &gitlab.ListInstanceVariablesOptions{
Page: page,
PerPage: perPage,
}
variables, response, err := gitClient.InstanceVariables.ListVariables(opt)
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
for index, variable := range variables {
log.Printf("Index: %d,\t Key: %s,\t Value: %s,\t VariableType: %s,\t Protected: %t,\t Masked: %t,\t Raw: %t\n", index, variable.Key, variable.Value, variable.VariableType, variable.Protected, variable.Masked, variable.Raw)
fmt.Println("")
if printJson {
if printTime {
for _, variable := range variables {
jsonData, err := json.Marshal(variable)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, variable := range variables {
jsonData, err := json.Marshal(variable)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, variable := range variables {
log.Printf("Key: %s\n", variable.Key)
log.Printf("Username: %s\n", variable.Value)
log.Printf("Name: %s\n", variable.VariableType)
log.Printf("State: %t\n", variable.Protected)
log.Printf("CreatedAt: %t\n", variable.Masked)
log.Printf("RequestedAt: %t\n", variable.Raw)
fmt.Println("")
}
} else {
for _, variable := range variables {
fmt.Printf("Key: %s\n", variable.Key)
fmt.Printf("Username: %s\n", variable.Value)
fmt.Printf("Name: %s\n", variable.VariableType)
fmt.Printf("State: %t\n", variable.Protected)
fmt.Printf("CreatedAt: %t\n", variable.Masked)
fmt.Printf("RequestedAt: %t\n", variable.Raw)
fmt.Println("")
}
}
}
return nil

View File

@ -162,7 +162,7 @@ func Issues() *cli.Command {
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
fmt.Println("")

View File

@ -48,7 +48,7 @@ func Jobs() *cli.Command {
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
fmt.Println("")

View File

@ -1,6 +1,8 @@
package pipelines
import (
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"github.com/xanzy/go-gitlab"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
@ -14,17 +16,23 @@ func Pipelines() *cli.Command {
Name: "pipeline",
Aliases: []string{"pipelines", "pl"},
Usage: "流水线 API中文文档https://docs.gitlab.cn/jh/api/pipelines.html",
Flags: append(flag.Common(), flag.Sort(), flag.Id(false)),
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Id(false)),
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "列出项目流水线",
Flags: append(flag.Common(), flag.Sort(), flag.Id(true)),
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Id(true)),
Action: func(context *cli.Context) error {
var baseUrl = context.String(constant.BaseUrl)
var token = context.String(constant.Token)
var sort = context.String(constant.Sort)
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 {
@ -32,16 +40,64 @@ func Pipelines() *cli.Command {
}
opt := &gitlab.ListProjectPipelinesOptions{
ListOptions: gitlab.ListOptions{
Page: page,
PerPage: perPage,
},
Sort: &sort,
}
PipelineInfos, response, err := gitClient.Pipelines.ListProjectPipelines(id, opt)
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
for index, pipelineInfo := range PipelineInfos {
log.Printf("Index: %d,\t ID: %d,\t IID: %d,\t ProjectID: %d,\t Status: %s,\t CreatedAt: %s\n", index, pipelineInfo.ID, pipelineInfo.IID, pipelineInfo.ProjectID, pipelineInfo.Status, pipelineInfo.CreatedAt)
fmt.Println("")
if printJson {
if printTime {
for _, pipelineInfo := range PipelineInfos {
jsonData, err := json.Marshal(pipelineInfo)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, pipelineInfo := range PipelineInfos {
jsonData, err := json.Marshal(pipelineInfo)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, pipelineInfo := range PipelineInfos {
log.Printf("ID: %d\n", pipelineInfo.ID)
log.Printf("IID: %d\n", pipelineInfo.IID)
log.Printf("ProjectID: %d\n", pipelineInfo.ProjectID)
log.Printf("Status: %s\n", pipelineInfo.Status)
log.Printf("CreatedAt: %s\n", pipelineInfo.CreatedAt)
fmt.Println("")
}
} else {
for _, pipelineInfo := range PipelineInfos {
fmt.Printf("ID: %d\n", pipelineInfo.ID)
fmt.Printf("IID: %d\n", pipelineInfo.IID)
fmt.Printf("ProjectID: %d\n", pipelineInfo.ProjectID)
fmt.Printf("Status: %s\n", pipelineInfo.Status)
fmt.Printf("CreatedAt: %s\n", pipelineInfo.CreatedAt)
fmt.Println("")
}
}
}
return nil

View File

@ -1,6 +1,8 @@
package projects
import (
"encoding/json"
"fmt"
"github.com/urfave/cli/v2"
"github.com/xanzy/go-gitlab"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
@ -18,13 +20,15 @@ func Projects() *cli.Command {
Name: "project",
Aliases: []string{"projects", "p"},
Usage: "项目 API中文文档https://docs.gitlab.cn/jh/api/projects.html",
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.Search(), flag.SearchNamespaces(),
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Search(), flag.SearchNamespaces(),
flag.OrderBy(OrderByUsage)),
Subcommands: []*cli.Command{
{
Name: "list",
Usage: "列出所有项目",
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.Search(), flag.SearchNamespaces(),
Flags: append(flag.Common(), flag.Sort(), flag.Page(), flag.PerPage(), flag.PrintJson(), flag.PrintTime(),
flag.Search(), flag.SearchNamespaces(),
flag.OrderBy(OrderByUsage)),
Action: func(context *cli.Context) error {
var baseUrl = context.String(constant.BaseUrl)
@ -35,6 +39,8 @@ func Projects() *cli.Command {
var search = context.String(constant.Search)
var searchNamespaces = context.Bool(constant.SearchNamespaces)
var orderBy = context.String(constant.OrderBy)
var printJson = context.Bool(constant.PrintJson)
var printTime = context.Bool(constant.PrintTime)
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl))
if err != nil {
@ -55,13 +61,53 @@ func Projects() *cli.Command {
if err != nil {
return err
}
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Page %d, PerPage: %d, Response StatusCode: %d\n", page, perPage, response.Response.StatusCode)
for index, project := range projects {
log.Printf("Index: %d,\t ID: %d,\t Path: %s,\t Name: %s\n", index, project.ID, project.Path, project.Name)
fmt.Println("")
//name := strings.Replace(project.PathWithNamespace, "xuxiaowei-com-cn/", "", -1)
//fmt.Printf("git submodule add -b main ../%s.git %s\n", name, name)
if printJson {
if printTime {
for _, project := range projects {
jsonData, err := json.Marshal(project)
if err != nil {
panic(err)
}
log.Printf("\n%s\n", string(jsonData))
fmt.Println("")
}
} else {
for _, project := range projects {
jsonData, err := json.Marshal(project)
if err != nil {
panic(err)
}
fmt.Printf("%s\n", string(jsonData))
fmt.Println("")
}
}
} else {
if printTime {
for _, project := range projects {
log.Printf("ID: %d\n", project.ID)
log.Printf("Path: %s\n", project.Path)
log.Printf("Name: %s\n", project.Name)
fmt.Println("")
}
} else {
for _, project := range projects {
fmt.Printf("ID: %d\n", project.ID)
fmt.Printf("Path: %s\n", project.Path)
fmt.Printf("Name: %s\n", project.Name)
fmt.Println("")
}
}
}
return nil