review feedback

This commit is contained in:
vilmibm 2020-03-16 14:49:07 -05:00
parent a23549001e
commit 2d90c09f48
4 changed files with 11 additions and 29 deletions

View file

@ -38,9 +38,9 @@ func computeDefaults(baseRef, headRef string) (defaults, error) {
} else {
out.Title = headRef // TODO format or something?
body := fmt.Sprintf("---\n%d commits:\n\n", len(commits))
body := ""
for _, c := range commits {
body += fmt.Sprintf("- %s %s\n", c.Sha[0:5], c.Title)
body += fmt.Sprintf("- %s\n", c.Title)
}
out.Body = body
}
@ -103,7 +103,7 @@ func prCreate(cmd *cobra.Command, _ []string) error {
defs, err := computeDefaults(baseBranch, headBranch)
if err != nil {
return fmt.Errorf("could not compute title or body defaults: %w", err)
fmt.Fprintf(colorableErr(cmd), "%s warning: could not compute title or body defaults: %w\n", utils.Yellow("!"), err)
}
isWeb, err := cmd.Flags().GetBool("web")

View file

@ -245,7 +245,7 @@ func TestPRCreate_survey_defaults_multicommit(t *testing.T) {
}{}
json.Unmarshal(bodyBytes, &reqBody)
expectedBody := "---\n2 commits:\n\n- 12345 commit 0\n- 23456 commit 1\n"
expectedBody := "- commit 0\n- commit 1\n"
eq(t, reqBody.Variables.Input.RepositoryID, "REPOID")
eq(t, reqBody.Variables.Input.Title, "feature")
@ -322,22 +322,3 @@ func TestPRCreate_survey_defaults_monocommit(t *testing.T) {
eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n")
}
func TestPRCreate_survey_defaults_no_changes(t *testing.T) {
initBlankContext("OWNER/REPO", "feature")
http := initFakeHTTP()
http.StubRepoResponse("OWNER", "REPO")
cs, cmdTeardown := initCmdStubber()
defer cmdTeardown()
cs.Stub("") // git status
cs.Stub("") // git log
_, err := RunCommand(prCreateCmd, `pr create`)
if err == nil {
t.Error("expected error")
}
eq(t, err.Error(), "could not compute title or body defaults: could not find any commits between master and feature")
}

View file

@ -27,7 +27,7 @@ var SurveyAsk = func(qs []*survey.Question, response interface{}, opts ...survey
return survey.Ask(qs, response, opts...)
}
var ConfirmSubmission = func() (Action, error) {
func confirmSubmission() (Action, error) {
confirmAnswers := struct {
Confirmation int
}{}
@ -53,7 +53,7 @@ var ConfirmSubmission = func() (Action, error) {
return Action(confirmAnswers.Confirmation), nil
}
var SelectTemplate = func(templatePaths []string) (string, error) {
func selectTemplate(templatePaths []string) (string, error) {
templateResponse := struct {
Index int
}{}
@ -89,7 +89,7 @@ func titleBodySurvey(cmd *cobra.Command, providedTitle, providedBody string, def
if providedBody == "" {
if len(templatePaths) > 0 {
var err error
templateContents, err = SelectTemplate(templatePaths)
templateContents, err = selectTemplate(templatePaths)
if err != nil {
return nil, err
}
@ -136,7 +136,7 @@ func titleBodySurvey(cmd *cobra.Command, providedTitle, providedBody string, def
inProgress.Body = templateContents
}
confirmA, err := ConfirmSubmission()
confirmA, err := confirmSubmission()
if err != nil {
return nil, fmt.Errorf("unable to confirm: %w", err)
}

View file

@ -78,8 +78,9 @@ type Commit struct {
func Commits(baseRef, headRef string) ([]*Commit, error) {
logCmd := GitCommand(
"-c", "log.ShowSignature=false",
"log", "--pretty=format:%H,%s",
fmt.Sprintf("%s..%s", baseRef, headRef))
"--cherry", fmt.Sprintf("%s...%s", baseRef, headRef))
output, err := utils.PrepareCmd(logCmd).Output()
if err != nil {
return []*Commit{}, err
@ -107,7 +108,7 @@ func Commits(baseRef, headRef string) ([]*Commit, error) {
}
func CommitBody(sha string) (string, error) {
showCmd := GitCommand("show", "-s", "--pretty=format:%b", sha)
showCmd := GitCommand("-c", "log.ShowSignature=false", "show", "-s", "--pretty=format:%b", sha)
output, err := utils.PrepareCmd(showCmd).Output()
if err != nil {
return "", err