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

Function fillPlaceholders

pkg/cmd/api/api.go:589–626  ·  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

587
588// fillPlaceholders replaces placeholders with values from the current repository
589func fillPlaceholders(value string, opts *ApiOptions) (string, error) {
590 var err error
591 return placeholderRE.ReplaceAllStringFunc(value, func(m string) string {
592 var name string
593 if m[0] == ':' {
594 name = m[1:]
595 } else {
596 name = m[1 : len(m)-1]
597 }
598
599 switch name {
600 case "owner":
601 if baseRepo, e := opts.BaseRepo(); e == nil {
602 return baseRepo.RepoOwner()
603 } else {
604 err = e
605 }
606 case "repo":
607 if baseRepo, e := opts.BaseRepo(); e == nil {
608 return baseRepo.RepoName()
609 } else {
610 err = e
611 }
612 case "branch":
613 if os.Getenv("GH_REPO") != "" {
614 err = errors.New("unable to determine an appropriate value for the 'branch' placeholder")
615 return m
616 }
617
618 if branch, e := opts.Branch(); e == nil {
619 return branch
620 } else {
621 err = e
622 }
623 }
624 return m
625 }), err
626}
627
628func printHeaders(w io.Writer, headers http.Header, colorize bool) {
629 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