-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathprCreator.go
More file actions
52 lines (40 loc) · 1.07 KB
/
prCreator.go
File metadata and controls
52 lines (40 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package utils
import (
"log"
"os"
"os/exec"
"github.com/google/uuid"
_ "embed"
)
//go:embed prCreator.sh
var prCreatorScriptContent string
func CreatePr(dryRun bool) bool {
uuid := uuid.New().String()
prBranchName := "codacy-cli-fix-" + uuid
cmd := exec.Command("/bin/sh")
cmd.Env = append(cmd.Env, "PR_BRANCH_NAME="+prBranchName)
if dryRun {
log.Println("Would create PR with branch name " + prBranchName)
log.Println("Commands:")
log.Println(prCreatorScriptContent)
return false
} else {
tmpFile, err := os.CreateTemp(os.TempDir(), "prCreator*.sh")
defer os.Remove(tmpFile.Name())
if err != nil {
log.Fatal("Error creating the temporary file for the script:", err)
}
_, err = tmpFile.WriteString(prCreatorScriptContent)
if err != nil {
log.Fatal("Error writing the script temporary file:", err)
}
// Execute the script
cmd := exec.Command("/bin/sh", tmpFile.Name(), prBranchName)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
log.Fatal("Error executing script:", err)
}
return true
}
}