MCPcopy Create free account
hub / github.com/cli/cli / NewUploader

Function NewUploader

internal/attachments/client.go:39–60  ·  view source on GitHub ↗

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 validates everything an upload needs, so a caller that gets an Uploader back can use it.

(httpClient *http.Client, tokenType gh.TokenType, host string, targetRepository int64, viewerPermission string)

Source from the content-addressed store, hash-verified

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

Callers 8

createRunFunction · 0.92
editRunFunction · 0.92
CommentableRunFunction · 0.92
createRunFunction · 0.92
editRunFunction · 0.92
newTestUploaderFunction · 0.85
TestUploadAuthenticationFunction · 0.85
TestNewUploaderFunction · 0.85

Calls 4

NewClientFromHTTPFunction · 0.92
checkHostFunction · 0.85
checkUploadTokenTypeFunction · 0.85
checkPermissionFunction · 0.85

Tested by 3

newTestUploaderFunction · 0.68
TestUploadAuthenticationFunction · 0.68
TestNewUploaderFunction · 0.68