diff --git a/pkg/plugin/types.go b/pkg/plugin/types.go index 59642bc..daafe24 100644 --- a/pkg/plugin/types.go +++ b/pkg/plugin/types.go @@ -8,6 +8,18 @@ package plugin import "time" type ( + // Pipeline being executed. + // + // Represents the full Drone environment that the plugin is executing in. + Pipeline struct { + Build Build + Repo Repo + Commit Commit + Stage Stage + Step Step + SemVer SemVer + } + // Build represents a build of a repository. Build struct { // Action that triggered the build. This value is used to differentiate diff --git a/pkg/urfave/urfave.go b/pkg/urfave/urfave.go index 4803b1f..90d7ca2 100644 --- a/pkg/urfave/urfave.go +++ b/pkg/urfave/urfave.go @@ -38,6 +38,36 @@ import ( "github.com/drone-plugins/drone-plugin-lib/pkg/plugin" ) +//--------------------------------------------------------------------- +// Pipeline +//--------------------------------------------------------------------- + +// PipelineFlags has the cli.Flags for the plugin.Pipeline. +func PipelineFlags() []cli.Flag { + flags := []cli.Flag{} + + flags = append(flags, BuildFlags()...) + flags = append(flags, RepoFlags()...) + flags = append(flags, CommitFlags()...) + flags = append(flags, StageFlags()...) + flags = append(flags, StepFlags()...) + flags = append(flags, SemVerFlags()...) + + return flags +} + +// PipelineFromContext creates a plugin.Pipeline from the cli.Context. +func PipelineFromContext(ctx *cli.Context) plugin.Environment { + return plugin.Pipeline{ + Build: BuildFromContext(ctx), + Repo: RepoFromContext(ctx), + Commit: CommitFromContext(ctx), + Stage: StageFromContext(ctx), + Step: StepFromContext(ctx), + SemVer: SemVerFromContext(ctx), + } +} + //--------------------------------------------------------------------- // Build Flags //---------------------------------------------------------------------