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

Function fetchDiff

pkg/cmd/pr/diff/diff.go:212–236  ·  view source on GitHub ↗
(httpClient *http.Client, baseRepo ghrepo.Interface, prNumber int, asPatch bool)

Source from the content-addressed store, hash-verified

210}
211
212func fetchDiff(httpClient *http.Client, baseRepo ghrepo.Interface, prNumber int, asPatch bool) (io.ReadCloser, error) {
213 path, err := safeurl.JoinPath("repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "pulls", strconv.Itoa(prNumber))
214 if err != nil {
215 return nil, err
216 }
217 acceptType := "application/vnd.github.v3.diff"
218 if asPatch {
219 acceptType = "application/vnd.github.v3.patch"
220 }
221
222 // TODO(api-client-rollout)
223 // This line of code is part of a mechanical roll out of the api client.
224 // As a follow up, consider whether the api client can be injected to this call site, rather than constructed
225 resp, err := api.NewClientFromHTTP(httpClient).Request(baseRepo.RepoHost(), http.MethodGet, path.String(), nil,
226 api.WithHeader("Accept", acceptType))
227 if err != nil {
228 return nil, err
229 }
230 if resp.StatusCode != 200 {
231 defer resp.Body.Close()
232 return nil, api.UnexpectedStatusError(resp)
233 }
234
235 return resp.Body, nil
236}
237
238const lineBufferSize = 4096
239

Callers 1

diffRunFunction · 0.85

Calls 10

JoinPathFunction · 0.92
NewClientFromHTTPFunction · 0.92
WithHeaderFunction · 0.92
UnexpectedStatusErrorFunction · 0.92
RequestMethod · 0.80
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
RepoHostMethod · 0.65
StringMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected