Skip to content

Commit

Permalink
added environment command
Browse files Browse the repository at this point in the history
  • Loading branch information
bradrydzewski committed Nov 16, 2020
1 parent bed84a3 commit a63407a
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
103 changes: 103 additions & 0 deletions drone/plugins/environ/environ.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package environ

import (
"context"
"fmt"

"github.com/drone/drone-cli/drone/internal"
"github.com/drone/drone-go/drone"
"github.com/drone/drone-go/plugin/environ"
"github.com/urfave/cli"
)

// Command exports the admission command set.
var Command = cli.Command{
Name: "env",
Usage: "test env extensions",
Action: environAction,
Flags: []cli.Flag{

//
// build and repository details
//

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",
},

cli.StringFlag{
Name: "endpoint",
Usage: "plugin endpoint",
EnvVar: "DRONE_ENVIRON_ENDPOINT",
},
cli.StringFlag{
Name: "secret",
Usage: "plugin secret",
EnvVar: "DRONE_ENVIRON_SECRET",
},
cli.StringFlag{
Name: "ssl-skip-verify",
Usage: "plugin ssl verification disabled",
EnvVar: "DRONE_ENVIRON_SKIP_VERIFY",
},
},
}

func environAction(c *cli.Context) error {
slug := c.String("repository")
owner, name, _ := internal.ParseRepo(slug)

req := &environ.Request{
Repo: drone.Repo{
Namespace: owner,
Name: name,
Slug: slug,
},
Build: drone.Build{
Ref: c.String("ref"),
Before: c.String("before"),
After: c.String("after"),
Source: c.String("source"),
Target: c.String("target"),
},
}

client := environ.Client(
c.String("endpoint"),
c.String("secret"),
c.Bool("ssl-skip-verify"),
)
list, err := client.List(context.Background(), req)
if err != nil {
return err
}

for k, v := range list {
fmt.Printf("%s=%s\n", k, v)
}
return nil
}
4 changes: 3 additions & 1 deletion drone/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/drone/drone-cli/drone/plugins/admit"
"github.com/drone/drone-cli/drone/plugins/config"
"github.com/drone/drone-cli/drone/plugins/convert"
"github.com/drone/drone-cli/drone/plugins/environ"
"github.com/drone/drone-cli/drone/plugins/registry"
"github.com/drone/drone-cli/drone/plugins/secret"

Expand All @@ -18,7 +19,8 @@ var Command = cli.Command{
admit.Command,
config.Command,
convert.Command,
secret.Command,
environ.Command,
registry.Command,
secret.Command,
},
}

0 comments on commit a63407a

Please sign in to comment.