diff --git a/src/codeql-cli/scripts/convert-markdown-for-docs.js b/src/codeql-cli/scripts/convert-markdown-for-docs.js index 9fbc64c17f3e..2347c60c25b1 100644 --- a/src/codeql-cli/scripts/convert-markdown-for-docs.js +++ b/src/codeql-cli/scripts/convert-markdown-for-docs.js @@ -1,6 +1,6 @@ import { readFile } from 'fs/promises' import path from 'path' -import got from 'got' + import { fromMarkdown } from 'mdast-util-from-markdown' import { toMarkdown } from 'mdast-util-to-markdown' import { visitParents } from 'unist-util-visit-parents' @@ -233,15 +233,24 @@ export async function convertContentToDocs( async function getRedirect(url) { let response = null try { - response = await got(url) + response = await fetch(url, { redirect: 'manual' }) + if (!response.ok && response.status !== 301 && response.status !== 302) { + throw new Error(`HTTP ${response.status}: ${response.statusText}`) + } } catch (error) { console.error(error) const errorMsg = `Failed to get redirect for ${url} when converting aka.ms links to docs.github.com links.` throw new Error(errorMsg) } - // The first entry of redirectUrls has the anchor if it exists - const redirect = response.redirectUrls[0].pathname + // Get the redirect location from the response header + const redirectLocation = response.headers.get('location') + if (!redirectLocation) { + throw new Error(`No redirect location found for ${url}`) + } + + // Parse the URL to get the pathname + const redirect = new URL(redirectLocation).pathname // Some of the aka.ms links have the /en language prefix. // This removes all language prefixes from the redirect url. diff --git a/src/workflows/find-past-built-pr.ts b/src/workflows/find-past-built-pr.ts index 9f3beb0c00da..a2bf28a91006 100644 --- a/src/workflows/find-past-built-pr.ts +++ b/src/workflows/find-past-built-pr.ts @@ -1,5 +1,3 @@ -import got from 'got' - import { setOutput } from '@actions/core' import github from './github' @@ -39,10 +37,14 @@ async function main() { } async function getBuiltSHA() { - const r = await got('https://docs.github.com/_build') - const sha = r.body.trim() + const r = await fetch('https://docs.github.com/_build') + if (!r.ok) { + throw new Error(`HTTP ${r.status}: ${r.statusText}`) + } + const body = await r.text() + const sha = body.trim() if (!/[a-f0-9]{40}/.test(sha)) { - throw new Error(`Response body does not look like a SHA ('${r.body.slice(0, 100)}'...)`) + throw new Error(`Response body does not look like a SHA ('${body.slice(0, 100)}'...)`) } return sha } diff --git a/src/workflows/purge-edge-cache.ts b/src/workflows/purge-edge-cache.ts index c36391997c86..8f1396eb12ae 100644 --- a/src/workflows/purge-edge-cache.ts +++ b/src/workflows/purge-edge-cache.ts @@ -1,5 +1,3 @@ -import got from 'got' - // Because we use shielding, it's recommended that you purge twice // so it purges the edge nodes *and* the origin. // The documentation says: @@ -32,7 +30,17 @@ async function purgeFastlyBySurrogateKey({ 'fastly-soft-purge': '1', } const requestPath = `https://api.fastly.com/service/${safeServiceId}/purge/${surrogateKey}` - return got.post(requestPath, { headers, json: true }) + const response = await fetch(requestPath, { + method: 'POST', + headers: { + ...headers, + 'Content-Type': 'application/json', + }, + }) + if (!response.ok) { + throw new Error(`HTTP ${response.status}: ${response.statusText}`) + } + return response } export default async function purgeEdgeCache( diff --git a/src/workflows/test-local-dev.ts b/src/workflows/test-local-dev.ts index d90e1810cd25..aff7dad53873 100755 --- a/src/workflows/test-local-dev.ts +++ b/src/workflows/test-local-dev.ts @@ -2,7 +2,6 @@ import assert from 'node:assert/strict' import fs from 'fs' import cheerio from 'cheerio' -import got from 'got' /** * A very basic script that tests the local dev server. @@ -22,12 +21,18 @@ import got from 'got' main() async function get(path: string, options?: Record) { - // By default, got() will use retries and follow redirects. + // By default, fetch() will follow redirects. const t0 = new Date() - const response = await got(makeURL(path), options) + const response = await fetch(makeURL(path), options) const took = new Date().getTime() - t0.getTime() - console.log(`GET ${path} => ${response.statusCode} (${took}ms)`) - return response + console.log(`GET ${path} => ${response.status} (${took}ms)`) + + // Convert fetch response to have similar interface as got response + const body = await response.text() + return { + statusCode: response.status, + body: body, + } } function makeURL(path: string) {