Feat: load git remote from drone env
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Dorian Zedler 2022-07-23 20:54:33 +02:00
parent d964a5c94c
commit 560450aeed
Signed by: dorian
GPG key ID: 989DE36109AFA354

View file

@ -26,6 +26,7 @@ type Args struct {
Folder string `envconfig:"PLUGIN_FOLDER"` Folder string `envconfig:"PLUGIN_FOLDER"`
SshKey string `envconfig:"PLUGIN_SSH_KEY"` SshKey string `envconfig:"PLUGIN_SSH_KEY"`
GitRemote string `envconfig:"PLUGIN_GIT_REMOTE"` GitRemote string `envconfig:"PLUGIN_GIT_REMOTE"`
GitRemoteFromDrone string `envconfig:"DRONE_GIT_SSH_URL"`
} }
const BRANCH_NAME = "pages" const BRANCH_NAME = "pages"
@ -33,7 +34,7 @@ const BRANCH_NAME = "pages"
// Exec executes the plugin. // Exec executes the plugin.
func Exec(ctx context.Context, args Args) error { func Exec(ctx context.Context, args Args) error {
if err := checkArgs(args); err != nil { if err := checkArgs(&args); err != nil {
return err return err
} }
@ -65,7 +66,7 @@ func Exec(ctx context.Context, args Args) error {
return nil return nil
} }
func checkArgs(args Args) error { func checkArgs(args *Args) error {
if args.Folder == "" { if args.Folder == "" {
return errors.New("PLUGIN_FOLDER is required!") return errors.New("PLUGIN_FOLDER is required!")
} }
@ -78,10 +79,14 @@ func checkArgs(args Args) error {
return errors.New("PLUGIN_SSH_KEY is required!") return errors.New("PLUGIN_SSH_KEY is required!")
} }
if args.GitRemote == "" { if args.GitRemote == "" && args.GitRemoteFromDrone == "" {
return errors.New("PLUGIN_GIT_REMOTE is required!") return errors.New("PLUGIN_GIT_REMOTE is required!")
} }
if args.GitRemote == "" && args.GitRemoteFromDrone != "" {
args.GitRemote = args.GitRemoteFromDrone
}
return nil return nil
} }