BitBucket Server PR mentions in comments map by username when imported to GitLab
<!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "type::bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=type::bug and verify the issue you're about to submit isn't a duplicate. ---> ### Summary When BitBucket Server (BBS) pull requests (PRs) 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. ### Steps to reproduce **On BBS:** Create a PR with comments and mention other users by username (e.g. `@petar`) **On GitLab:** [Import the BBS repo](https://docs.gitlab.com/ee/api/import.html#import-repository-from-bitbucket-server) and examine the PR. The mentioned users are referencing the 1st hit by `username` on the GitLab instance. ![image](/uploads/dfd02b56992e2286de9fe4f44ca2bc46/image.png) ### Example Project The test project has been deleted from gitlab.com since. ### What is the current *bug* behavior? Users mentioned by `username` in imported BBS PR comments/threads reference the 1st hit by `username` on GitLab, which does not have to be the same user as on source (BBS). ### What is the expected *correct* behavior? Users mentioned by `username` in imported BBS PR comments/threads reference the user by a more unique field (e.g. `email`) on GitLab. If the user is found on GitLab, reference them with hyperlink to user profile. If the user is **not** found on GitLab, leave the mention static. ### Relevant logs and/or screenshots Pasted :point_up: ### Output of checks This bug happens on GitLab.com #### Results of GitLab environment info gitlab.com, but should apply to all GitLab installations. #### Results of GitLab application Check gitlab.com, but should apply to all GitLab installations. ### Possible fixes The solution would be to step through every note and pull request description 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](https://developer.atlassian.com/server/bitbucket/rest/v815/api-group-project/#api-api-latest-projects-projectkey-permissions-users-get) to fetch all the users and save it in a cache. Direct Transfer has a similar approach in `lib/bulk_imports/common/transformers/member_attributes_transformer.rb` and `lib/bulk_imports/common/pipelines/members_pipeline.rb`. Cache structure: `project/#{project.id}/username/#{username}` =\> `#{email}` This has to be done _before_ `PullRequestImporter` and `PullRequestNotesImporter`. 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 remove the `@` and format it as code between backticks. The result should look like this: ![Screenshot_2023-12-07_at_10.58.30](/uploads/91d3fafb183b6c26582df6d527e03aca/Screenshot_2023-12-07_at_10.58.30.png){width=673 height=93}
issue