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

Function initDefaultTitleBody

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

Source from the content-addressed store, hash-verified

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