Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 13 additions & 4 deletions src/codeql-cli/scripts/convert-markdown-for-docs.js
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions src/workflows/find-past-built-pr.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import got from 'got'

import { setOutput } from '@actions/core'

import github from './github'
Expand Down Expand Up @@ -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
}
Expand Down
14 changes: 11 additions & 3 deletions src/workflows/purge-edge-cache.ts
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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(
Expand Down
15 changes: 10 additions & 5 deletions src/workflows/test-local-dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -22,12 +21,18 @@ import got from 'got'
main()

async function get(path: string, options?: Record<string, any>) {
// 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) {
Expand Down
Loading