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 jsonper product (overriding themax_redirects = 0used by the broken-link gate, which is left untouched). - Defaults to a dry run that only reports what would change. Pass
--applyto 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 productsRelated
First runs of this tool against the product docs:
- GitLab Runner: gitlab-org/gitlab-runner!6831 (merged)
- Omnibus GitLab: gitlab-org/omnibus-gitlab!9512 (merged)
- GitLab Chart: gitlab-org/charts/gitlab!5121 (merged)
- GitLab Operator: gitlab-org/cloud-native/gitlab-operator!1503 (merged)
How to set up and validate locally
- Configure a local GitLab Docs environment with the product projects cloned as siblings.
- Check out this branch.
- Install lychee.
- Run
make fix-redirects PRODUCT=runnerand confirm it reports redirecting links without modifying files. - Run
go test ./cmd/internal/task/and confirm the new tests pass.
Merge request acceptance checklist
- I have evaluated the MR acceptance checklist for this merge request.
Edited by Marcel Amirault