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

Function removeRun

pkg/cmd/variable/delete/delete.go:72–140  ·  view source on GitHub ↗
(opts *DeleteOptions)

Source from the content-addressed store, hash-verified

70}
71
72func removeRun(opts *DeleteOptions) error {
73 c, err := opts.HttpClient()
74 if err != nil {
75 return fmt.Errorf("could not create http client: %w", err)
76 }
77 client := api.NewClientFromHTTP(c)
78
79 orgName := opts.OrgName
80 envName := opts.EnvName
81
82 variableEntity, err := shared.GetVariableEntity(orgName, envName)
83 if err != nil {
84 return err
85 }
86
87 var baseRepo ghrepo.Interface
88 if variableEntity == shared.Repository || variableEntity == shared.Environment {
89 baseRepo, err = opts.BaseRepo()
90 if err != nil {
91 return err
92 }
93 }
94
95 cfg, err := opts.Config()
96 if err != nil {
97 return err
98 }
99
100 var path *safeurl.MutableSafeURL
101 var host string
102 switch variableEntity {
103 case shared.Organization:
104 path, err = safeurl.JoinPath("orgs", orgName, "actions", "variables", opts.VariableName)
105 host, _ = cfg.Authentication().DefaultHost()
106 case shared.Environment:
107 path, err = safeurl.JoinPath("repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "environments", envName, "variables", opts.VariableName)
108 host = baseRepo.RepoHost()
109 case shared.Repository:
110 path, err = safeurl.JoinPath("repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "actions", "variables", opts.VariableName)
111 host = baseRepo.RepoHost()
112 }
113 if err != nil {
114 return err
115 }
116
117 err = client.REST(host, "DELETE", path.String(), nil, nil)
118 if err != nil {
119 return fmt.Errorf("failed to delete variable %s: %w", opts.VariableName, err)
120 }
121
122 if opts.IO.IsStdoutTTY() {
123 var target string
124 switch variableEntity {
125 case shared.Organization:
126 target = orgName
127 case shared.Repository, shared.Environment:
128 target = ghrepo.FullName(baseRepo)
129 }

Callers 2

NewCmdDeleteFunction · 0.70
TestRemoveRunFunction · 0.70

Calls 15

RepoOwnerMethod · 0.95
RepoNameMethod · 0.95
RepoHostMethod · 0.95
StringMethod · 0.95
NewClientFromHTTPFunction · 0.92
GetVariableEntityFunction · 0.92
JoinPathFunction · 0.92
FullNameFunction · 0.92
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconWithColorMethod · 0.80
ErrorfMethod · 0.65

Tested by 1

TestRemoveRunFunction · 0.56