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