2016-05-11 05:19:45 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2016-05-12 01:43:24 +00:00
|
|
|
"fmt"
|
2016-05-11 05:19:45 +00:00
|
|
|
"os"
|
|
|
|
"text/template"
|
|
|
|
|
2017-03-16 10:14:02 +00:00
|
|
|
"github.com/urfave/cli"
|
2016-05-11 05:19:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var buildQueueCmd = cli.Command{
|
2017-03-16 10:14:02 +00:00
|
|
|
Name: "queue",
|
|
|
|
Usage: "show build queue",
|
|
|
|
Action: buildQueue,
|
2016-05-11 05:19:45 +00:00
|
|
|
Flags: []cli.Flag{
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "format",
|
|
|
|
Usage: "format output",
|
|
|
|
Value: tmplBuildQueue,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func buildQueue(c *cli.Context) error {
|
|
|
|
|
|
|
|
client, err := newClient(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
builds, err := client.BuildQueue()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-05-12 01:43:24 +00:00
|
|
|
if len(builds) == 0 {
|
|
|
|
fmt.Println("there are no pending or running builds")
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-05-11 05:19:45 +00:00
|
|
|
tmpl, err := template.New("_").Parse(c.String("format") + "\n")
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
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 .Email }}<{{.Email}}>{{ end }}
|
|
|
|
Message: {{ .Message }}
|
|
|
|
`
|