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

Function fillPlaceholders

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

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