MCPcopy
hub / github.com/cli/cli / removeRun

Function removeRun

pkg/cmd/secret/delete/delete.go:89–168  ·  view source on GitHub ↗
(opts *DeleteOptions)

Source from the content-addressed store, hash-verified

87}
88
89func removeRun(opts *DeleteOptions) error {
90 c, err := opts.HttpClient()
91 if err != nil {
92 return fmt.Errorf("could not create http client: %w", err)
93 }
94 client := api.NewClientFromHTTP(c)
95
96 orgName := opts.OrgName
97 envName := opts.EnvName
98
99 secretEntity, err := shared.GetSecretEntity(orgName, envName, opts.UserSecrets)
100 if err != nil {
101 return err
102 }
103
104 var baseRepo ghrepo.Interface
105 if secretEntity == shared.Repository || secretEntity == shared.Environment {
106 baseRepo, err = opts.BaseRepo()
107 if err != nil {
108 return err
109 }
110 }
111
112 secretApp, err := shared.GetSecretApp(opts.Application, secretEntity)
113 if err != nil {
114 return err
115 }
116
117 if !shared.IsSupportedSecretEntity(secretApp, secretEntity) {
118 return fmt.Errorf("%s secrets are not supported for %s", secretEntity, secretApp)
119 }
120
121 cfg, err := opts.Config()
122 if err != nil {
123 return err
124 }
125
126 var path string
127 var host string
128 switch secretEntity {
129 case shared.Organization:
130 path = fmt.Sprintf("orgs/%s/%s/secrets/%s", orgName, secretApp, opts.SecretName)
131 host, _ = cfg.Authentication().DefaultHost()
132 case shared.Environment:
133 path = fmt.Sprintf("repos/%s/environments/%s/secrets/%s", ghrepo.FullName(baseRepo), envName, opts.SecretName)
134 host = baseRepo.RepoHost()
135 case shared.User:
136 path = fmt.Sprintf("user/codespaces/secrets/%s", opts.SecretName)
137 host, _ = cfg.Authentication().DefaultHost()
138 case shared.Repository:
139 path = fmt.Sprintf("repos/%s/%s/secrets/%s", ghrepo.FullName(baseRepo), secretApp, opts.SecretName)
140 host = baseRepo.RepoHost()
141 }
142
143 err = client.REST(host, "DELETE", path, nil, nil)
144 if err != nil {
145 return fmt.Errorf("failed to delete secret %s: %w", opts.SecretName, err)
146 }

Callers 5

NewCmdDeleteFunction · 0.70
Test_removeRun_repoFunction · 0.70
Test_removeRun_envFunction · 0.70
Test_removeRun_orgFunction · 0.70
Test_removeRun_userFunction · 0.70

Calls 15

RepoHostMethod · 0.95
NewClientFromHTTPFunction · 0.92
GetSecretEntityFunction · 0.92
GetSecretAppFunction · 0.92
IsSupportedSecretEntityFunction · 0.92
FullNameFunction · 0.92
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconWithColorMethod · 0.80
ErrorfMethod · 0.65
BaseRepoMethod · 0.65
ConfigMethod · 0.65

Tested by 4

Test_removeRun_repoFunction · 0.56
Test_removeRun_envFunction · 0.56
Test_removeRun_orgFunction · 0.56
Test_removeRun_userFunction · 0.56