Skip to content

check_external_links: report permanently redirected links with their new address - #1222

Merged
yakew7 merged 3 commits into
yakew7:mainfrom
minutechreview:feat/report-moved-links-1196
Oct 29, 2026
Merged

yakew7 merged 3 commits into
yakew7:mainfrom
minutechreview:feat/report-moved-links-1196

Conversation

@minutechreview

Copy link
Copy Markdown
Contributor

Summary

check_external_links.py now lists links whose redirect chain starts with a permanent 301 or 308, together with the address they end on, as a new moved class that is never counted as broken.

Type

  • Audit
  • Explainer
  • Bug fix
  • Other

How it works: _open still uses urlopen, so the existing request path, user agents and DOI handling are unchanged. When the final URL differs from the requested one, it makes one extra request with redirects turned off to read the first hop's status. A 301 or 308 gives ("moved", final_url); a 302 or 307 stays ok, because the old address is still the one to cite. A 301 that ends on a 404 is still broken. Only links that redirected pay for the extra request.

Report changes:

  • text: the summary line adds N moved. when there are any, and a Moved (permanent 301 or 308 redirect; update the link, not counted as broken): section lists old -> new (files)
  • --json: a new moved list with the same url/detail/files shape, detail being the new address
  • --fail-on-broken ignores moved links

Tests (local server in tests/test_check_external_links.py): /moved (301) and /moved-permanently (308) report /ok as the new address, /moved-twice (301 then 302) reports its final address, /redirect (302) and /temporary (307) stay ok, /moved-to-gone (301 to a 404) is broken, and main prints the moved section and exits 0 with --fail-on-broken. The JSON key test now expects moved. CONTRIBUTING's make external-links line mentions it.

Not in this PR: the weekly external-links.yml issue body still lists only broken links. It reads ok/broken/unknown/ignored by key, so the new key does not break it; showing moved links there would be a small follow-up.

Checks: pytest tests/test_check_external_links.py 26 passed, 1 failed; the failure is test_a_name_that_does_not_resolve..., which fails the same way on main on my machine (my DNS answers .invalid names). With the old script the 4 new moved cases and the JSON key test fail; treating 302/307 as moved fails the temporary-redirect cases. ruff check faircode scripts tests, check_em_dash.py and check_broken_links.py pass.

Linked issue

Closes #1196

…new address

Closes yakew7#1196

Signed-off-by: minutechreview <141821420+minutechreview@users.noreply.github.com>
@vercel

vercel Bot commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

@minutechreview is attempting to deploy a commit to the yashkewlani2020-gmailcom's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown

@yakew7 @ahmdkaml @propcgamer20-png - new PR touching a path you own, please review.

yakew7 and others added 2 commits October 29, 2026 17:32
Signed-off-by: minutechreview <141821420+minutechreview@users.noreply.github.com>
@yakew7
yakew7 merged commit eef35e6 into yakew7:main Oct 29, 2026
16 of 17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

check_external_links.py does not report permanently redirected links

2 participants