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

Preserve original URLs when --remap is used #1493

Open
oponomarov-tu opened this issue Sep 2, 2024 · 1 comment
Open

Preserve original URLs when --remap is used #1493

oponomarov-tu opened this issue Sep 2, 2024 · 1 comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed workaround

Comments

@oponomarov-tu
Copy link

oponomarov-tu commented Sep 2, 2024

I'm using the --remap feature to validate links pointing to private GitHub repositories containing documentation.

$ lychee . --remap 'https://github.com/<my org>/(?P<repo>[^/]+)/(?:blob|tree)/(?P<revision>[^/]+)/(?P<path>[^#]+) https://api.github.com/repos/<my org>/$repo/contents/$path?ref=$revision' --header "Authorization=token $GITHUB_TOKEN" -v

Since there's no straightforward way to verify if a link to a private GitHub repository is broken, I'm mitigating this by using both the --github-token argument and setting the --header "Authorization=token $GITHUB_TOKEN".

With this setup, the --remap feature substitutes links like:

[`sre-design-docs/use-conventional-commit-messages.md`](https://github.com/<my org>/<my private repo>/blob/master/docs/design/docs/non-existint-document.md)

With their API equivalent:

✗ [404] https://api.github.com/repos/<my org>/<my private repo>/contents/docs/design/docs/non-existint-document.md?ref=master | Failed: Network error: Not Found

This approach works as expected, but I’m wondering if there's a way to convert the output link back to its original Markdown format. The goal is to prevent confusion when users search for the broken link in the document. Ideally, I’d like this validation to occur "in the background" to maintain a seamless user experience.

Thank you for considering this feature request. I hope others find this workaround helpful as well.

@mre
Copy link
Member

mre commented Sep 6, 2024

Thank you for your detailed explanation of how you're using lychee's --remap feature to validate links pointing to private GitHub repositories. It's always great to see users coming up with creative solutions to meet their specific needs!

Your suggestion to show the remapped URLs in the output is an excellent idea. This would indeed help prevent confusion when users search for broken links in their documents.

I'm wondering if we should show the original URL as well as the remapped URL, though.
We could modify lychee to display both URLs using the following format:

[STATUS] ORIGINAL_URL -> REMAPPED_URL | Additional info

For example, the output would look like this:

[404] https://github.com/<my org>/<my private repo>/blob/master/docs/design/docs/non-existint-document.md -> https://api.github.com/repos/<my org>/<my private repo>/contents/docs/design/docs/non-existint-document.md?ref=master | Failed: Network error: Not Found

This format shows the connection between the original link and its remapped version.
I wonder if it's too verbose, though? Alternatively, we could show the original URL only in verbose mode (-v).

We support multiple output formats (--format), so that would require some planning, though.

@mre mre added question Further information is requested workaround labels Sep 6, 2024
@mre mre added good first issue Good for newcomers help wanted Extra attention is needed and removed question Further information is requested labels Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed workaround
Projects
None yet
Development

No branches or pull requests

2 participants