File tree Expand file tree Collapse file tree 4 files changed +41
-17
lines changed
Expand file tree Collapse file tree 4 files changed +41
-17
lines changed Original file line number Diff line number Diff line change 11import { readFile } from 'fs/promises'
22import path from 'path'
3- import got from 'got'
3+
44import { fromMarkdown } from 'mdast-util-from-markdown'
55import { toMarkdown } from 'mdast-util-to-markdown'
66import { visitParents } from 'unist-util-visit-parents'
@@ -233,15 +233,24 @@ export async function convertContentToDocs(
233233async function getRedirect ( url ) {
234234 let response = null
235235 try {
236- response = await got ( url )
236+ response = await fetch ( url , { redirect : 'manual' } )
237+ if ( ! response . ok && response . status !== 301 && response . status !== 302 ) {
238+ throw new Error ( `HTTP ${ response . status } : ${ response . statusText } ` )
239+ }
237240 } catch ( error ) {
238241 console . error ( error )
239242 const errorMsg = `Failed to get redirect for ${ url } when converting aka.ms links to docs.github.com links.`
240243 throw new Error ( errorMsg )
241244 }
242245
243- // The first entry of redirectUrls has the anchor if it exists
244- const redirect = response . redirectUrls [ 0 ] . pathname
246+ // Get the redirect location from the response header
247+ const redirectLocation = response . headers . get ( 'location' )
248+ if ( ! redirectLocation ) {
249+ throw new Error ( `No redirect location found for ${ url } ` )
250+ }
251+
252+ // Parse the URL to get the pathname
253+ const redirect = new URL ( redirectLocation ) . pathname
245254
246255 // Some of the aka.ms links have the /en language prefix.
247256 // This removes all language prefixes from the redirect url.
Original file line number Diff line number Diff line change 1- import got from 'got'
2-
31import { setOutput } from '@actions/core'
42
53import github from './github'
@@ -39,10 +37,14 @@ async function main() {
3937}
4038
4139async function getBuiltSHA ( ) {
42- const r = await got ( 'https://docs.github.com/_build' )
43- const sha = r . body . trim ( )
40+ const r = await fetch ( 'https://docs.github.com/_build' )
41+ if ( ! r . ok ) {
42+ throw new Error ( `HTTP ${ r . status } : ${ r . statusText } ` )
43+ }
44+ const body = await r . text ( )
45+ const sha = body . trim ( )
4446 if ( ! / [ a - f 0 - 9 ] { 40 } / . test ( sha ) ) {
45- throw new Error ( `Response body does not look like a SHA ('${ r . body . slice ( 0 , 100 ) } '...)` )
47+ throw new Error ( `Response body does not look like a SHA ('${ body . slice ( 0 , 100 ) } '...)` )
4648 }
4749 return sha
4850}
Original file line number Diff line number Diff line change 1- import got from 'got'
2-
31// Because we use shielding, it's recommended that you purge twice
42// so it purges the edge nodes *and* the origin.
53// The documentation says:
@@ -32,7 +30,17 @@ async function purgeFastlyBySurrogateKey({
3230 'fastly-soft-purge' : '1' ,
3331 }
3432 const requestPath = `https://api.fastly.com/service/${ safeServiceId } /purge/${ surrogateKey } `
35- return got . post ( requestPath , { headers, json : true } )
33+ const response = await fetch ( requestPath , {
34+ method : 'POST' ,
35+ headers : {
36+ ...headers ,
37+ 'Content-Type' : 'application/json' ,
38+ } ,
39+ } )
40+ if ( ! response . ok ) {
41+ throw new Error ( `HTTP ${ response . status } : ${ response . statusText } ` )
42+ }
43+ return response
3644}
3745
3846export default async function purgeEdgeCache (
Original file line number Diff line number Diff line change @@ -2,7 +2,6 @@ import assert from 'node:assert/strict'
22import fs from 'fs'
33
44import cheerio from 'cheerio'
5- import got from 'got'
65
76/**
87 * A very basic script that tests the local dev server.
@@ -22,12 +21,18 @@ import got from 'got'
2221main ( )
2322
2423async function get ( path : string , options ?: Record < string , any > ) {
25- // By default, got () will use retries and follow redirects.
24+ // By default, fetch () will follow redirects.
2625 const t0 = new Date ( )
27- const response = await got ( makeURL ( path ) , options )
26+ const response = await fetch ( makeURL ( path ) , options )
2827 const took = new Date ( ) . getTime ( ) - t0 . getTime ( )
29- console . log ( `GET ${ path } => ${ response . statusCode } (${ took } ms)` )
30- return response
28+ console . log ( `GET ${ path } => ${ response . status } (${ took } ms)` )
29+
30+ // Convert fetch response to have similar interface as got response
31+ const body = await response . text ( )
32+ return {
33+ statusCode : response . status ,
34+ body : body ,
35+ }
3136}
3237
3338function makeURL ( path : string ) {
You can’t perform that action at this time.
0 commit comments