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

Function uploadDeployKey

pkg/cmd/repo/deploy-key/add/http.go:14–40  ·  view source on GitHub ↗
(httpClient *http.Client, repo ghrepo.Interface, keyFile io.Reader, title string, isWritable bool)

Source from the content-addressed store, hash-verified

12)
13
14func uploadDeployKey(httpClient *http.Client, repo ghrepo.Interface, keyFile io.Reader, title string, isWritable bool) error {
15 path, err := safeurl.JoinPath("repos", repo.RepoOwner(), repo.RepoName(), "keys")
16 if err != nil {
17 return err
18 }
19
20 keyBytes, err := io.ReadAll(keyFile)
21 if err != nil {
22 return err
23 }
24
25 payload := map[string]any{
26 "title": title,
27 "key": string(keyBytes),
28 "read_only": !isWritable,
29 }
30
31 payloadBytes, err := json.Marshal(payload)
32 if err != nil {
33 return err
34 }
35
36 // TODO(api-client-rollout)
37 // This line of code is part of a mechanical roll out of the api client.
38 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
39 return api.NewClientFromHTTP(httpClient).REST(repo.RepoHost(), "POST", path.String(), bytes.NewBuffer(payloadBytes), nil)
40}

Callers 2

addRunFunction · 0.85

Calls 7

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RESTMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65

Tested by 1