Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External link checker: Add an HTTP header for the auth for GitHub #1392

Merged
merged 3 commits into from
May 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/weekly-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ jobs:
- name: Install Node.js dependencies
run: npm ci
- name: Check external links
env:
GITHUB_TOKEN: ${{ github.token }}
run: >
npm run check:external-links --
'docs/**/*.{md,mdx,ipynb}'
Expand Down
15 changes: 14 additions & 1 deletion scripts/lib/links/ExternalLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class ExternalLink {
let error: string = "";
try {
const response = await fetch(this.value, {
headers: { "User-Agent": "qiskit-documentation-broken-links-finder" },
headers: getHeaders(this.value),
method: "HEAD",
});
if (response.status >= 300) {
Expand All @@ -57,3 +57,16 @@ export class ExternalLink {
return `❌ ${error}. Appears in:\n${fileList.join("\n")}`;
}
}

function getHeaders(link: string) {
const headers: HeadersInit = {
"User-Agent": "qiskit-documentation-broken-links-finder",
};

if (link.startsWith("https://github.com")) {
const ghToken = process.env.GITHUB_TOKEN;
headers["Authorization"] = ghToken ? `token ${ghToken}` : "";
arnaucasau marked this conversation as resolved.
Show resolved Hide resolved
}

return headers;
}
Loading