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

Function removeRun

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

Source from the content-addressed store, hash-verified

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

Callers 2

NewCmdDeleteFunction · 0.70
TestRemoveRunFunction · 0.70

Calls 13

RepoHostMethod · 0.95
NewClientFromHTTPFunction · 0.92
GetVariableEntityFunction · 0.92
FullNameFunction · 0.92
IsStdoutTTYMethod · 0.80
ColorSchemeMethod · 0.80
SuccessIconWithColorMethod · 0.80
ErrorfMethod · 0.65
BaseRepoMethod · 0.65
ConfigMethod · 0.65
DefaultHostMethod · 0.65
AuthenticationMethod · 0.65

Tested by 1

TestRemoveRunFunction · 0.56