Convert mentions on pull requests from Bitbucket Server
What does this MR do and why?
This is part of 2 MRs that addresses BitBucket Server PR mentions in comments map by... (#433008 - closed):
- Cache user usernames and emails from Bitbucket Server: !139097 (merged)
- Convert mentions on pull requests from Bitbucket Server
👈 this MR
This MR creates a MentionsConverter
which is called from PullRequestImporter
and PullRequestImporter
to convert mentions in MR descriptions and notes.
The converter firstly checks for emails in the text and substitutes it with a index of an array containing the emails because we need to match on the @
symbol for mentions and this could lead to altering emails. After converting the mentions, we then substitute the emails back in.
To convert mentions, we find all matches of @
followed by letters, digits, underscores or hyphens. These are the requirements of usernames on gitlab. For each mention, we see if there's a cache entry containing an email from Bitbucket Server (done in !139097 (merged)). If there is an email, we check if there's a gitlab user with the email. If that's the case, it is added to an array of mentions and later substituted. In order to handle mentions that are substrings or copies of other mentions, the @
is replaced with a placeholder text and later substituted back in.
How to set up and validate locally
- Disable the feature flag
Feature.disable(:bitbucket_server_convert_mentions_to_users)
- Setup bitbucket server by following these instructions
- Create another user at http://localhost:7990/admin/users with email
john@gmail.com
and usernamedoe
. Add any (read/write/admin) permission for this user to access the project. - Create a project and repo, push up changes and create a pull request. Mention
@doe
in the pull request description and create a note with a mention. - On gdk, create a user with email
janedoe@gmail.com
and usernamedoe
- Import the project from bitbucket server
- Go to the MR and see that the note/description has an
@mention
linking to Jane's profile - Enable the feature flag
Feature.enable(:bitbucket_server_convert_mentions_to_users)
- Delete the project (so that we can import again)
Projects::DestroyService.new(Project.last, User.first, {}).execute
- Import the project again and see that the MR now does not have an
@mention
for Jane. - Optionally repeat the process with:
- On gitlab, update Jane's email to
john@gmail.com
-> link to Jane's profile - On BBS, remove John's access to the project -> does not have a link to a user profile
- On gitlab, delete Jane's user -> does not have a link to a user profile
- On gitlab, update Jane's email to
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #433008 (closed)