MCPcopy
hub / github.com/github/docs / get

Function get

tests/helpers/e2etest.js:5–50  ·  view source on GitHub ↗
(
  route,
  opts = {
    method: 'get',
    body: undefined,
    followRedirects: false,
    followAllRedirects: false,
    headers: {},
  }
)

Source from the content-addressed store, hash-verified

3import { omitBy, isUndefined } from 'lodash-es'
4
5export async function get(
6 route,
7 opts = {
8 method: 'get',
9 body: undefined,
10 followRedirects: false,
11 followAllRedirects: false,
12 headers: {},
13 }
14) {
15 const method = opts.method || 'get'
16 const fn = got[method]
17 if (!fn || typeof fn !== 'function') throw new Error(`No method function for '${method}'`)
18 const absURL = `http://localhost:4000${route}`
19 const xopts = omitBy(
20 {
21 body: opts.body,
22 headers: opts.headers,
23 retry: { limit: 0 },
24 throwHttpErrors: false,
25 followRedirect: opts.followAllRedirects || opts.followRedirects,
26 },
27 isUndefined
28 )
29 const res = await fn(absURL, xopts)
30 // follow all redirects, or just follow one
31 if (opts.followAllRedirects && [301, 302].includes(res.status)) {
32 // res = await get(res.headers.location, opts)
33 throw new Error('A')
34 } else if (opts.followRedirects && [301, 302].includes(res.status)) {
35 // res = await get(res.headers.location)
36 throw new Error('B')
37 }
38
39 const text = res.body
40 const status = res.statusCode
41 const headers = res.headers
42 return {
43 text,
44 status,
45 statusCode: status, // Legacy
46 headers,
47 header: headers, // Legacy
48 url: res.url,
49 }
50}
51
52export async function head(route, opts = { followRedirects: false }) {
53 const res = await get(route, { method: 'head', followRedirects: opts.followRedirects })

Callers 15

anchor-redirect.jsFile · 0.90
early-access.jsFile · 0.90
redirects.jsFile · 0.90
frame.jsFile · 0.90
api-search.jsFile · 0.90
search.jsFile · 0.90
internal-links.jsFile · 0.90
api-search.jsFile · 0.90
webhooks.jsFile · 0.90
redirects.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected