Skip to content

Commit

Permalink
add queue pause and resume
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Oct 22, 2018
1 parent f12f74e commit 3c26d22
Show file tree
Hide file tree
Showing 10 changed files with 208 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion drone/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ var Command = cli.Command{
buildStartCmd,
buildApproveCmd,
buildDeclineCmd,
buildQueueCmd,
buildPromoteCmd,
buildRollbackCmd,
},
Expand Down
122 changes: 61 additions & 61 deletions drone/build/build_queue.go
Original file line number Diff line number Diff line change
@@ -1,63 +1,63 @@
package build

import (
"fmt"
"os"
"text/template"

"github.com/drone/drone-cli/drone/internal"
"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,
},
},
}

func buildQueue(c *cli.Context) error {

client, err := internal.NewClient(c)
if err != nil {
return err
}

builds, err := client.BuildQueue()
if err != nil {
return err
}

if len(builds) == 0 {
fmt.Println("there are no pending or running builds")
return nil
}

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 .AuthorEmail }}<{{.AuthorEmail}}>{{ end }}
Message: {{ .Message }}
`
// import (
// "fmt"
// "os"
// "text/template"

// "github.com/drone/drone-cli/drone/internal"
// "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,
// },
// },
// }

// func buildQueue(c *cli.Context) error {

// client, err := internal.NewClient(c)
// if err != nil {
// return err
// }

// builds, err := client.BuildQueue()
// if err != nil {
// return err
// }

// if len(builds) == 0 {
// fmt.Println("there are no pending or running builds")
// return nil
// }

// 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 .AuthorEmail }}<{{.AuthorEmail}}>{{ end }}
// Message: {{ .Message }}
// `
2 changes: 2 additions & 0 deletions drone/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/drone/drone-cli/drone/jsonnet"
"github.com/drone/drone-cli/drone/log"
"github.com/drone/drone-cli/drone/plugins"
"github.com/drone/drone-cli/drone/queue"
"github.com/drone/drone-cli/drone/repo"
"github.com/drone/drone-cli/drone/secret"
"github.com/drone/drone-cli/drone/server"
Expand Down Expand Up @@ -80,6 +81,7 @@ func main() {
user.Command,
secret.Command,
server.Command,
queue.Command,
autoscale.Command,
format.Command,
sign.Command,
Expand Down
14 changes: 14 additions & 0 deletions drone/queue/queue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package queue

import "github.com/urfave/cli"

// Command exports the queue command set.
var Command = cli.Command{
Name: "queue",
Usage: "queue operations",
Subcommands: []cli.Command{
queueListCmd,
queuePauseCmd,
queueResumeCmd,
},
}
58 changes: 58 additions & 0 deletions drone/queue/queue_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package queue

import (
"fmt"
"os"
"text/template"

"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)

var queueListCmd = cli.Command{
Name: "ls",
Usage: "list queue items",
Action: queueList,
Flags: []cli.Flag{
cli.StringFlag{
Name: "format",
Usage: "format output",
Value: tmplStage,
},
},
}

func queueList(c *cli.Context) (err error) {
client, err := internal.NewClient(c)
if err != nil {
return err
}
builds, err := client.Queue()
if err != nil {
return err
}

if len(builds) == 0 {
fmt.Println("there are no pending or running builds")
return nil
}

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
}

var tmplStage = "\x1b[33mitem #{{ .ID }} \x1b[0m" + `
Status: {{ .Status }}
Machine: {{ .Machine }}
OS: {{ .OS }}
Arch: {{ .Arch }}
Variant: {{ .Variant }}
Version: {{ .Kernel }}
`
20 changes: 20 additions & 0 deletions drone/queue/queue_pause.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package queue

import (
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)

var queuePauseCmd = cli.Command{
Name: "pause",
Usage: "pause queue operations",
Action: queuePause,
}

func queuePause(c *cli.Context) (err error) {
client, err := internal.NewClient(c)
if err != nil {
return err
}
return client.QueuePause()
}
20 changes: 20 additions & 0 deletions drone/queue/queue_resume.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package queue

import (
"github.com/drone/drone-cli/drone/internal"
"github.com/urfave/cli"
)

var queueResumeCmd = cli.Command{
Name: "resume",
Usage: "resume queue operations",
Action: queueResume,
}

func queueResume(c *cli.Context) (err error) {
client, err := internal.NewClient(c)
if err != nil {
return err
}
return client.QueueResume()
}
32 changes: 23 additions & 9 deletions vendor/github.com/drone/drone-go/drone/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 9 additions & 3 deletions vendor/github.com/drone/drone-go/drone/interface.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3c26d22

Please sign in to comment.