| 70 | } |
| 71 | |
| 72 | func 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 | } |