Feat: load git remote from drone env
continuous-integration/drone/push Build is passing Details

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
1 changed files with 11 additions and 6 deletions

View File

@ -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
}