add approve/decline to client/cli
This commit is contained in:
parent
e319aaff15
commit
a4e03defdc
5 changed files with 104 additions and 0 deletions
|
@ -102,6 +102,12 @@ type Client interface {
|
||||||
// the prior history.
|
// the prior history.
|
||||||
BuildFork(string, string, int, map[string]string) (*model.Build, error)
|
BuildFork(string, string, int, map[string]string) (*model.Build, error)
|
||||||
|
|
||||||
|
// BuildApprove approves a blocked build.
|
||||||
|
BuildApprove(string, string, int) (*model.Build, error)
|
||||||
|
|
||||||
|
// BuildDecline declines a blocked build.
|
||||||
|
BuildDecline(string, string, int) (*model.Build, error)
|
||||||
|
|
||||||
// BuildLogs returns the build logs for the specified job.
|
// BuildLogs returns the build logs for the specified job.
|
||||||
BuildLogs(string, string, int, int) (io.ReadCloser, error)
|
BuildLogs(string, string, int, int) (io.ReadCloser, error)
|
||||||
|
|
||||||
|
|
|
@ -34,6 +34,8 @@ const (
|
||||||
pathEncrypt = "%s/api/repos/%s/%s/encrypt"
|
pathEncrypt = "%s/api/repos/%s/%s/encrypt"
|
||||||
pathBuilds = "%s/api/repos/%s/%s/builds"
|
pathBuilds = "%s/api/repos/%s/%s/builds"
|
||||||
pathBuild = "%s/api/repos/%s/%s/builds/%v"
|
pathBuild = "%s/api/repos/%s/%s/builds/%v"
|
||||||
|
pathApprove = "%s/api/repos/%s/%s/builds/%d/approve"
|
||||||
|
pathDecline = "%s/api/repos/%s/%s/builds/%d/decline"
|
||||||
pathJob = "%s/api/repos/%s/%s/builds/%d/%d"
|
pathJob = "%s/api/repos/%s/%s/builds/%d/%d"
|
||||||
pathLog = "%s/api/repos/%s/%s/logs/%d/%d"
|
pathLog = "%s/api/repos/%s/%s/logs/%d/%d"
|
||||||
pathKey = "%s/api/repos/%s/%s/key"
|
pathKey = "%s/api/repos/%s/%s/key"
|
||||||
|
@ -257,6 +259,22 @@ func (c *client) BuildFork(owner, name string, num int, params map[string]string
|
||||||
return out, err
|
return out, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BuildApprove approves a blocked build.
|
||||||
|
func (c *client) BuildApprove(owner, name string, num int) (*model.Build, error) {
|
||||||
|
out := new(model.Build)
|
||||||
|
uri := fmt.Sprintf(pathApprove, c.base, owner, name, num)
|
||||||
|
err := c.post(uri, nil, out)
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// BuildDecline declines a blocked build.
|
||||||
|
func (c *client) BuildDecline(owner, name string, num int) (*model.Build, error) {
|
||||||
|
out := new(model.Build)
|
||||||
|
uri := fmt.Sprintf(pathDecline, c.base, owner, name, num)
|
||||||
|
err := c.post(uri, nil, out)
|
||||||
|
return out, err
|
||||||
|
}
|
||||||
|
|
||||||
// BuildLogs returns the build logs for the specified job.
|
// BuildLogs returns the build logs for the specified job.
|
||||||
func (c *client) BuildLogs(owner, name string, num, job int) (io.ReadCloser, error) {
|
func (c *client) BuildLogs(owner, name string, num, job int) (io.ReadCloser, error) {
|
||||||
uri := fmt.Sprintf(pathLog, c.base, owner, name, num, job)
|
uri := fmt.Sprintf(pathLog, c.base, owner, name, num, job)
|
||||||
|
|
|
@ -12,6 +12,8 @@ var buildCmd = cli.Command{
|
||||||
buildInfoCmd,
|
buildInfoCmd,
|
||||||
buildStopCmd,
|
buildStopCmd,
|
||||||
buildStartCmd,
|
buildStartCmd,
|
||||||
|
buildApproveCmd,
|
||||||
|
buildDeclineCmd,
|
||||||
buildQueueCmd,
|
buildQueueCmd,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
39
drone/build_approve.go
Normal file
39
drone/build_approve.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var buildApproveCmd = cli.Command{
|
||||||
|
Name: "approve",
|
||||||
|
Usage: "approve a build",
|
||||||
|
Action: buildApprove,
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildApprove(c *cli.Context) (err error) {
|
||||||
|
repo := c.Args().First()
|
||||||
|
owner, name, err := parseRepo(repo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
number, err := strconv.Atoi(c.Args().Get(1))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := newClient(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = client.BuildApprove(owner, name, number)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Approving build %s/%s#%d\n", owner, name, number)
|
||||||
|
return nil
|
||||||
|
}
|
39
drone/build_decline.go
Normal file
39
drone/build_decline.go
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/urfave/cli"
|
||||||
|
)
|
||||||
|
|
||||||
|
var buildDeclineCmd = cli.Command{
|
||||||
|
Name: "decline",
|
||||||
|
Usage: "decline a build",
|
||||||
|
Action: buildDecline,
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildDecline(c *cli.Context) (err error) {
|
||||||
|
repo := c.Args().First()
|
||||||
|
owner, name, err := parseRepo(repo)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
number, err := strconv.Atoi(c.Args().Get(1))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
client, err := newClient(c)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = client.BuildDecline(owner, name, number)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Declining build %s/%s#%d\n", owner, name, number)
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in a new issue