提交 b78cce1b 编写于 作者: 徐晓伟's avatar 徐晓伟

🚧 Pipelines 流水线 API

上级 b0a23f63
......@@ -3,6 +3,7 @@ package main
import (
"fmt"
"github.com/xuxiaowei-com-cn/git-go/buildinfo"
"github.com/xuxiaowei-com-cn/gitlab-go/pipelines"
"github.com/xuxiaowei-com-cn/gitlab-go/projects"
"gopkg.in/yaml.v3"
"log"
......@@ -53,6 +54,7 @@ func main() {
Usage: Description,
Commands: []*cli.Command{
projects.Projects(),
pipelines.Pipelines(),
},
}
......
package pipelines
import (
"fmt"
"github.com/urfave/cli/v2"
"github.com/xanzy/go-gitlab"
"github.com/xuxiaowei-com-cn/gitlab-go/constant"
)
// Pipelines 流水线 API https://docs.gitlab.cn/jh/api/pipelines.html
func Pipelines() *cli.Command {
return &cli.Command{
Name: "pipelines",
Aliases: []string{"pl"},
Usage: "流水线 API,中文文档:https://docs.gitlab.cn/jh/api/pipelines.html",
Action: func(context *cli.Context) error {
var token = context.String(constant.Token)
var baseUrl = context.String(constant.BaseUrl)
var id = context.String(constant.Id)
if baseUrl == "" {
baseUrl = constant.BaseUrlDefault
}
gitClient, err := gitlab.NewClient(token, gitlab.WithBaseURL(baseUrl))
if err != nil {
return err
}
opt := &gitlab.ListProjectPipelinesOptions{}
PipelineInfos, response, err := gitClient.Pipelines.ListProjectPipelines(id, opt)
fmt.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)
}
return nil
},
Flags: []cli.Flag{
&cli.StringFlag{
Name: constant.Token,
Usage: "your_access_token",
},
&cli.StringFlag{
Name: constant.BaseUrl,
Usage: "实例地址,例如:https://gitlab.xuxiaowei.com.cn/api/v4",
},
&cli.StringFlag{
Name: constant.Id,
Usage: "项目 ID 或 URL 编码的路径",
Required: true,
},
},
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册