Skip to content

Commit 3b53fc6

Browse files
committed
Reduce 429 error responses when checking links
- set concurrency to 1 - retry 429 responses with retry-after header - set bearer token for GitHub links
1 parent ffcb10a commit 3b53fc6

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

.github/workflows/docs_test.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ jobs:
3434
working-directory: docs/v2
3535
run: ./render.sh
3636
- name: Run docs tests
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3739
run: |
3840
bundle config set --local without 'development'
3941
bundle install

docs/v3/gulpfile.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import gulp from 'gulp';
44
import express from 'express';
55
import { glob } from 'glob';
66
import { LinkChecker } from 'linkinator';
7+
import { instance as gaxios } from 'gaxios';
78

89
import * as cheerio from 'cheerio';
910

@@ -85,17 +86,54 @@ 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+
gaxios.interceptors.request.add({
113+
resolved: (config) => {
114+
if (config.url?.includes('github.com')) {
115+
console.log('→ Request to', config.url);
116+
console.log(' Request headers:', config.headers);
117+
}
118+
return config;
119+
},
120+
rejected: (error) => Promise.reject(error),
121+
});
122+
97123
const checker = new LinkChecker();
98124

125+
// Fires after *each* link is checked
126+
checker.on('link', (result) => {
127+
if (result.state === 'BROKEN') {
128+
// failureDetails is an array; each entry has `.headers`
129+
const detail = result.failureDetails[0];
130+
console.log(
131+
`[${result.status}] ${result.url}`,
132+
'\n→ headers:', detail.headers
133+
);
134+
}
135+
});
136+
99137
if (path === '../v2') {
100138
const htmlFiles = await glob(path + '/**/*.html');
101139
let allResults = { links: [] };

0 commit comments

Comments
 (0)