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

Function listRun

pkg/cmd/secret/list/list.go:107–221  ·  view source on GitHub ↗
(opts *ListOptions)

Source from the content-addressed store, hash-verified

105}
106
107func listRun(opts *ListOptions) error {
108 client, err := opts.HttpClient()
109 if err != nil {
110 return fmt.Errorf("could not create http client: %w", err)
111 }
112
113 orgName := opts.OrgName
114 envName := opts.EnvName
115
116 var baseRepo ghrepo.Interface
117 if orgName == "" && !opts.UserSecrets {
118 baseRepo, err = opts.BaseRepo()
119 if err != nil {
120 return err
121 }
122 }
123
124 secretEntity, err := shared.GetSecretEntity(orgName, envName, opts.UserSecrets)
125 if err != nil {
126 return err
127 }
128
129 secretApp, err := shared.GetSecretApp(opts.Application, secretEntity)
130 if err != nil {
131 return err
132 }
133
134 if !shared.IsSupportedSecretEntity(secretApp, secretEntity) {
135 return fmt.Errorf("%s secrets are not supported for %s", secretEntity, secretApp)
136 }
137
138 // Since populating the `NumSelectedRepos` field costs further API requests
139 // (one per secret), it's important to avoid extra calls when the output will
140 // not present the field's value. So, we should only populate this field in
141 // these cases:
142 // 1. The command is run in the TTY mode without the `--json <fields>` option.
143 // 2. The command is run with `--json <fields>` option, and `numSelectedRepos`
144 // is among the selected fields. In this case, TTY mode is irrelevant.
145 showSelectedRepoInfo := opts.IO.IsStdoutTTY()
146 if opts.Exporter != nil {
147 // Note that if there's an exporter set, then we don't mind the TTY mode
148 // because we just have to populate the requested fields.
149 showSelectedRepoInfo = slices.Contains(opts.Exporter.Fields(), fieldNumSelectedRepos)
150 }
151
152 var secrets []Secret
153 switch secretEntity {
154 case shared.Repository:
155 secrets, err = getRepoSecrets(client, baseRepo, secretApp)
156 case shared.Environment:
157 secrets, err = getEnvSecrets(client, baseRepo, envName)
158 case shared.Organization, shared.User:
159 var cfg gh.Config
160 var host string
161
162 cfg, err = opts.Config()
163 if err != nil {
164 return err

Callers 3

Test_listRunFunction · 0.70
NewCmdListFunction · 0.70

Calls 15

AuthenticationMethod · 0.95
GetSecretEntityFunction · 0.92
GetSecretAppFunction · 0.92
IsSupportedSecretEntityFunction · 0.92
NewNoResultsErrorFunction · 0.92
NewFunction · 0.92
WithHeaderFunction · 0.92
getRepoSecretsFunction · 0.85
getEnvSecretsFunction · 0.85
getUserSecretsFunction · 0.85
getOrgSecretsFunction · 0.85
IsStdoutTTYMethod · 0.80

Tested by 2

Test_listRunFunction · 0.56