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

Function fillPlaceholders

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

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