mirror of
https://github.com/drone/drone-cli.git
synced 2024-11-23 01:11:57 +01:00
Merge pull request #154 from tboerger/incomplete-builds
Implement build queue command
This commit is contained in:
commit
a986f7c87c
@ -16,5 +16,6 @@ var Command = cli.Command{
|
||||
buildDeclineCmd,
|
||||
buildPromoteCmd,
|
||||
buildRollbackCmd,
|
||||
buildQueueCmd,
|
||||
},
|
||||
}
|
||||
|
@ -1,63 +1,93 @@
|
||||
package build
|
||||
|
||||
// import (
|
||||
// "fmt"
|
||||
// "os"
|
||||
// "text/template"
|
||||
import (
|
||||
"os"
|
||||
"text/template"
|
||||
|
||||
// "github.com/drone/drone-cli/drone/internal"
|
||||
// "github.com/urfave/cli"
|
||||
// )
|
||||
"github.com/drone/drone-cli/drone/internal"
|
||||
"github.com/drone/funcmap"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// var buildQueueCmd = cli.Command{
|
||||
// Name: "queue",
|
||||
// Usage: "show build queue",
|
||||
// ArgsUsage: " ",
|
||||
// Action: buildQueue,
|
||||
// Flags: []cli.Flag{
|
||||
// cli.StringFlag{
|
||||
// Name: "format",
|
||||
// Usage: "format output",
|
||||
// Value: tmplBuildQueue,
|
||||
// },
|
||||
// },
|
||||
// }
|
||||
var buildQueueCmd = cli.Command{
|
||||
Name: "queue",
|
||||
Usage: "show build queue",
|
||||
ArgsUsage: "",
|
||||
Action: buildQueue,
|
||||
Flags: []cli.Flag{
|
||||
cli.StringFlag{
|
||||
Name: "format",
|
||||
Usage: "format output",
|
||||
Value: tmplBuildQueue,
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "repo",
|
||||
Usage: "repo filter",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "branch",
|
||||
Usage: "branch filter",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "event",
|
||||
Usage: "event filter",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "status",
|
||||
Usage: "status filter",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// func buildQueue(c *cli.Context) error {
|
||||
func buildQueue(c *cli.Context) error {
|
||||
client, err := internal.NewClient(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// client, err := internal.NewClient(c)
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
repos, err := client.Incomplete()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// builds, err := client.BuildQueue()
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format") + "\n")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// if len(builds) == 0 {
|
||||
// fmt.Println("there are no pending or running builds")
|
||||
// return nil
|
||||
// }
|
||||
slug := c.String("repo")
|
||||
branch := c.String("branch")
|
||||
event := c.String("event")
|
||||
status := c.String("status")
|
||||
|
||||
// tmpl, err := template.New("_").Parse(c.String("format") + "\n")
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
for _, repo := range repos {
|
||||
if slug != "" && repo.Slug != slug {
|
||||
continue
|
||||
}
|
||||
if branch != "" && repo.Build.Target != branch {
|
||||
continue
|
||||
}
|
||||
if event != "" && repo.Build.Event != event {
|
||||
continue
|
||||
}
|
||||
if status != "" && repo.Build.Status != status {
|
||||
continue
|
||||
}
|
||||
tmpl.Execute(os.Stdout, repo)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// for _, build := range builds {
|
||||
// tmpl.Execute(os.Stdout, build)
|
||||
// }
|
||||
// return nil
|
||||
// }
|
||||
|
||||
// // template for build list information
|
||||
// var tmplBuildQueue = "\x1b[33m{{ .FullName }} #{{ .Number }} \x1b[0m" + `
|
||||
// Status: {{ .Status }}
|
||||
// Event: {{ .Event }}
|
||||
// Commit: {{ .Commit }}
|
||||
// Branch: {{ .Branch }}
|
||||
// Ref: {{ .Ref }}
|
||||
// Author: {{ .Author }} {{ if .AuthorEmail }}<{{.AuthorEmail}}>{{ end }}
|
||||
// Message: {{ .Message }}
|
||||
// `
|
||||
// template for build queue information
|
||||
var tmplBuildQueue = "\x1b[33m{{ .Slug }}#{{ .Build.Number }} \x1b[0m" + `
|
||||
Name: {{ .Slug }}
|
||||
Build: {{ .Build.Number }}
|
||||
Status: {{ .Build.Status }}
|
||||
Event: {{ .Build.Event }}
|
||||
Branch: {{ .Build.Target }}
|
||||
Ref: {{ .Build.Ref }}
|
||||
Author: {{ .Build.Author }}{{ if .Build.AuthorEmail }} <{{ .Build.AuthorEmail }}>{{ end }}
|
||||
Created: {{ .Build.Created | time }}
|
||||
Started: {{ .Build.Started | time }}
|
||||
Updated: {{ .Build.Updated | time }}
|
||||
`
|
||||
|
4
go.mod
4
go.mod
@ -11,15 +11,17 @@ require (
|
||||
github.com/docker/distribution v2.7.1+incompatible
|
||||
github.com/docker/go-connections v0.3.0
|
||||
github.com/docker/go-units v0.3.3
|
||||
github.com/drone/drone-go v1.0.6
|
||||
github.com/drone/drone-go v1.0.7-0.20190918192642-21c14e63f89a
|
||||
github.com/drone/drone-runtime v1.0.7-0.20190729070836-38f28a11afe8
|
||||
github.com/drone/drone-yaml v0.0.0-20190729072335-70fa398b3560
|
||||
github.com/drone/envsubst v1.0.1
|
||||
github.com/drone/funcmap v0.0.0-20190918184546-d4ef6e88376d
|
||||
github.com/drone/signal v1.0.0
|
||||
github.com/fatih/color v1.7.0
|
||||
github.com/ghodss/yaml v1.0.0
|
||||
github.com/gogo/protobuf v0.0.0-20170307180453-100ba4e88506
|
||||
github.com/golang/protobuf v1.2.0
|
||||
github.com/google/go-cmp v0.3.1 // indirect
|
||||
github.com/google/go-jsonnet v0.11.2
|
||||
github.com/jackspirou/syscerts v0.0.0-20160531025014-b68f5469dff1
|
||||
github.com/joho/godotenv v1.3.0
|
||||
|
5
go.sum
5
go.sum
@ -23,6 +23,8 @@ github.com/drone/drone-go v0.0.0-20190809073937-cba78c0895aa h1:XRCcOdGaOUd74BZR
|
||||
github.com/drone/drone-go v0.0.0-20190809073937-cba78c0895aa/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4=
|
||||
github.com/drone/drone-go v1.0.6 h1:YbMwEwlE3HC4InN0bT21EDvzImct5dGG1I56dSdUhjI=
|
||||
github.com/drone/drone-go v1.0.6/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4=
|
||||
github.com/drone/drone-go v1.0.7-0.20190918192642-21c14e63f89a h1:GgG6EpzcAx9GavIZONS10tm32kvaz4FYpggWOCvwE7M=
|
||||
github.com/drone/drone-go v1.0.7-0.20190918192642-21c14e63f89a/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4=
|
||||
github.com/drone/drone-runtime v0.0.0-20190729082142-807d0aeaa221/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs=
|
||||
github.com/drone/drone-runtime v1.0.7-0.20190729070836-38f28a11afe8 h1:lcS2z7+ZySmVM+XJJjBZZPTcn6IB1BSfLWtDGyco3xo=
|
||||
github.com/drone/drone-runtime v1.0.7-0.20190729070836-38f28a11afe8/go.mod h1:+osgwGADc/nyl40J0fdsf8Z09bgcBZXvXXnLOY48zYs=
|
||||
@ -30,6 +32,8 @@ github.com/drone/drone-yaml v0.0.0-20190729072335-70fa398b3560 h1:3QL4NnDpGtaXpg
|
||||
github.com/drone/drone-yaml v0.0.0-20190729072335-70fa398b3560/go.mod h1:rCLISp/rqZ50s6G4nKsm971tRSzolxzqqXfgjDqPYoE=
|
||||
github.com/drone/envsubst v1.0.1 h1:NOOStingM2sbBwsIUeQkKUz8ShwCUzmqMxWrpXItfPE=
|
||||
github.com/drone/envsubst v1.0.1/go.mod h1:bkZbnc/2vh1M12Ecn7EYScpI4YGYU0etwLJICOWi8Z0=
|
||||
github.com/drone/funcmap v0.0.0-20190918184546-d4ef6e88376d h1:/IO7UVVu191Jc0DajV4cDVoO+91cuppvgxg2MZl+AXI=
|
||||
github.com/drone/funcmap v0.0.0-20190918184546-d4ef6e88376d/go.mod h1:Hph0/pT6ZxbujnE1Z6/08p5I0XXuOsppqF6NQlGOK0E=
|
||||
github.com/drone/signal v1.0.0 h1:NrnM2M/4yAuU/tXs6RP1a1ZfxnaHwYkd0kJurA1p6uI=
|
||||
github.com/drone/signal v1.0.0/go.mod h1:S8t92eFT0g4WUgEc/LxG+LCuiskpMNsG0ajAMGnyZpc=
|
||||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||
@ -43,6 +47,7 @@ github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfb
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-jsonnet v0.11.2 h1:oSCkvGPE72ouWJLOajr4p0clGFCOFmwhqo52faGsudk=
|
||||
github.com/google/go-jsonnet v0.11.2/go.mod h1:gVu3UVSfOt5fRFq+dh9duBqXa5905QY8S1QvMNcEIVs=
|
||||
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||
|
Loading…
Reference in New Issue
Block a user