MCPcopy Index your code
hub / github.com/cli/cli / initDefaultTitleBody

Function initDefaultTitleBody

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

Source from the content-addressed store, hash-verified

643var regexPattern = regexp.MustCompile(`(?m)^`)
644
645func initDefaultTitleBody(ctx CreateContext, state *shared.IssueMetadataState, useFirstCommit bool, addBody bool) error {
646 commits, err := ctx.GitClient.Commits(context.Background(), ctx.BaseTrackingBranch, ctx.PRRefs.UnqualifiedHeadRef())
647 if err != nil {
648 return err
649 }
650
651 if len(commits) == 1 || useFirstCommit {
652 state.Title = commits[len(commits)-1].Title
653 state.Body = commits[len(commits)-1].Body
654 } else {
655 state.Title = humanize(ctx.PRRefs.UnqualifiedHeadRef())
656 var body strings.Builder
657 for i := len(commits) - 1; i >= 0; i-- {
658 fmt.Fprintf(&body, "- **%s**\n", commits[i].Title)
659 if addBody {
660 x := regexPattern.ReplaceAllString(commits[i].Body, " ")
661 fmt.Fprintf(&body, "%s", x)
662
663 if i > 0 {
664 fmt.Fprintln(&body)
665 fmt.Fprintln(&body)
666 }
667 }
668 }
669 state.Body = body.String()
670 }
671
672 return nil
673}
674
675func NewIssueState(ctx CreateContext, opts CreateOptions, apiActorsSupported bool) (*shared.IssueMetadataState, error) {
676 var milestoneTitles []string

Callers 1

NewIssueStateFunction · 0.85

Calls 4

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

Tested by

no test coverage detected