@@ -4,6 +4,7 @@ import gulp from 'gulp';
44import express from 'express' ;
55import { glob } from 'glob' ;
66import { LinkChecker } from 'linkinator' ;
7+ import { instance as gaxios } from 'gaxios' ;
78
89import * as cheerio from 'cheerio' ;
910
@@ -85,17 +86,65 @@ async function checkPathAndExit(path, options, done) {
8586
8687 const url = 'http://localhost:8001/' ;
8788
89+ const githubToken = process . env . GITHUB_TOKEN ;
90+
8891 const config = {
8992 path : url ,
9093 linksToSkip : options . linksToSkip || [ ] ,
9194 recurse : options . recurse ,
9295 silent : options . silent ,
9396 markdown : options . markdown ,
97+ concurrency : 1 ,
98+ retry : true ,
99+ beforeRequest : ( url , options ) => {
100+ // add the bearer token for GitHub links
101+ if ( githubToken && url . host . endsWith ( 'github.com' ) ) {
102+ options . headers = {
103+ ...( options . headers || { } ) ,
104+ authorization : `Bearer ${ githubToken } ` ,
105+ } ;
106+ }
107+ return options ;
108+ } ,
94109 } ;
95110
96111 try {
112+ const token = process . env . GITHUB_TOKEN ;
113+ console . log ( 'GITHUB_TOKEN is' , token ? 'SET' : 'NOT SET' ) ;
114+
115+ gaxios . interceptors . request . add ( {
116+ resolved : ( config ) => {
117+ if ( config . url ?. includes ( 'github.com' ) ) {
118+ console . log ( '→ Request to' , config . url ) ;
119+ console . log ( ' Request headers:' , config . headers ) ;
120+
121+ if ( token ) {
122+ config . headers = {
123+ ...( config . headers || { } ) ,
124+ authorization : `Bearer ${ token } ` ,
125+ } ;
126+ console . log ( ' Headers after injection: ' , config . headers ) ;
127+ }
128+ }
129+ return config ;
130+ } ,
131+ rejected : ( error ) => Promise . reject ( error ) ,
132+ } ) ;
133+
97134 const checker = new LinkChecker ( ) ;
98135
136+ // Fires after *each* link is checked
137+ checker . on ( 'link' , ( result ) => {
138+ if ( result . state === 'BROKEN' ) {
139+ // failureDetails is an array; each entry has `.headers`
140+ const detail = result . failureDetails [ 0 ] ;
141+ console . log (
142+ `[${ result . status } ] ${ result . url } ` ,
143+ '\n→ headers:' , detail . headers
144+ ) ;
145+ }
146+ } ) ;
147+
99148 if ( path === '../v2' ) {
100149 const htmlFiles = await glob ( path + '/**/*.html' ) ;
101150 let allResults = { links : [ ] } ;
0 commit comments