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

View File

@ -26,6 +26,7 @@ type Args struct {
Folder string `envconfig:"PLUGIN_FOLDER"`
SshKey string `envconfig:"PLUGIN_SSH_KEY"`
GitRemote string `envconfig:"PLUGIN_GIT_REMOTE"`
GitBranch string `envconfig:"PLUGIN_GIT_BRANCH"`
GitRemoteFromDrone string `envconfig:"DRONE_GIT_SSH_URL"`
}
@ -87,6 +88,10 @@ func checkArgs(args *Args) error {
args.GitRemote = args.GitRemoteFromDrone
}
if args.GitBranch == "" {
args.GitBranch = BRANCH_NAME
}
return nil
}
@ -127,7 +132,7 @@ func copyFiles(args Args) error {
func initRepo(args Args) error {
cmd := exec.Command(
"git",
"init", "-b", BRANCH_NAME, "/tmp/pages")
"init", "-b", args.GitBranch, "/tmp/pages")
if err := execute(cmd); err != nil {
return err
@ -149,7 +154,7 @@ func doCommit(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 {