stop using Defaults struct
This commit is contained in:
parent
1c280d4341
commit
0ed7879329
2 changed files with 15 additions and 23 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -15,11 +15,6 @@ import (
|
|||
"github.com/cli/cli/utils"
|
||||
)
|
||||
|
||||
type Defaults struct {
|
||||
Title string
|
||||
Body string
|
||||
}
|
||||
|
||||
type Action int
|
||||
type metadataStateType int
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue