Skip to content

Commit

Permalink
fix: fix check_golang_profiler_changes - pass pr body as file not arg…
Browse files Browse the repository at this point in the history
…ument (#62)
  • Loading branch information
korniltsev authored Oct 27, 2023
1 parent d4c3674 commit 53446ca
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions godeltaprof/compat/cmd/check_golang_profiler_changes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,17 +97,20 @@ out:
}
}
}

prBodyFile := createTempFile(msg)

if found == -1 {
log.Println("existing PR not found, creating a new one")
createPR(msg)
createPR(prBodyFile)
} else {
log.Printf("found existing PR %+v. updating.", prs[found])
updatePR(msg, prs[found])
updatePR(prBodyFile, prs[found])
}

}

func updatePR(msg string, request PullRequest) {
func updatePR(prBodyFile string, request PullRequest) {
branchName := createBranchName()
commitMessage := createCommitMessage()

Expand All @@ -119,11 +122,11 @@ func updatePR(msg string, request PullRequest) {
shMy.sh(fmt.Sprintf("git commit -am '%s'", commitMessage))
shMy.sh(fmt.Sprintf("git push -f %s %s:%s", myRemote, branchName, request.HeadRefName))

shMy.sh(fmt.Sprintf("gh pr edit %d --body '%s'", request.Number, msg))
shMy.sh(fmt.Sprintf("gh pr edit %d --body-file '%s'", request.Number, prBodyFile))

}

func createPR(msg string) {
func createPR(prBodyFile string) {
branchName := createBranchName()
commitMessage := createCommitMessage()

Expand All @@ -135,7 +138,7 @@ func createPR(msg string) {
shMy.sh(fmt.Sprintf("git commit -am '%s'", commitMessage))
shMy.sh(fmt.Sprintf("git push %s %s", myRemote, branchName))

shMy.sh(fmt.Sprintf("gh pr create --title '%s' --body '%s' --label '%s' ", commitMessage, msg, label))
shMy.sh(fmt.Sprintf("gh pr create --title '%s' --body-file '%s' --label '%s' ", commitMessage, prBodyFile, label))

}

Expand Down Expand Up @@ -210,6 +213,16 @@ func getRepoDir() string {
return path.Join(cwd, repoDir)
}

func createTempFile(body string) string {
prBodyFile, err := os.CreateTemp("", "check_golang_profiler_changes")
requireNoError(err, "create temp file")
prBodyFilePath := prBodyFile.Name()
defer os.Remove(prBodyFilePath)
prBodyFile.Write([]byte(body))
prBodyFile.Close()
return prBodyFilePath
}

type PullRequest struct {
BaseRefName string `json:"baseRefName"`
HeadRefName string `json:"headRefName"`
Expand Down

0 comments on commit 53446ca

Please sign in to comment.