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

Method RESTWithNext

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

Source from the content-addressed store, hash-verified

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

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