Skip to content

feat(links): auto-remap base-branch GitHub URLs to PR branch#18

Merged
zeitlinger merged 1 commit intomainfrom
feat/links-remap-pr-branch
Feb 16, 2026
Merged

feat(links): auto-remap base-branch GitHub URLs to PR branch#18
zeitlinger merged 1 commit intomainfrom
feat/links-remap-pr-branch

Conversation

@zeitlinger
Copy link
Copy Markdown
Member

Summary

  • Add build_remap_args() to links.sh that generates lychee --remap flags to redirect /blob/{base}/ and /tree/{base}/ GitHub URLs to the PR branch
  • Works in CI (using GITHUB_REPOSITORY, GITHUB_BASE_REF, GITHUB_HEAD_REF) and locally (parsing git remote URL and branch info)
  • Supports fork PRs via PR_HEAD_REPO env var; skips silently when on the default branch or when repo info can't be determined

This eliminates the need for consuming repos to add boilerplate sed commands in their CI workflows to remap branch URLs during link checking (e.g., prometheus/client_java#1883).

Test plan

  • Lint passes (mise run lint)
  • On default branch (main): no remap args generated
  • CI simulation (GITHUB_REPOSITORY/GITHUB_BASE_REF/GITHUB_HEAD_REF): correct remap args
  • Fork CI simulation (with PR_HEAD_REPO): remaps to fork repo
  • Head == base branch: no remap args generated

Add build_remap_args() to generate lychee --remap flags that redirect
/blob/main/ and /tree/main/ URLs to the PR branch. Works in both CI
(using GITHUB_* env vars) and locally (parsing git remote/branch info).
Supports fork PRs via PR_HEAD_REPO env var. Skips silently when on the
default branch or when repo info can't be determined.
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
Copilot AI review requested due to automatic review settings February 16, 2026 17:53
@zeitlinger zeitlinger merged commit dd6cc61 into main Feb 16, 2026
12 checks passed
@zeitlinger zeitlinger deleted the feat/links-remap-pr-branch branch February 16, 2026 17:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds automatic URL remapping functionality to the lint:links task to redirect base-branch GitHub URLs to the PR branch during link checking. This eliminates the need for consuming repositories to add manual sed commands in their CI workflows.

Changes:

  • Added build_remap_args() function that generates --remap flags for lychee to redirect /blob/{base}/ and /tree/{base}/ URLs
  • Modified run_lychee() to collect and pass remap arguments to lychee
  • Supports both CI environments (via GITHUB_* env vars) and local execution (via git commands), with fork PR support via PR_HEAD_REPO

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tasks/lint/links.sh
Comment on lines +57 to +59
echo "${base_url}/blob/${base_ref}/(.*) ${head_url}/blob/${head_ref}/\$1"
echo "--remap"
echo "${base_url}/tree/${base_ref}/(.*) ${head_url}/tree/${head_ref}/\$1"
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remap pattern is missing regex anchors (^ and $). Without anchors, the pattern could match partial URLs incorrectly. The pattern should be anchored to match complete URLs: ^${base_url}/blob/${base_ref}/(.*)$

This is particularly important because lychee uses these patterns for regex matching, and without anchors, a URL like https://example.com/link-to-https://github.com/owner/repo/blob/main/file.md could be incorrectly matched and remapped.

Suggested change
echo "${base_url}/blob/${base_ref}/(.*) ${head_url}/blob/${head_ref}/\$1"
echo "--remap"
echo "${base_url}/tree/${base_ref}/(.*) ${head_url}/tree/${head_ref}/\$1"
echo "^${base_url}/blob/${base_ref}/(.*)\$ ${head_url}/blob/${head_ref}/\$1"
echo "--remap"
echo "^${base_url}/tree/${base_ref}/(.*)\$ ${head_url}/tree/${head_ref}/\$1"

Copilot uses AI. Check for mistakes.
Comment thread tasks/lint/links.sh
Comment on lines +57 to +59
echo "${base_url}/blob/${base_ref}/(.*) ${head_url}/blob/${head_ref}/\$1"
echo "--remap"
echo "${base_url}/tree/${base_ref}/(.*) ${head_url}/tree/${head_ref}/\$1"
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remap pattern is missing regex anchors (^ and $). Without anchors, the pattern could match partial URLs incorrectly. The pattern should be anchored to match complete URLs: ^${base_url}/tree/${base_ref}/(.*)$

This is particularly important because lychee uses these patterns for regex matching, and without anchors, a URL like https://example.com/link-to-https://github.com/owner/repo/tree/main/path could be incorrectly matched and remapped.

Suggested change
echo "${base_url}/blob/${base_ref}/(.*) ${head_url}/blob/${head_ref}/\$1"
echo "--remap"
echo "${base_url}/tree/${base_ref}/(.*) ${head_url}/tree/${head_ref}/\$1"
echo "^${base_url}/blob/${base_ref}/(.*)$ ${head_url}/blob/${head_ref}/\$1"
echo "--remap"
echo "^${base_url}/tree/${base_ref}/(.*)$ ${head_url}/tree/${head_ref}/\$1"

Copilot uses AI. Check for mistakes.
Comment thread tasks/lint/links.sh
Comment on lines +53 to +59
local base_url="https://github.com/${repo}"
local head_url="https://github.com/${head_repo}"

echo "--remap"
echo "${base_url}/blob/${base_ref}/(.*) ${head_url}/blob/${head_ref}/\$1"
echo "--remap"
echo "${base_url}/tree/${base_ref}/(.*) ${head_url}/tree/${head_ref}/\$1"
Copy link

Copilot AI Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branch names and repository names may contain special characters (like / in branch names for feature branches like feature/my-feature) that could break the regex pattern. These values should be escaped before being used in the regex pattern to prevent regex interpretation of special characters.

Consider using a regex escaping function or quoting mechanism to handle special characters like ., *, +, ?, [, ], {, }, (, ), ^, $, |, \, and /.

Copilot uses AI. Check for mistakes.
zeitlinger added a commit that referenced this pull request Feb 16, 2026
## Summary

- Add `^` and `$` regex anchors to the lychee `--remap` patterns to
prevent partial URL matching

Addresses review feedback from #18 — without anchors, a URL embedded
inside another URL (e.g.,
`https://example.com/link-to-https://github.com/org/repo/blob/main/file.md`)
could be incorrectly remapped.

## Test plan

- [x] Lint passes (`mise run lint`)
- [x] CI simulation: remap patterns include `^` prefix and `$` suffix

Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>
zeitlinger pushed a commit that referenced this pull request Feb 16, 2026
🤖 I have created a release *beep* *boop*
---


## [0.3.0](v0.2.0...v0.3.0)
(2026-02-16)


### Features

* add Renovate shareable preset for consuming repos
([#17](#17))
([8a06590](8a06590))
* **links:** auto-remap base-branch GitHub URLs to PR branch
([#18](#18))
([dd6cc61](dd6cc61))


### Bug Fixes

* **links:** add regex anchors to remap patterns
([#19](#19))
([2e17348](2e17348))
* replace broken release-please PR comment with docs
([#12](#12))
([817b37d](817b37d))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
zeitlinger pushed a commit that referenced this pull request Apr 13, 2026
## flint v0.20.0 — Rust rewrite

flint has been rewritten from scratch in Rust. The bash + Docker stack
is replaced by a fast, cross-platform native binary with no container
dependency.

### Highlights

- **Native binary** — no Docker, no bash wrappers; runs anywhere mise
can install a Rust crate
- **Parallel linting** — all checks run concurrently
- **Diff-aware** — only checks files changed since the merge base by
default (`--full` for everything)
- **`flint update`** — migrates obsolete `mise.toml` tool keys
automatically (e.g. `ubi:` → `github:`, `npm:markdownlint-cli` →
`npm:markdownlint-cli2`)
- **`flint hook install`** — installs a pre-commit hook without any mise
task knowledge
- **New linters**: `gofmt`, `google-java-format`, `ktlint`,
`dotnet-format`, `markdownlint-cli2`, `xmllint` (via `cargo:xmloxide`),
`license-header` (pure-Rust, no binary)
- **Windows support** — ktlint self-executing JAR handled via explicit
`java -jar` invocation

### Migration

See
[AGENTS-V2.md](https://github.com/grafana/flint/blob/main/AGENTS-V2.md)
and [README.md](https://github.com/grafana/flint/blob/main/README.md)
for full setup instructions.

Quick reference for existing consumers:

```toml
[tools]
# While installing from source (pre-crates.io release):
"cargo:https://github.com/grafana/flint" = "branch:main"

[env]
FLINT_CONFIG_DIR = ".github/config"

[tasks.lint]
run = "flint run"

[tasks."lint:fix"]
run = "flint run --fix"
```

Remove: `lint:super-linter`, `lint:links`, `lint:renovate-deps`,
`setup:native-lint-tools`, `setup:pre-commit-hook` tasks. Run `flint
update` to auto-migrate any obsolete tool keys.

> [!NOTE]
> The changelog below includes entries from the legacy v1 bash era — see
[README-V1.md](https://github.com/grafana/flint/blob/main/README-V1.md)
for v1 docs.

---

##
[0.20.0](flint-v0.19.0...flint-v0.20.0)
(2026-04-13)


### Features

* add flint v2 Rust binary
([#139](#139))
([19f2b25](19f2b25))
* add native linting mode and version mapping infrastructure
([#93](#93))
([24b06da](24b06da))
* add Renovate shareable preset for consuming repos
([#17](#17))
([8a06590](8a06590))
* consolidate link checking and add autofix flags
([#7](#7))
([086a5e9](086a5e9))
* flint update command, explicit JAR flag, v0.20.0
([#146](#146))
([b43bf52](b43bf52))
* handle line-number anchors and issue comments globally
([#56](#56))
([cf751df](cf751df))
* **links:** add GitHub URL remaps for line-number and fragment anchors
([#28](#28))
([5b59065](5b59065))
* **links:** auto-remap base-branch GitHub URLs to PR branch
([#18](#18))
([dd6cc61](dd6cc61))
* **renovate:** support SHA-pinned URLs in Renovate preset
([#21](#21))
([4fd1f28](4fd1f28))
* **super-linter:** default to slim image
([#24](#24))
([c8eeab8](c8eeab8))
* support NATIVE env var for container-free linting
([#107](#107))
([0a8193d](0a8193d))


### Bug Fixes

* activate mise environment in native lint mode
([#123](#123))
([d0fec45](d0fec45))
* add 'mise run fix' hint to lint failure output
([#90](#90))
([5b4ad5d](5b4ad5d))
* decouple version mapping generation from pinned super-linter version
([#112](#112))
([5370e77](5370e77))
* **deps:** update rust crate crossterm to 0.29
([#156](#156))
([c59ae3e](c59ae3e))
* **deps:** update rust crate similar to v3
([#160](#160))
([684be4e](684be4e))
* **deps:** update rust crate toml to v1
([#161](#161))
([3aae614](3aae614))
* **deps:** update rust crate toml_edit to 0.25
([#158](#158))
([42d9efd](42d9efd))
* exclude GitHub compare links from lychee checks
([#10](#10))
([e714608](e714608))
* fail native lint when enabled tools are missing
([#111](#111))
([163bb6b](163bb6b))
* improve link checker reliability against GitHub rate limiting
([#95](#95))
([7a5282d](7a5282d))
* include staged files in native lint file list
([#135](#135))
([34412d6](34412d6))
* **links:** add regex anchors to remap patterns
([#19](#19))
([2e17348](2e17348))
* native lint in worktrees, trust toml, use ec binary, drop isort
([#134](#134))
([8594bba](8594bba))
* **release-please:** fix footer not appearing on release PRs
([#40](#40))
([d7a55e4](d7a55e4))
* remap same-repo GitHub URLs to local file paths
([#100](#100))
([b4feadd](b4feadd))
* **renovate-deps:** forward GITHUB_TOKEN as GITHUB_COM_TOKEN
([#132](#132))
([4d6510b](4d6510b))
* replace broken release-please PR comment with docs
([#12](#12))
([817b37d](817b37d))
* run shellcheck on .bats files in native mode
([#137](#137))
([a4fd3f8](a4fd3f8))
* strip Scroll to Text Fragment anchors in link checks
([#86](#86))
([b630cdf](b630cdf))
* tighten markdownlint config for native mode
([#106](#106))
([6ef25b2](6ef25b2))
* use remap instead of exclude for issue comment anchors
([#58](#58))
([656f355](656f355))

---
> [!IMPORTANT]
> Close and reopen this PR to trigger CI checks.

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This was referenced Apr 16, 2026
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.

2 participants