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

Replace GitHub URLs outside of the owner namespace to avoid backlink spam #214

Merged
merged 1 commit into from
Feb 3, 2025

Conversation

mschoettle
Copy link
Contributor

Replaces github.com in URLs with redirect.github.com to avoid backlink spam.
This is only done when the URL points to outside of the owner of the GitHub namespace, e.g., the organization, to keep internal backlinks.

Fixes #211

return str.replace('github.com', 'redirect.github.com');
}

reString = `https:\\/\\/github\\.com\\/(?!${settings.github.owner}).+\\/.+\\/\\d+`;
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure the regex is correct?
Multiple things:

  • Doesn't the regex match only digits in the last path part of the URL? (What do you think about just ignoring the part after the org/owner completely?)
  • Are the double backslashes really required? I did think not.
  • Doesn't need the lookahead need a slash at the end as well so we are sure it is not my robofriends repo (github.com/spruce1/...) for example

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good points. I looked at how renovate does it and they replace all URLs as long as it doesn't start with certain subdomains that already redirect:

https://github.com/renovatebot/renovate/blob/de8140d476d35b28871b8fc9a836b909e79c446c/lib/modules/platform/github/massage-markdown-links.ts#L18-L23

So yes, we could do that while maintaining internal links intact.

The double backslashes are required (all the existing regexes have this as well).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed, please have a look again

@mschoettle mschoettle requested a review from spruce February 3, 2025 14:48
@spruce spruce merged commit b5a59a7 into piceaTech:master Feb 3, 2025
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.

Add ability to rewrite GitHub URLs to issues/PRs from other organizations to avoid backlinks
2 participants