|
4 | 4 | "context" |
5 | 5 | "errors" |
6 | 6 | "fmt" |
7 | | - "io/ioutil" |
| 7 | + "io" |
8 | 8 | "net/http" |
9 | 9 | "strings" |
10 | 10 |
|
@@ -209,36 +209,28 @@ func (pr *PullRequest) ChecksStatus() (summary PullRequestChecksStatus) { |
209 | 209 | return |
210 | 210 | } |
211 | 211 |
|
212 | | -func (c Client) PullRequestDiff(baseRepo ghrepo.Interface, prNumber int) (string, error) { |
| 212 | +func (c Client) PullRequestDiff(baseRepo ghrepo.Interface, prNumber int) (io.ReadCloser, error) { |
213 | 213 | url := fmt.Sprintf("https://api.github.com/repos/%s/pulls/%d", |
214 | 214 | ghrepo.FullName(baseRepo), prNumber) |
215 | 215 | req, err := http.NewRequest("GET", url, nil) |
216 | 216 | if err != nil { |
217 | | - return "", err |
| 217 | + return nil, err |
218 | 218 | } |
219 | 219 |
|
220 | 220 | req.Header.Set("Accept", "application/vnd.github.v3.diff; charset=utf-8") |
221 | 221 |
|
222 | 222 | resp, err := c.http.Do(req) |
223 | 223 | if err != nil { |
224 | | - return "", err |
225 | | - } |
226 | | - defer resp.Body.Close() |
227 | | - |
228 | | - b, err := ioutil.ReadAll(resp.Body) |
229 | | - if err != nil { |
230 | | - return "", err |
231 | | - } |
232 | | - |
233 | | - if resp.StatusCode == 200 { |
234 | | - return string(b), nil |
| 224 | + return nil, err |
235 | 225 | } |
236 | 226 |
|
237 | 227 | if resp.StatusCode == 404 { |
238 | | - return "", &NotFoundError{errors.New("pull request not found")} |
| 228 | + return nil, &NotFoundError{errors.New("pull request not found")} |
| 229 | + } else if resp.StatusCode != 200 { |
| 230 | + return nil, handleHTTPError(resp) |
239 | 231 | } |
240 | 232 |
|
241 | | - return "", errors.New("pull request diff lookup failed") |
| 233 | + return resp.Body, nil |
242 | 234 | } |
243 | 235 |
|
244 | 236 | func PullRequests(client *Client, repo ghrepo.Interface, currentPRNumber int, currentPRHeadRef, currentUsername string) (*PullRequestsPayload, error) { |
|
0 commit comments