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

Function uploadDeployKey

pkg/cmd/repo/deploy-key/add/http.go:15–58  ·  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

13)
14
15func uploadDeployKey(httpClient *http.Client, repo ghrepo.Interface, keyFile io.Reader, title string, isWritable bool) error {
16 url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(repo.RepoHost()), "repos", repo.RepoOwner(), repo.RepoName(), "keys")
17 if err != nil {
18 return err
19 }
20
21 keyBytes, err := io.ReadAll(keyFile)
22 if err != nil {
23 return err
24 }
25
26 payload := map[string]interface{}{
27 "title": title,
28 "key": string(keyBytes),
29 "read_only": !isWritable,
30 }
31
32 payloadBytes, err := json.Marshal(payload)
33 if err != nil {
34 return err
35 }
36
37 req, err := http.NewRequest("POST", url.String(), bytes.NewBuffer(payloadBytes))
38 if err != nil {
39 return err
40 }
41
42 resp, err := httpClient.Do(req)
43 if err != nil {
44 return err
45 }
46 defer resp.Body.Close()
47
48 if resp.StatusCode > 299 {
49 return api.HandleHTTPError(resp)
50 }
51
52 _, err = io.Copy(io.Discard, resp.Body)
53 if err != nil {
54 return err
55 }
56
57 return nil
58}

Callers 1

addRunFunction · 0.85

Calls 10

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
StringMethod · 0.65
DoMethod · 0.65
CloseMethod · 0.65
CopyMethod · 0.45

Tested by

no test coverage detected