debian-mirror-gitlab/lib/gitlab/github_import/milestone_finder.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.2 KiB
Ruby
Raw Normal View History

2018-03-17 18:26:18 +05:30
# frozen_string_literal: true
module Gitlab
module GithubImport
class MilestoneFinder
attr_reader :project
# The base cache key to use for storing/retrieving milestone IDs.
2019-12-04 20:38:33 +05:30
CACHE_KEY = 'github-import/milestone-finder/%{project}/%{iid}'
2018-03-17 18:26:18 +05:30
# project - An instance of `Project`
def initialize(project)
@project = project
end
# issuable - An instance of `Gitlab::GithubImport::Representation::Issue`
# or `Gitlab::GithubImport::Representation::PullRequest`.
def id_for(issuable)
return unless issuable.milestone_number
2020-04-08 14:13:33 +05:30
Gitlab::Cache::Import::Caching.read_integer(cache_key_for(issuable.milestone_number))
2018-03-17 18:26:18 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: disable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
def build_cache
mapping = @project
.milestones
.pluck(:id, :iid)
.each_with_object({}) do |(id, iid), hash|
hash[cache_key_for(iid)] = id
end
2020-04-08 14:13:33 +05:30
Gitlab::Cache::Import::Caching.write_multiple(mapping)
2018-03-17 18:26:18 +05:30
end
2018-12-05 23:21:45 +05:30
# rubocop: enable CodeReuse/ActiveRecord
2018-03-17 18:26:18 +05:30
def cache_key_for(iid)
CACHE_KEY % { project: project.id, iid: iid }
end
end
end
end