Skip to content

Commit 1eee703

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 1eee703

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-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: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,43 @@ async function checkPathAndExit(path, options, done) {
8585

8686
const url = 'http://localhost:8001/';
8787

88+
const githubToken = process.env.GITHUB_TOKEN;
89+
8890
const config = {
8991
path: url,
9092
linksToSkip: options.linksToSkip || [],
9193
recurse: options.recurse,
9294
silent: options.silent,
9395
markdown: options.markdown,
96+
concurrency: 1,
97+
retry: true,
98+
beforeRequest: (url, options) => {
99+
// add the bearer token for GitHub links
100+
if (githubToken && url.host.endsWith('github.com')) {
101+
options.headers = {
102+
...(options.headers || {}),
103+
authorization: `Bearer ${githubToken}`,
104+
};
105+
}
106+
return options;
107+
},
94108
};
95109

96110
try {
97111
const checker = new LinkChecker();
98112

113+
// Fires after *each* link is checked
114+
checker.on('link', (result) => {
115+
if (result.state === 'BROKEN') {
116+
// failureDetails is an array; each entry has `.headers`
117+
const detail = result.failureDetails[0];
118+
console.log(
119+
`[${result.status}] ${result.url}`,
120+
'\n→ headers:', detail.headers
121+
);
122+
}
123+
});
124+
99125
if (path === '../v2') {
100126
const htmlFiles = await glob(path + '/**/*.html');
101127
let allResults = { links: [] };

0 commit comments

Comments
 (0)