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

Function removeRun

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

Source from the content-addressed store, hash-verified

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

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

RepoOwnerMethod · 0.95
RepoNameMethod · 0.95
RepoHostMethod · 0.95
StringMethod · 0.95
NewClientFromHTTPFunction · 0.92
GetSecretEntityFunction · 0.92
GetSecretAppFunction · 0.92
IsSupportedSecretEntityFunction · 0.92
JoinPathFunction · 0.92
FullNameFunction · 0.92
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80

Tested by 4

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