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

Method RESTWithNext

api/client.go:166–201  ·  view source on GitHub ↗
(hostname string, method string, p string, body io.Reader, data any)

Source from the content-addressed store, hash-verified

164}
165
166func (c Client) RESTWithNext(hostname string, method string, p string, body io.Reader, data any) (string, error) {
167 opts := clientOptions(hostname, c.http.Transport)
168 restClient, err := ghAPI.NewRESTClient(opts)
169 if err != nil {
170 return "", err
171 }
172
173 resp, err := restClient.Request(method, p, body)
174 if err != nil {
175 return "", handleResponse(err)
176 }
177 defer resp.Body.Close()
178
179 if resp.StatusCode == http.StatusNoContent {
180 return "", nil
181 }
182
183 b, err := io.ReadAll(resp.Body)
184 if err != nil {
185 return "", err
186 }
187
188 err = json.Unmarshal(b, &data)
189 if err != nil {
190 return "", err
191 }
192
193 var next string
194 for _, m := range linkRE.FindAllStringSubmatch(resp.Header.Get("Link"), -1) {
195 if len(m) > 2 && m[2] == "next" {
196 next = m[1]
197 }
198 }
199
200 return next, nil
201}
202
203// Request performs a REST request and returns the response for the caller to consume.
204//

Callers

nothing calls this directly

Calls 5

clientOptionsFunction · 0.85
handleResponseFunction · 0.85
RequestMethod · 0.80
CloseMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected