Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix check_golang_profiler_changes - pass pr body as file not argument #62

Merged
merged 1 commit into from
Oct 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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