Cache users from Bitbucket Server
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):
- Cache user usernames and emails from Bitbucket Server
👈 this MR - Convert mentions on pull requests from Bitbucket Server: !139221 (merged)
This MR runs a pipeline right after the repository has been created which fetches users from Bitbucket Server with access to the project and stores every user's username and email in a cache.
-
UsersImporter
is called fromImportUsersWorker
if the feature flag is enabled for the project's creator - Adds a
users
method toBitbucketServer::Client
which calls this API endpoint and returns them asBitbucketServer::Representation::User
objects which extractsemail
andusername
. - Creates a
BitbucketServer::UsersMapper
which has two methods:-
write_source_email_to_cache
: writes to the cache withkey = 'bitbucket_server/project/{project.id}/source/username/{username}'
andvalue = email
. The cache expires after 24 hours. -
read_source_email_from_cache
: fetches email cache entry for a given username
-
- Steps through users and calls
write_source_email_to_cache
for each
NOTE: for a user to be returned via the API, they need to have at least read access to the project. If the project is public, it will only return users who are invited to the project. We fetch users in batches of 100 until the response is empty so that we don't risk overloading with thousands of users at once.
How to set up and validate locally
- Enable the feature flag
Feature.enable(:bitbucket_server_convert_mentions_to_users)
- Setup bitbucket server by following these instructions
- Create another user at http://localhost:7990/admin/users with email
john@gmail.com
and usernamedoe
- Import the project from bitbucket server
- Verify that there are cache entries containing the username and email:
Gitlab::Cache::Import::Caching.with_redis { |redis| redis.keys.select { |k| k.match?(/.*bitbucket_server.*source\/username/) }.map { |k| {"#{k}": redis.get(k) } } }
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #433008 (closed)