Skip to content

Commit dd5a32f

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 dd5a32f

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,26 @@ 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 {
@@ -108,6 +122,11 @@ async function checkPathAndExit(path, options, done) {
108122
displayResults(allResults);
109123
} else {
110124
const results = await checker.check(config);
125+
126+
const userCall = results.find(r => r.url.includes('github.com'));
127+
console.log('Status:', userCall.status);
128+
console.log('Headers:', userCall.response.headers);
129+
111130
displayResults(results);
112131
}
113132

0 commit comments

Comments
 (0)