Draft: Add fix-redirects task to rewrite redirecting links (part 4 - tooling)

What does this MR do and why?

Adds a fix-redirects task to the gldocs CLI that finds external links in product documentation which return HTTP redirects, and rewrites them in the source Markdown to their resolved destination URLs.

This automates a recurring monthly maintenance task. The existing external-link checks report redirecting links but do not fix them, so updating them was a manual effort. The new task follows redirects with lychee, reads the redirect_map from lychee's JSON output, and rewrites the links in place.

How it works

  • Reads products and their docs directories from data/products.yaml, so all published products are covered automatically (run against one with --product).
  • Runs lychee with --max-redirects 4 --format json per product (overriding the max_redirects = 0 used by the broken-link gate, which is left untouched).
  • Defaults to a dry run that only reports what would change. Pass --apply to write.
  • GitLab issue, epic, and work-item redirects are listed for manual review (via --report) instead of being rewritten, since those churn as GitLab migrates between those types.

Usage

make fix-redirects                  # dry run, all products
make fix-redirects PRODUCT=runner   # dry run, single product
make fix-redirects APPLY=1          # write changes to all products

First runs of this tool against the product docs:

How to set up and validate locally

  1. Configure a local GitLab Docs environment with the product projects cloned as siblings.
  2. Check out this branch.
  3. Install lychee.
  4. Run make fix-redirects PRODUCT=runner and confirm it reports redirecting links without modifying files.
  5. Run go test ./cmd/internal/task/ and confirm the new tests pass.

Merge request acceptance checklist

Edited by Marcel Amirault

Merge request reports

Loading