NewUploader prepares uploads against targetRepository, the numeric REST id of the repository the assets are uploaded against, and viewerPermission, the GraphQL viewerPermission field on that same repository. It refuses what gh can tell will not upload. The credential is left to the endpoint, which a
(httpClient *http.Client, host string, targetRepository int64, viewerPermission string)
| 36 | // upload work, so any other order would name a fault the user cannot fix. The |
| 37 | // other checks are free to move. |
| 38 | func NewUploader(httpClient *http.Client, host string, targetRepository int64, viewerPermission string) (*Uploader, error) { |
| 39 | if err := checkHost(host); err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | |
| 43 | if targetRepository <= 0 { |
| 44 | return nil, errors.New("could not determine which repository to attach files to") |
| 45 | } |
| 46 | |
| 47 | if err := checkPermission(viewerPermission); err != nil { |
| 48 | return nil, err |
| 49 | } |
| 50 | |
| 51 | // TODO(api-client-rollout) |
| 52 | // This line of code is part of a mechanical roll out of the api client. |
| 53 | // As a follow up, consider whether the api client can be injected to this call site, rather than constructed |
| 54 | return &Uploader{client: api.NewClientFromHTTP(httpClient), host: host, targetRepository: targetRepository}, nil |
| 55 | } |
| 56 | |
| 57 | // checkHost rejects a host that cannot serve the upload endpoint. IsEnterprise |
| 58 | // is false for ghe.com tenants, so data residency keeps working. |