MCPcopy Create free account
hub / github.com/cli/cli / initDefaultTitleBody

Function initDefaultTitleBody

pkg/cmd/pr/create/create.go:708–736  ·  view source on GitHub ↗
(ctx CreateContext, state *shared.IssueMetadataState, useFirstCommit bool, addBody bool)

Source from the content-addressed store, hash-verified

706var regexPattern = regexp.MustCompile(`(?m)^`)
707
708func initDefaultTitleBody(ctx CreateContext, state *shared.IssueMetadataState, useFirstCommit bool, addBody bool) error {
709 commits, err := ctx.GitClient.Commits(context.Background(), ctx.BaseTrackingBranch, ctx.PRRefs.UnqualifiedHeadRef())
710 if err != nil {
711 return err
712 }
713
714 if len(commits) == 1 || useFirstCommit {
715 state.Title = commits[len(commits)-1].Title
716 state.Body = commits[len(commits)-1].Body
717 } else {
718 state.Title = humanize(ctx.PRRefs.UnqualifiedHeadRef())
719 var body strings.Builder
720 for i := len(commits) - 1; i >= 0; i-- {
721 fmt.Fprintf(&body, "- **%s**\n", commits[i].Title)
722 if addBody {
723 x := regexPattern.ReplaceAllString(commits[i].Body, " ")
724 fmt.Fprintf(&body, "%s", x)
725
726 if i > 0 {
727 fmt.Fprintln(&body)
728 fmt.Fprintln(&body)
729 }
730 }
731 }
732 state.Body = body.String()
733 }
734
735 return nil
736}
737
738func NewIssueState(ctx CreateContext, opts CreateOptions, apiActorsSupported bool) (*shared.IssueMetadataState, error) {
739 var milestoneTitles []string

Callers 1

NewIssueStateFunction · 0.85

Calls 4

humanizeFunction · 0.85
CommitsMethod · 0.65
UnqualifiedHeadRefMethod · 0.65
StringMethod · 0.65

Tested by

no test coverage detected