使用 log 替换 fmt

This commit is contained in:
徐晓伟 2023-10-09 10:18:31 +08:00
parent 596d9c01e0
commit 2b85630271
6 changed files with 23 additions and 22 deletions

View File

@ -1,11 +1,11 @@
package access_requests
import (
"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"
)
// AccessRequests 群组和项目访问请求 API https://docs.gitlab.cn/jh/api/access_requests.html
@ -33,13 +33,13 @@ func AccessRequests() *cli.Command {
opt := &gitlab.ListAccessRequestsOptions{}
accessRequests, response, err := gitClient.AccessRequests.ListGroupAccessRequests(id, opt)
fmt.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
for index, accessRequest := range accessRequests {
fmt.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)
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)
}
return nil
@ -62,13 +62,13 @@ func AccessRequests() *cli.Command {
opt := &gitlab.ListAccessRequestsOptions{}
accessRequests, response, err := gitClient.AccessRequests.ListProjectAccessRequests(id, opt)
fmt.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
for index, accessRequest := range accessRequests {
fmt.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)
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)
}
return nil

View File

@ -1,11 +1,11 @@
package instance_level_ci_variables
import (
"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"
)
// InstanceLevelCiVariables 实例级 CI/CD 变量 API https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html
@ -31,13 +31,13 @@ func InstanceLevelCiVariables() *cli.Command {
opt := &gitlab.ListInstanceVariablesOptions{}
variables, response, err := gitClient.InstanceVariables.ListVariables(opt)
fmt.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
for index, variable := range variables {
fmt.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)
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)
}
return nil

View File

@ -6,6 +6,7 @@ import (
"github.com/xanzy/go-gitlab"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
"github.com/xuxiaowei-com-cn/gitlab-go/flag"
"log"
)
// JobsArtifacts 作业产物 API https://docs.gitlab.cn/jh/api/job_artifacts.html
@ -21,7 +22,7 @@ func JobsArtifacts() *cli.Command {
Usage: "获取作业产物(未完成)",
Flags: append(flag.Common(), flag.Id(true), flag.JobId(false)),
Action: func(context *cli.Context) error {
fmt.Println("获取作业产物")
log.Printf("获取作业产物")
return fmt.Errorf("未完成")
},
@ -53,9 +54,9 @@ func JobsArtifacts() *cli.Command {
return err
}
fmt.Printf("Delete ProjectId: %s, JobId: %d Artifacts\n", id, jobId)
log.Printf("Delete ProjectId: %s, JobId: %d Artifacts\n", id, jobId)
response, err := gitClient.Jobs.DeleteArtifacts(id, jobId)
fmt.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
@ -78,9 +79,9 @@ func JobsArtifacts() *cli.Command {
return err
}
fmt.Printf("Delete ProjectId: %s Artifacts\n", id)
log.Printf("Delete ProjectId: %s Artifacts\n", id)
response, err := gitClient.Jobs.DeleteProjectArtifacts(id)
fmt.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}

View File

@ -1,11 +1,11 @@
package jobs
import (
"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"
)
// Jobs 作业 API https://docs.gitlab.cn/jh/api/jobs.html
@ -32,13 +32,13 @@ func Jobs() *cli.Command {
opt := &gitlab.ListJobsOptions{}
jobs, response, err := gitClient.Jobs.ListProjectJobs(id, opt)
fmt.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
for index, job := range jobs {
fmt.Printf("Index: %d,\t ID: %d,\t Name: %s,\t ProjectID: %d,\t Status: %s,\t CreatedAt: %s\n", index, job.ID, job.Name, job.Project.ID, job.Status, job.CreatedAt)
log.Printf("Index: %d,\t ID: %d,\t Name: %s,\t ProjectID: %d,\t Status: %s,\t CreatedAt: %s\n", index, job.ID, job.Name, job.Project.ID, job.Status, job.CreatedAt)
}
return nil

View File

@ -1,11 +1,11 @@
package pipelines
import (
"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"
)
// Pipelines 流水线 API https://docs.gitlab.cn/jh/api/pipelines.html
@ -35,13 +35,13 @@ func Pipelines() *cli.Command {
Sort: &sort,
}
PipelineInfos, response, err := gitClient.Pipelines.ListProjectPipelines(id, opt)
fmt.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
for index, pipelineInfo := range PipelineInfos {
fmt.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)
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)
}
return nil

View File

@ -1,11 +1,11 @@
package projects
import (
"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"
)
// Projects 项目 API https://docs.gitlab.cn/jh/api/projects.html
@ -34,13 +34,13 @@ func Projects() *cli.Command {
Sort: &sort,
}
projects, response, err := gitClient.Projects.ListProjects(opt)
fmt.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
log.Printf("Response StatusCode: %d\n", response.Response.StatusCode)
if err != nil {
return err
}
for index, project := range projects {
fmt.Printf("Index: %d,\t ID: %d,\t Path: %s,\t Name: %s\n", index, project.ID, project.Path, project.Name)
log.Printf("Index: %d,\t ID: %d,\t Path: %s,\t Name: %s\n", index, project.ID, project.Path, project.Name)
}
return nil