Skip to content

Convert mentions on pull requests from Bitbucket Server

Madelein van Niekerk requested to merge 433008-convert-mentions into master

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):

  1. Cache user usernames and emails from Bitbucket Server: !139097 (merged)
  2. 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

  1. Disable the feature flag
    Feature.disable(:bitbucket_server_convert_mentions_to_users)
  2. Setup bitbucket server by following these instructions
  3. Create another user at http://localhost:7990/admin/users with email john@gmail.com and username doe. Add any (read/write/admin) permission for this user to access the project.
  4. 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.
  5. On gdk, create a user with email janedoe@gmail.com and username doe
  6. Import the project from bitbucket server
  7. Go to the MR and see that the note/description has an @mention linking to Jane's profile
  8. Enable the feature flag
    Feature.enable(:bitbucket_server_convert_mentions_to_users)
  9. Delete the project (so that we can import again)
    Projects::DestroyService.new(Project.last, User.first, {}).execute
  10. Import the project again and see that the MR now does not have an @mention for Jane.
  11. Optionally repeat the process with:
    1. On gitlab, update Jane's email to john@gmail.com -> link to Jane's profile
    2. On BBS, remove John's access to the project -> does not have a link to a user profile
    3. On gitlab, delete Jane's user -> does not have a link to a user profile

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #433008 (closed)

Edited by Madelein van Niekerk

Merge request reports