BitBucket Server PR mentions in comments map by username when imported to GitLab
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 and examine the PR. The mentioned users are referencing the 1st hit by username
on the GitLab instance.
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
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 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: