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

Function fillPlaceholders

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

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