Skip to content

Prevent spam from GitHub mentions in merge commits #260

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

Merged
merged 1 commit into from
Apr 3, 2025

Conversation

xosnrdev
Copy link
Contributor

Resolves #258

@xosnrdev xosnrdev force-pushed the ims branch 2 times, most recently from 5ac0d1f to 4bcfb25 Compare March 28, 2025 05:58
@Kobzol
Copy link
Contributor

Kobzol commented Mar 28, 2025

Hi, thanks for the PR, I'll try to take a look in the upcoming days.

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Thank you for the PR! The implementation looks like a good start, but there are a few things that should be modified, I left a bunch of comments.

@xosnrdev
Copy link
Contributor Author

Thanks for the feedback. I didn't put unicode text into consideration 😞.

Will resolve shortly.

@xosnrdev
Copy link
Contributor Author

Would fuzz test be ideal or overkill ?

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Fuzz testing would be way overkill I think :) To clarify, I didn't mean that the GitHub username could include Unicode, as far as I know, it cannot contain it. So for matching the usernames, doing what you had before (a-zA-Z0-9) was fine. Just the way you searched for the character before/after the match wasn't correct.

The code is now more complicated than before. What I meant was to solve the preceding/following word in the regex itself.

What do you think about this regex? (^|\s)@([a-zA-Z0-9][a-zA-Z0-9]*)($|\s)

@xosnrdev
Copy link
Contributor Author

Not sure this (^|\s)@([a-zA-Z0-9][a-zA-Z0-9]*)($|\s) matches auto-linking for @org/team and also trying boundary checks with look-around using the regex crate is not supported:

regex parse error:
    (?<!\S)@[a-zA-Z0-9][a-zA-Z0-9\-]{0,38}(?:/[a-zA-Z0-9][a-zA-Z0-9\-]{0,38})*(?!\S)
    ^^^^
error: look-around, including look-ahead and look-behind, is not supported
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
)

A workaround for look-around can be may be using the fancy-regex crate rust-lang/regex#910 at the cost of performance or writing more complex regex code.

@Kobzol
Copy link
Contributor

Kobzol commented Mar 31, 2025

I know that regex doesn't support lookaround, but we don't need it, right? We can just match the before/after part of the regex, and then ignore it, it doesn't need to be lookbehind/lookahead. Of course the regex would have to be extended for teams, it was just an example.

@xosnrdev
Copy link
Contributor Author

Ofc we don't need look-around.

@Kobzol
Copy link
Contributor

Kobzol commented Apr 1, 2025

Nice, this made the code much shorter and easier to understand! :) I think that we should use \s for the before/after chars though, otherwise e.g. abč@user.com would count as a mention.

@xosnrdev
Copy link
Contributor Author

xosnrdev commented Apr 1, 2025

I'll add test for this abč@user.com.

using /s will fail this test Hello,@user! How are you? as it matches whitespace characters like spaces, tabs, and newlines

@Kobzol
Copy link
Contributor

Kobzol commented Apr 2, 2025

using /s will fail this test Hello,@user! How are you? as it matches whitespace characters like spaces, tabs, and newlines

Yes, that was the idea :D I wonder if GitHub does indeed ping in these situations. It doesn't seem like so? I think that whitespace should be enough.

Hello,@xosrndev, are you pinged?

@Kobzol
Copy link
Contributor

Kobzol commented Apr 2, 2025

Hello, @xosrndev, are you pinged?

Hmm, it doesn't ping even above, unless I manually select the user. I guess that it shouldn't be tested in PR/issue comments, but rather in the commit messages directly. We should first test on some test repo in which exact situations does GitHub indeed ping when the mention is in the commit message.

@xosnrdev
Copy link
Contributor Author

xosnrdev commented Apr 2, 2025

Well it did ping on a test repo.

Screenshot 2025-04-02 at 11 01 53 AM Screenshot 2025-04-02 at 11 06 37 AM

@Kobzol
Copy link
Contributor

Kobzol commented Apr 2, 2025

Interesting, thanks for testing that out! Ok, in that case let's just use what homu does for now, which is \B, so "not a word boundary". It tries to detect a situation where there is a word on the left, but not on the right (and on the right we always have @). I'm not fully sure how rust-lang/homu#230 works yet, so let's start with just copying homu, and we can improve the regex in the future, once we have the baseline functionality merged.

@xosnrdev
Copy link
Contributor Author

xosnrdev commented Apr 2, 2025

bet.

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Thanks! Copying homu is usually not a bad default, we can always make it smarter in the future. Left one last nit, otherwise LGTM.

Copy link
Contributor

@Kobzol Kobzol left a comment

Choose a reason for hiding this comment

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

Thanks!

@Kobzol Kobzol added this pull request to the merge queue Apr 3, 2025
Merged via the queue into rust-lang:main with commit 0bf0f67 Apr 3, 2025
2 checks passed
@xosnrdev xosnrdev deleted the ims branch April 3, 2025 13:52
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.

Implement mention suppression
2 participants