Feat: Allow to set branch

This commit is contained in:
Dorian Zedler 2022-07-23 21:17:55 +02:00
parent 560450aeed
commit 4e2b785248
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"`
GitBranch string `envconfig:"PLUGIN_GIT_BRANCH"`
GitRemoteFromDrone string `envconfig:"DRONE_GIT_SSH_URL"` GitRemoteFromDrone string `envconfig:"DRONE_GIT_SSH_URL"`
} }
@ -87,6 +88,10 @@ func checkArgs(args *Args) error {
args.GitRemote = args.GitRemoteFromDrone args.GitRemote = args.GitRemoteFromDrone
} }
if args.GitBranch == "" {
args.GitBranch = BRANCH_NAME
}
return nil return nil
} }
@ -127,7 +132,7 @@ func copyFiles(args Args) error {
func initRepo(args Args) error { func initRepo(args Args) error {
cmd := exec.Command( cmd := exec.Command(
"git", "git",
"init", "-b", BRANCH_NAME, "/tmp/pages") "init", "-b", args.GitBranch, "/tmp/pages")
if err := execute(cmd); err != nil { if err := execute(cmd); err != nil {
return err return err
@ -149,7 +154,7 @@ func doCommit(args Args) error {
} }
func push(args Args) error { func push(args Args) error {
return execute(repo.RemotePushNamedBranch(args.GitRemote, BRANCH_NAME, BRANCH_NAME, true, false)) return execute(repo.RemotePushNamedBranch(args.GitRemote, args.GitBranch, args.GitBranch, true, false))
} }
func execute(cmd *exec.Cmd) error { func execute(cmd *exec.Cmd) error {