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

Function initDefaultTitleBody

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

Source from the content-addressed store, hash-verified

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