diff --git a/client/client.go b/client/client.go index 0ed884d9b..d959d7b9c 100644 --- a/client/client.go +++ b/client/client.go @@ -102,6 +102,12 @@ type Client interface { // the prior history. 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(string, string, int, int) (io.ReadCloser, error) diff --git a/client/client_impl.go b/client/client_impl.go index 182bc7e0d..0f316797c 100644 --- a/client/client_impl.go +++ b/client/client_impl.go @@ -34,6 +34,8 @@ const ( pathEncrypt = "%s/api/repos/%s/%s/encrypt" pathBuilds = "%s/api/repos/%s/%s/builds" 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" pathLog = "%s/api/repos/%s/%s/logs/%d/%d" 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 } +// 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. func (c *client) BuildLogs(owner, name string, num, job int) (io.ReadCloser, error) { uri := fmt.Sprintf(pathLog, c.base, owner, name, num, job) diff --git a/drone/build.go b/drone/build.go index 65c1ece14..78572952f 100644 --- a/drone/build.go +++ b/drone/build.go @@ -12,6 +12,8 @@ var buildCmd = cli.Command{ buildInfoCmd, buildStopCmd, buildStartCmd, + buildApproveCmd, + buildDeclineCmd, buildQueueCmd, }, } diff --git a/drone/build_approve.go b/drone/build_approve.go new file mode 100644 index 000000000..a9dfff482 --- /dev/null +++ b/drone/build_approve.go @@ -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 +} diff --git a/drone/build_decline.go b/drone/build_decline.go new file mode 100644 index 000000000..fb4ce35d3 --- /dev/null +++ b/drone/build_decline.go @@ -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 +}