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

Function fillPlaceholders

pkg/cmd/api/api.go:552–589  ·  view source on GitHub ↗

fillPlaceholders replaces placeholders with values from the current repository

(value string, opts *ApiOptions)

Source from the content-addressed store, hash-verified

550
551// fillPlaceholders replaces placeholders with values from the current repository
552func fillPlaceholders(value string, opts *ApiOptions) (string, error) {
553 var err error
554 return placeholderRE.ReplaceAllStringFunc(value, func(m string) string {
555 var name string
556 if m[0] == ':' {
557 name = m[1:]
558 } else {
559 name = m[1 : len(m)-1]
560 }
561
562 switch name {
563 case "owner":
564 if baseRepo, e := opts.BaseRepo(); e == nil {
565 return baseRepo.RepoOwner()
566 } else {
567 err = e
568 }
569 case "repo":
570 if baseRepo, e := opts.BaseRepo(); e == nil {
571 return baseRepo.RepoName()
572 } else {
573 err = e
574 }
575 case "branch":
576 if os.Getenv("GH_REPO") != "" {
577 err = errors.New("unable to determine an appropriate value for the 'branch' placeholder")
578 return m
579 }
580
581 if branch, e := opts.Branch(); e == nil {
582 return branch
583 } else {
584 err = e
585 }
586 }
587 return m
588 }), err
589}
590
591func printHeaders(w io.Writer, headers http.Header, colorize bool) {
592 var names []string

Callers 3

apiRunFunction · 0.85
magicFieldValueFunction · 0.85
Test_fillPlaceholdersFunction · 0.85

Calls 3

BaseRepoMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65

Tested by 1

Test_fillPlaceholdersFunction · 0.68