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

Adding code tags around any nwo#number text string #5646

Merged
merged 8 commits into from
Sep 7, 2022

Conversation

pavera
Copy link
Contributor

@pavera pavera commented Sep 7, 2022

Attempting to improve our link sanitation to prevent <org>/<repo>#<pr number> text strings from being hydrated into full github.com links by PR creation machinery.

I found that a number of our tests produce redirect links, however the link text itself is in the format above, and adding those links to a PR comment or description results in a valid github.com link and creates a mention on the targeted PR timeline.

This should also break up any text string in the above format to prevent flood of mentions experienced in the below issue:
Closes #5639

I also added common tests to the test debug dropdown in vscode and fixed a path issue with the vscode debugger.

This is still a WIP as there is 1 failing test which I need to fix, and the approach may be overly heavy handed. I'm not sure my tests which resulted in lots of valid links were valid, so feedback there would be good.

@pavera pavera marked this pull request as ready for review September 7, 2022 15:46
@pavera pavera requested a review from a team as a code owner September 7, 2022 15:46
@honeyankit honeyankit self-requested a review September 7, 2022 15:49
@pavera
Copy link
Contributor Author

pavera commented Sep 7, 2022

I've now limited this to only find text strings and not link text. I am concerned as copy/pasting a link such as: https://github.com/dependabot/dependabot-core/blob/main/common/spec/dependabot/pull_request_creator/message_builder/link_and_mention_sanitizer_spec.rb#L278

results in:

rust-num/num-traits#144

\n

I feel like we should probably be escaping the link text as well.

@pavera pavera changed the title Adding a space in link text and any nwo#number text string Adding code tags around any nwo#number text string Sep 7, 2022
@@ -14,6 +14,7 @@ class LinkAndMentionSanitizer
github\.com/(?<repo>#{GITHUB_USERNAME}/[^/\s]+)/
(?:issue|pull)s?/(?<number>\d+)
}x.freeze
GITHUB_NWO_REGEX = %r{(?<repo>#{GITHUB_USERNAME}/[^/\s#]+)#(?<number>\d+)}.freeze
Copy link
Member

@Nishnha Nishnha Sep 7, 2022

Choose a reason for hiding this comment

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

Could you explain this regex? Specifically [^/\s#]+

Copy link
Contributor Author

@pavera pavera Sep 7, 2022

Choose a reason for hiding this comment

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

I cribbed it together from the above regex that grabs the repo and number from a full github pr or issue link. Given a string like myorg/myrepo#123 the regex will match myorg based on the GITHUB_USERNAME regex, then will match nonwhitespace and non # chars after a / as the repo name, then grab the digits after the # as the issue or PR number. Specifically [^/\s#]+ says: match 1 or many characters (+) as long as they don't match (^) the following: forward slash (/), whitespace (\s), or hash symbol (#)

Copy link
Contributor

Choose a reason for hiding this comment

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

@pavera : could you put the regex explanation in the comment as well. It will be easier for future debugging.

end
it do
is_expected.to eq(
"<p><code>dsp-testing/dependabot-ts-definitely-typed#25</code></p>\n"
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to include the newline at the end of the line?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the call here renders the doc and adds the newline, so the test check has to expect it as far as I know.

Copy link
Contributor

@deivid-rodriguez deivid-rodriguez left a comment

Choose a reason for hiding this comment

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

Looks good to me!

What does nwo stand for?

@pavera
Copy link
Contributor Author

pavera commented Sep 7, 2022

What does nwo stand for?
"name with owner" shorthand for org/repo

Copy link
Member

@jakecoffman jakecoffman left a comment

Choose a reason for hiding this comment

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

Seems like it should work, and it didn't break any of the smoke tests. Nicely done!

@pavera pavera merged commit 6a10daa into main Sep 7, 2022
@pavera pavera deleted the pavera/add-spaces-to-nwo-refs branch September 7, 2022 18:58
@@ -20,7 +20,7 @@
"name": "Debug Tests",
"type": "Ruby",
"request": "launch",
"program": "${workspaceRoot}/${input:ecosystem}/.bundle/bin/rspec",
"program": "${workspaceRoot}/omnibus/.bundle/bin/rspec",
Copy link
Member

Choose a reason for hiding this comment

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

What was the rationale for this? I don't see it mentioned in the commit messages / PR description, so was surprised to see it... did I just miss it somehow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change was necessitated by #5529

@pavera pavera mentioned this pull request Oct 31, 2022
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.

github links in release notes cause timeline notification spam
7 participants