Map User Mentions from Bitbucket Cloud PR Imports
What does this MR do and why?
This MR maps user mentions in Bitbucket Cloud imports so that user mentions appear readable and similar to the mentions in Bitbucket. The user mentions go from something like this:
@{712020:11de8fea-aef8-41e9-8039-7b42d8dd56d2}
To this:
@Sam Word Gitlab
Unfortunately, it's not possible to map to actual GitLab users based on email because Bitbucket no longer exposes usernames, and they never exposed all email addresses for users in a workspace. See this comment thread on the parent issue for more details on why it's not possible. However, since it is possible to get nicknames and names from the Bitbucket Cloud API, it seemed best to map to names in backticks to look similar to the original Bitbucket mention.
Summary of Changes:
:bitbucket_cloud_convert_mentions_to_users
New Feature Flag: A new feature flag, :bitbucket_cloud_convert_mentions_to_users
was added to mitigate risks in our importers, and a new issue for its rollout was added #442484
Added a new stage worker and importer to cache users
Similar to the Bitbucket Server importer, a ImportUsersWorker
and UsersImporter
were added to call the Bitbucket Cloud API to get all members of a workspace.
client.rb
Updated Bitbucket Cloud's A call to the new endpoint was added to lib/bitbucket/client.rb
, but the new endpoint doesn't support sorting on created_on
, so other endpoints needed to be updated. Bitbucket's paginator also needed to be updated to handle paginated API calls with logging between the calls to each page.
Updated UserFromMention and MentionsConverter
USerFromMention
and MentionsConverter
were updated to handle cached names that do not map to an actual User, and convert mentions that don't match GitLab's User.reference_pattern
Added MentionsConverter to Bitbucket Cloud importers with comments/text with mentions
MentionsConverter
was added to Bitbucket Cloud's IssueImporter
, IssueNotesImporter
, PullRequestImporter
, PullRequestNotesImporter
to find and convert Bitbucket's mentions to something more user-friendly
spec/support/shared_examples/lib/gitlab/bitbucket_import/stage_methods_shared_examples.rb
Spec changes to Some spec changes to DRY up Bitbucket Cloud import specs
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
Before | After | |
---|---|---|
MR description | ||
MR comment | ||
Issue description | ||
Issue comment |
How mentions appear in Bitbucket itself:
How to set up and validate locally
- Create/find a Bitbucket Cloud repository to import
- Set up your local environment for Bitbucket Cloud imports
- Ensure the
:bitbucket_cloud_convert_mentions_to_users
feature flag is enabled - Import the Bitbucket Cloud repository
- See that Bitbucket Cloud mentions are now mapped to the Bitbucket user's nickname or name in MRs, MR comments, issues and issue comments. Note that issues imported from Bitbucket Cloud need to be Bitbucket issues, not Jira issues integrated into the Bitbucket project.
Related to #436307