(hostname string, method string, p string, body io.Reader, data interface{})
| 111 | } |
| 112 | |
| 113 | func (c Client) RESTWithNext(hostname string, method string, p string, body io.Reader, data interface{}) (string, error) { |
| 114 | opts := clientOptions(hostname, c.http.Transport) |
| 115 | restClient, err := ghAPI.NewRESTClient(opts) |
| 116 | if err != nil { |
| 117 | return "", err |
| 118 | } |
| 119 | |
| 120 | resp, err := restClient.Request(method, p, body) |
| 121 | if err != nil { |
| 122 | return "", err |
| 123 | } |
| 124 | defer resp.Body.Close() |
| 125 | |
| 126 | success := resp.StatusCode >= 200 && resp.StatusCode < 300 |
| 127 | if !success { |
| 128 | return "", HandleHTTPError(resp) |
| 129 | } |
| 130 | |
| 131 | if resp.StatusCode == http.StatusNoContent { |
| 132 | return "", nil |
| 133 | } |
| 134 | |
| 135 | b, err := io.ReadAll(resp.Body) |
| 136 | if err != nil { |
| 137 | return "", err |
| 138 | } |
| 139 | |
| 140 | err = json.Unmarshal(b, &data) |
| 141 | if err != nil { |
| 142 | return "", err |
| 143 | } |
| 144 | |
| 145 | var next string |
| 146 | for _, m := range linkRE.FindAllStringSubmatch(resp.Header.Get("Link"), -1) { |
| 147 | if len(m) > 2 && m[2] == "next" { |
| 148 | next = m[1] |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | return next, nil |
| 153 | } |
| 154 | |
| 155 | // HandleHTTPError parses a http.Response into a HTTPError. |
| 156 | // |
nothing calls this directly
no test coverage detected