From 06d273c3532a1f40543341c8427089613acd1691 Mon Sep 17 00:00:00 2001 From: Thomas Boerger Date: Wed, 18 Mar 2020 15:20:08 +0100 Subject: [PATCH] Integrate build create command --- drone/build/build.go | 1 + drone/build/build_create.go | 56 +++++++++++++++++++++++++++++++++++++ go.mod | 2 +- go.sum | 4 +++ 4 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 drone/build/build_create.go diff --git a/drone/build/build.go b/drone/build/build.go index 790ebe0..92d40c1 100644 --- a/drone/build/build.go +++ b/drone/build/build.go @@ -10,6 +10,7 @@ var Command = cli.Command{ buildListCmd, buildLastCmd, buildInfoCmd, + buildCreateCmd, buildStopCmd, buildStartCmd, buildApproveCmd, diff --git a/drone/build/build_create.go b/drone/build/build_create.go new file mode 100644 index 0000000..6066e31 --- /dev/null +++ b/drone/build/build_create.go @@ -0,0 +1,56 @@ +package build + +import ( + "os" + "text/template" + + "github.com/drone/drone-cli/drone/internal" + "github.com/drone/funcmap" + "github.com/urfave/cli" +) + +var buildCreateCmd = cli.Command{ + Name: "create", + Usage: "create a build", + ArgsUsage: "", + Action: buildCreate, + Flags: []cli.Flag{ + cli.StringFlag{ + Name: "commit", + Usage: "source commit", + }, + cli.StringFlag{ + Name: "branch", + Usage: "source branch", + }, + cli.StringFlag{ + Name: "format", + Usage: "format output", + Value: tmplBuildInfo, + }, + }, +} + +func buildCreate(c *cli.Context) (err error) { + repo := c.Args().First() + owner, name, err := internal.ParseRepo(repo) + if err != nil { + return err + } + + client, err := internal.NewClient(c) + if err != nil { + return err + } + + build, err := client.BuildCreate(owner, name, c.String("commit"), c.String("branch")) + if err != nil { + return err + } + + tmpl, err := template.New("_").Funcs(funcmap.Funcs).Parse(c.String("format")) + if err != nil { + return err + } + return tmpl.Execute(os.Stdout, build) +} diff --git a/go.mod b/go.mod index ffefde4..cf2e7a5 100644 --- a/go.mod +++ b/go.mod @@ -11,7 +11,7 @@ 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.7-0.20191002153459-173e210cf8d6 + github.com/drone/drone-go v1.3.0 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 diff --git a/go.sum b/go.sum index 055552e..939d6ee 100644 --- a/go.sum +++ b/go.sum @@ -27,6 +27,10 @@ github.com/drone/drone-go v1.0.7-0.20190918192642-21c14e63f89a h1:GgG6EpzcAx9Gav github.com/drone/drone-go v1.0.7-0.20190918192642-21c14e63f89a/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4= github.com/drone/drone-go v1.0.7-0.20191002153459-173e210cf8d6 h1:qwBSqbhs6hLMsqALZ/CUEqZawlK1Sui4Bn1nNTJfDHY= github.com/drone/drone-go v1.0.7-0.20191002153459-173e210cf8d6/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4= +github.com/drone/drone-go v1.2.0 h1:Gnp79mJHf4Q5Kwkw2nIRQcj7ZAA/kqKNEz5dJ3n/0Uk= +github.com/drone/drone-go v1.2.0/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4= +github.com/drone/drone-go v1.3.0 h1:eIk79qCiw+hzmDFYSofZKrR7E0tPs7Vm13kKH80n0zs= +github.com/drone/drone-go v1.3.0/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=