diff --git a/README.md b/README.md index 3ee9b3b..8a0f6a9 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,7 @@ AUTHOR: COMMANDS: 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 instance-level-ci-variable, instance-level-ci-variables, ilcv 实例级 CI/CD 变量 API,中文文档:https://docs.gitlab.cn/jh/api/instance_level_ci_variables.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 @@ -193,6 +194,27 @@ COPYRIGHT: --help, -h show help ``` +- [board - 项目议题板 API](https://docs.gitlab.cn/jh/api/boards.html) + + ```shell + $ go run main.go board --help + NAME: + gitlab-go board - 项目议题板 API,中文文档:https://docs.gitlab.cn/jh/api/boards.html + + USAGE: + gitlab-go board command [command options] [arguments...] + + COMMANDS: + list 列出项目议题板 + 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 编码的路径 + --help, -h show help + ``` + - [instance-level-ci-variable - 实例级 CI/CD 变量 API](https://docs.gitlab.cn/jh/api/instance_level_ci_variables.html) ```shell diff --git a/boards/boards.go b/boards/boards.go new file mode 100644 index 0000000..99a7ff6 --- /dev/null +++ b/boards/boards.go @@ -0,0 +1,54 @@ +package boards + +import ( + "encoding/json" + "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" +) + +// Boards 项目议题板 API https://docs.gitlab.cn/jh/api/boards.html +func Boards() *cli.Command { + return &cli.Command{ + Name: "board", + Aliases: []string{"boards"}, + Usage: "项目议题板 API,中文文档:https://docs.gitlab.cn/jh/api/boards.html", + Flags: append(flag.Common(), flag.Id(false)), + Subcommands: []*cli.Command{ + { + Name: "list", + Usage: "列出项目议题板", + Flags: append(flag.Common(), 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) + + gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl)) + if err != nil { + return err + } + + opt := &gitlab.ListIssueBoardsOptions{} + issueBoards, response, err := gitClient.Boards.ListIssueBoards(id, opt) + log.Printf("Response StatusCode: %d\n", response.Response.StatusCode) + if err != nil { + return err + } + + for index, issueBoard := range issueBoards { + jsonData, err := json.Marshal(issueBoard) + if err != nil { + panic(err) + } + log.Printf("Index: %d: %s\n", index, string(jsonData)) + } + + return nil + }, + }, + }, + } +} diff --git a/main.go b/main.go index b56570b..66b0cc3 100644 --- a/main.go +++ b/main.go @@ -4,6 +4,7 @@ import ( "fmt" "github.com/xuxiaowei-com-cn/git-go/buildinfo" "github.com/xuxiaowei-com-cn/gitlab-go/access_requests" + "github.com/xuxiaowei-com-cn/gitlab-go/boards" "github.com/xuxiaowei-com-cn/gitlab-go/instance_level_ci_variables" "github.com/xuxiaowei-com-cn/gitlab-go/job_artifacts" "github.com/xuxiaowei-com-cn/gitlab-go/jobs" @@ -63,6 +64,7 @@ func main() { Copyright: Copyright, Commands: []*cli.Command{ access_requests.AccessRequests(), + boards.Boards(), instance_level_ci_variables.InstanceLevelCiVariables(), job_artifacts.JobsArtifacts(), jobs.Jobs(),