Class: Gitlab::GithubImport::MilestoneFinder

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/github_import/milestone_finder.rb

Constant Summary collapse

CACHE_KEY =

The base cache key to use for storing/retrieving milestone IDs.

'github-import/milestone-finder/%{project}/%{iid}'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ MilestoneFinder

project - An instance of `Project`


12
13
14
# File 'lib/gitlab/github_import/milestone_finder.rb', line 12

def initialize(project)
  @project = project
end

Instance Attribute Details

#projectObject (readonly)

Returns the value of attribute project


6
7
8
# File 'lib/gitlab/github_import/milestone_finder.rb', line 6

def project
  @project
end

Instance Method Details

#build_cacheObject

rubocop: disable CodeReuse/ActiveRecord


25
26
27
28
29
30
31
32
33
34
# File 'lib/gitlab/github_import/milestone_finder.rb', line 25

def build_cache
  mapping = @project
    .milestones
    .pluck(:id, :iid)
    .each_with_object({}) do |(id, iid), hash|
      hash[cache_key_for(iid)] = id
    end

  Gitlab::Cache::Import::Caching.write_multiple(mapping)
end

#cache_key_for(iid) ⇒ Object

rubocop: enable CodeReuse/ActiveRecord


37
38
39
# File 'lib/gitlab/github_import/milestone_finder.rb', line 37

def cache_key_for(iid)
  CACHE_KEY % { project: project.id, iid: iid }
end

#id_for(issuable) ⇒ Object

issuable - An instance of `Gitlab::GithubImport::Representation::Issue`

or `Gitlab::GithubImport::Representation::PullRequest`.

18
19
20
21
22
# File 'lib/gitlab/github_import/milestone_finder.rb', line 18

def id_for(issuable)
  return unless issuable.milestone_number

  Gitlab::Cache::Import::Caching.read_integer(cache_key_for(issuable.milestone_number))
end