| 69 | } |
| 70 | |
| 71 | func 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 != "" { |