From 0ed78793299fcdac782bc80c5f7c13493c75c1c8 Mon Sep 17 00:00:00 2001 From: vilmibm Date: Tue, 10 Nov 2020 16:25:18 -0800 Subject: [PATCH] stop using Defaults struct --- pkg/cmd/pr/create/create.go | 33 +++++++++++++++------------------ pkg/cmd/pr/shared/survey.go | 5 ----- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/pkg/cmd/pr/create/create.go b/pkg/cmd/pr/create/create.go index 32bd5807d..eac02a31a 100644 --- a/pkg/cmd/pr/create/create.go +++ b/pkg/cmd/pr/create/create.go @@ -159,19 +159,12 @@ func createRun(opts *CreateOptions) (err error) { return err } - defs, defaultsErr := computeDefaults(*ctx) - if defaultsErr != nil && (opts.Autofill || opts.WebMode || !opts.Interactive) { - return fmt.Errorf("could not compute title or body defaults: %w", defaultsErr) - } - var milestoneTitles []string if opts.Milestone != "" { milestoneTitles = []string{opts.Milestone} } state := shared.IssueMetadataState{ - Title: defs.Title, - Body: defs.Body, Type: shared.PRMetadata, Reviewers: opts.Reviewers, Assignees: opts.Assignees, @@ -180,6 +173,11 @@ func createRun(opts *CreateOptions) (err error) { Milestones: milestoneTitles, } + defaultsErr := computeDefaults(*ctx, &state) + if defaultsErr != nil && (opts.Autofill || opts.WebMode || !opts.Interactive) { + return fmt.Errorf("could not compute title or body defaults: %w", defaultsErr) + } + if opts.TitleProvided { state.Title = opts.Title } @@ -297,34 +295,33 @@ func createRun(opts *CreateOptions) (err error) { return errors.New("expected to cancel, preview, or submit") } -func computeDefaults(createCtx CreateContext) (shared.Defaults, error) { - baseRef := createCtx.BaseTrackingBranch - headRef := createCtx.HeadBranch - out := shared.Defaults{} +func computeDefaults(ctx CreateContext, state *shared.IssueMetadataState) error { + baseRef := ctx.BaseTrackingBranch + headRef := ctx.HeadBranch commits, err := git.Commits(baseRef, headRef) if err != nil { - return out, err + return err } if len(commits) == 1 { - out.Title = commits[0].Title + state.Title = commits[0].Title body, err := git.CommitBody(commits[0].Sha) if err != nil { - return out, err + return err } - out.Body = body + state.Body = body } else { - out.Title = utils.Humanize(headRef) + state.Title = utils.Humanize(headRef) var body strings.Builder for i := len(commits) - 1; i >= 0; i-- { fmt.Fprintf(&body, "- %s\n", commits[i].Title) } - out.Body = body.String() + state.Body = body.String() } - return out, nil + return nil } func determineTrackingBranch(remotes context.Remotes, headBranch string) *git.TrackingRef { diff --git a/pkg/cmd/pr/shared/survey.go b/pkg/cmd/pr/shared/survey.go index da995925e..d73846113 100644 --- a/pkg/cmd/pr/shared/survey.go +++ b/pkg/cmd/pr/shared/survey.go @@ -15,11 +15,6 @@ import ( "github.com/cli/cli/utils" ) -type Defaults struct { - Title string - Body string -} - type Action int type metadataStateType int