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

Function fetchDiff

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

Source from the content-addressed store, hash-verified

211}
212
213func fetchDiff(httpClient *http.Client, baseRepo ghrepo.Interface, prNumber int, asPatch bool) (io.ReadCloser, error) {
214 url, err := safeurl.JoinPathWithHostPrefix(ghinstance.RESTPrefix(baseRepo.RepoHost()), "repos", baseRepo.RepoOwner(), baseRepo.RepoName(), "pulls", strconv.Itoa(prNumber))
215 if err != nil {
216 return nil, err
217 }
218 acceptType := "application/vnd.github.v3.diff"
219 if asPatch {
220 acceptType = "application/vnd.github.v3.patch"
221 }
222
223 req, err := http.NewRequest("GET", url.String(), nil)
224 if err != nil {
225 return nil, err
226 }
227
228 req.Header.Set("Accept", acceptType)
229
230 resp, err := httpClient.Do(req)
231 if err != nil {
232 return nil, err
233 }
234 if resp.StatusCode != 200 {
235 return nil, api.HandleHTTPError(resp)
236 }
237
238 return resp.Body, nil
239}
240
241const lineBufferSize = 4096
242

Callers 1

diffRunFunction · 0.85

Calls 9

JoinPathWithHostPrefixFunction · 0.92
RESTPrefixFunction · 0.92
HandleHTTPErrorFunction · 0.92
RepoHostMethod · 0.65
RepoOwnerMethod · 0.65
RepoNameMethod · 0.65
StringMethod · 0.65
SetMethod · 0.65
DoMethod · 0.65

Tested by

no test coverage detected