From 560450aeeda4be74307beca25975aef96614e96f Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Sat, 23 Jul 2022 20:54:33 +0200 Subject: [PATCH] Feat: load git remote from drone env --- plugin/plugin.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/plugin/plugin.go b/plugin/plugin.go index deac56a..4fd66d5 100644 --- a/plugin/plugin.go +++ b/plugin/plugin.go @@ -23,9 +23,10 @@ type Args struct { // Level defines the plugin log level. Level string `envconfig:"PLUGIN_LOG_LEVEL"` - Folder string `envconfig:"PLUGIN_FOLDER"` - SshKey string `envconfig:"PLUGIN_SSH_KEY"` - GitRemote string `envconfig:"PLUGIN_GIT_REMOTE"` + Folder string `envconfig:"PLUGIN_FOLDER"` + SshKey string `envconfig:"PLUGIN_SSH_KEY"` + GitRemote string `envconfig:"PLUGIN_GIT_REMOTE"` + GitRemoteFromDrone string `envconfig:"DRONE_GIT_SSH_URL"` } const BRANCH_NAME = "pages" @@ -33,7 +34,7 @@ const BRANCH_NAME = "pages" // Exec executes the plugin. func Exec(ctx context.Context, args Args) error { - if err := checkArgs(args); err != nil { + if err := checkArgs(&args); err != nil { return err } @@ -65,7 +66,7 @@ func Exec(ctx context.Context, args Args) error { return nil } -func checkArgs(args Args) error { +func checkArgs(args *Args) error { if args.Folder == "" { return errors.New("PLUGIN_FOLDER is required!") } @@ -78,10 +79,14 @@ func checkArgs(args Args) error { return errors.New("PLUGIN_SSH_KEY is required!") } - if args.GitRemote == "" { + if args.GitRemote == "" && args.GitRemoteFromDrone == "" { return errors.New("PLUGIN_GIT_REMOTE is required!") } + if args.GitRemote == "" && args.GitRemoteFromDrone != "" { + args.GitRemote = args.GitRemoteFromDrone + } + return nil }