Class: Gitlab::BitbucketImport::UserFinder
- Inherits:
-
Object
- Object
- Gitlab::BitbucketImport::UserFinder
- Defined in:
- lib/gitlab/bitbucket_import/user_finder.rb
Constant Summary collapse
- USER_ID_FOR_AUTHOR_CACHE_KEY =
'bitbucket-importer/user-finder/%{project_id}/%{author}'
- CACHE_USER_ID_NOT_FOUND =
-1
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
Instance Method Summary collapse
- #find_user_id(author) ⇒ Object
- #gitlab_user_id(project, username) ⇒ Object
-
#initialize(project) ⇒ UserFinder
constructor
A new instance of UserFinder.
Constructor Details
#initialize(project) ⇒ UserFinder
Returns a new instance of UserFinder.
11 12 13 |
# File 'lib/gitlab/bitbucket_import/user_finder.rb', line 11 def initialize(project) @project = project end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
9 10 11 |
# File 'lib/gitlab/bitbucket_import/user_finder.rb', line 9 def project @project end |
Instance Method Details
#find_user_id(author) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gitlab/bitbucket_import/user_finder.rb', line 15 def find_user_id() return unless cache_key = build_cache_key() cached_id = cache.read_integer(cache_key) return if cached_id == CACHE_USER_ID_NOT_FOUND return cached_id if cached_id id = User.by_provider_and_extern_uid(:bitbucket, ).select(:id).first&.id cache.write(cache_key, id || CACHE_USER_ID_NOT_FOUND) id end |
#gitlab_user_id(project, username) ⇒ Object
31 32 33 |
# File 'lib/gitlab/bitbucket_import/user_finder.rb', line 31 def gitlab_user_id(project, username) find_user_id(username) || project.creator_id end |