Skip to content

Commit 0fcb1aa

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 0fcb1aa

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

.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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import gulp from 'gulp';
44
import express from 'express';
55
import { glob } from 'glob';
66
import { LinkChecker } from 'linkinator';
7-
87
import * as cheerio from 'cheerio';
8+
import { instance as gaxios } from 'gaxios';
99

1010
function displayErrors(err, stdout, stderr) {
1111
if (err) {
@@ -85,15 +85,33 @@ async function checkPathAndExit(path, options, done) {
8585

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

88+
const githubToken = process.env.GITHUB_TOKEN;
89+
console.log('GITHUB_TOKEN is', githubToken ? 'SET' : 'NOT SET');
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,
9499
};
95100

96101
try {
102+
gaxios.interceptors.request.add({
103+
resolved: (config) => {
104+
if (githubToken && config.url?.includes('github.com')) {
105+
config.headers = {
106+
...(config.headers || {}),
107+
authorization: `Bearer ${githubToken}`,
108+
};
109+
}
110+
return config;
111+
},
112+
rejected: (error) => Promise.reject(error),
113+
});
114+
97115
const checker = new LinkChecker();
98116

99117
if (path === '../v2') {

0 commit comments

Comments
 (0)