diff --git a/github/client.go b/github/client.go index 5613e7742cf809bfa6c8fe1a5f4894acb0338ef0..e30e43ad9a22db2ac0ca0bf534116dcab828acb3 100644 --- a/github/client.go +++ b/github/client.go @@ -70,24 +70,17 @@ func (client *Client) PullRequest(project *Project, id string) (pr *PullRequest, } func (client *Client) PullRequestPatch(project *Project, id string) (patch io.ReadCloser, err error) { - url, err := octokit.PullRequestsURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name, "number": id}) - if err != nil { - return - } - - api, err := client.api() + api, err := client.simpleApi() if err != nil { - err = FormatError("getting pull request", err) return } - patch, result := api.PullRequests(client.requestURL(url)).Patch() - if result.HasError() { - err = FormatError("getting pull request", result.Err) + res, err := api.GetFile(fmt.Sprintf("repos/%s/%s/pulls/%s", project.Owner, project.Name, id), patchMediaType) + if err = checkStatus(200, "getting pull request patch", res, err); err != nil { return } - return + return res.Body, nil } type PullRequest struct { @@ -150,25 +143,17 @@ func (client *Client) RequestReview(project *Project, prNumber int, params map[s } func (client *Client) CommitPatch(project *Project, sha string) (patch io.ReadCloser, err error) { - url, err := octokit.CommitsURL.Expand(octokit.M{"owner": project.Owner, "repo": project.Name, "sha": sha}) - if err != nil { - return - } - - api, err := client.api() + api, err := client.simpleApi() if err != nil { - err = FormatError("getting pull request", err) return } - hyperlink := octokit.Hyperlink(client.requestURL(url).String()) - patch, result := api.Commits().Patch(&hyperlink, octokit.M{}) - if result.HasError() { - err = FormatError("getting pull request", result.Err) + res, err := api.GetFile(fmt.Sprintf("repos/%s/%s/commits/%s", project.Owner, project.Name, sha), patchMediaType) + if err = checkStatus(200, "getting commit patch", res, err); err != nil { return } - return + return res.Body, nil } type Gist struct { diff --git a/github/http.go b/github/http.go index fc2ebae50073bd89e726c84e15ffb2d3551d2aee..730d8e92122aa130b78c129e9a323efd65f6cb81 100644 --- a/github/http.go +++ b/github/http.go @@ -19,6 +19,7 @@ import ( ) const apiPayloadVersion = "application/vnd.github.v3+json;charset=utf-8" +const patchMediaType = "application/vnd.github.v3.patch;charset=utf-8" const textMediaType = "text/plain;charset=utf-8" var inspectHeaders = []string{