1
0
mirror of https://github.com/drone/drone-cli.git synced 2025-05-01 05:38:00 +02:00

command for testing converter plugin

This commit is contained in:
Brad Rydzewski 2019-09-01 15:58:47 -07:00
parent cf2392c5bd
commit 419f4830df
5 changed files with 127 additions and 1 deletions

BIN
drone/drone Executable file

Binary file not shown.

@ -0,0 +1,122 @@
package convert
import (
"context"
"io/ioutil"
"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/drone/drone-go/plugin/converter"
"github.com/urfave/cli"
)
// Command exports the registry command set.
var Command = cli.Command{
Name: "convert",
Usage: "convert the pipeline configuration",
ArgsUsage: "[repo/name]",
Action: convert,
Flags: []cli.Flag{
cli.StringFlag{
Name: "path",
Usage: "path to the configuration file",
},
cli.StringFlag{
Name: "ref",
Usage: "git reference",
Value: "refs/heads/master",
},
cli.StringFlag{
Name: "source",
Usage: "source branch",
Value: "master",
},
cli.StringFlag{
Name: "target",
Usage: "target branch",
Value: "master",
},
cli.StringFlag{
Name: "before",
Usage: "commit sha before the change",
},
cli.StringFlag{
Name: "after",
Usage: "commit sha after the change",
},
cli.StringFlag{
Name: "repository",
Usage: "repository name",
},
// TODO(bradrydzewski) these parameters should
// be defined globally for all plugin commands.
cli.StringFlag{
Name: "endpoint",
Usage: "plugin endpoint",
EnvVar: "DRONE_CONVERT_ENDPOINT",
},
cli.StringFlag{
Name: "secret",
Usage: "plugin secret",
EnvVar: "DRONE_CONVERT_SECRET",
},
cli.StringFlag{
Name: "ssl-skip-verify",
Usage: "plugin ssl verification disabled",
EnvVar: "DRONE_CONVERT_SKIP_VERIFY",
},
},
}
func convert(c *cli.Context) error {
slug := c.String("repository")
owner, name, _ := internal.ParseRepo(slug)
path := c.String("path")
if path == "" {
path = c.Args().First()
}
raw, err := ioutil.ReadFile(path)
if err != nil {
return err
}
req := &converter.Request{
Repo: drone.Repo{
Namespace: owner,
Name: name,
Slug: slug,
Config: path,
},
Build: drone.Build{
Ref: c.String("ref"),
Before: c.String("before"),
After: c.String("after"),
Source: c.String("source"),
Target: c.String("target"),
},
Config: drone.Config{
Data: string(raw),
},
}
client := converter.Client(
c.String("endpoint"),
c.String("secret"),
c.Bool("ssl-skip-verify"),
)
res, err := client.Convert(context.Background(), req)
if err != nil {
return err
}
switch {
case res == nil:
println(string(raw))
case res != nil:
println(res.Data)
}
return nil
}

@ -2,6 +2,7 @@ package plugins
import (
"github.com/drone/drone-cli/drone/plugins/config"
"github.com/drone/drone-cli/drone/plugins/convert"
"github.com/drone/drone-cli/drone/plugins/registry"
"github.com/drone/drone-cli/drone/plugins/secret"
@ -14,6 +15,7 @@ var Command = cli.Command{
Usage: "plugin helper functions",
Subcommands: []cli.Command{
config.Command,
convert.Command,
secret.Command,
registry.Command,
},

2
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 v0.0.0-20190809073937-cba78c0895aa
github.com/drone/drone-go v1.0.6
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

2
go.sum

@ -21,6 +21,8 @@ github.com/docker/go-units v0.3.3 h1:Xk8S3Xj5sLGlG5g67hJmYMmUgXv5N4PhkjJHHqrwnTk
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/drone/drone-go v0.0.0-20190809073937-cba78c0895aa h1:XRCcOdGaOUd74BZRO4T0XZeEo5h4j/dkod7TV6JI0pk=
github.com/drone/drone-go v0.0.0-20190809073937-cba78c0895aa/go.mod h1:GxyeGClYohaKNYJv/ZpsmVHtMJ7WhoT+uDaJNcDIrk4=
github.com/drone/drone-go v1.0.6 h1:YbMwEwlE3HC4InN0bT21EDvzImct5dGG1I56dSdUhjI=
github.com/drone/drone-go v1.0.6/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=