BitBucket Cloud PR mentions in comments map by username when imported to GitLab

Problem

When BitBucket Cloud (BBC) pull requests are imported to GitLab, authorship map correctly, by email, but user mentions seem to map by username. On GitLab.com this can end up being a completely different user than on the source, and similar might apply on a self-managed GitLab instance. This is both confusing and might cause concerns for end-users.

Solution

The solution would be to step through every pull request description and note and issue description and note and update the user references with project-specific users.

We need to have a map between usernames and emails on bitbucket. In order to that we can make an API call to fetch all the users and save it in a cache.

Cache structure: project/#{project.id}/username/#{username} => #{email}

This has to be done before the importers that contain mentions, ideally right after RepositoryImporter.

Once we get to the importer steps, we can check for @ symbols and find the corresponding email for the username. We should then find a user record matching the email and if found, replace the username with the found user's username. If not found, we don't want to keep the reference since it may tag incorrect users. In this case we should format it between backticks.

Bitbucket Server implementation

The MentionsConverter introduced in !139221 (merged) could be moved out of the BitbucketServerImport namespace so that it can be reused by other importers.

See #433008 (comment 1699072845) for more info.