2019-07-17 09:06:19 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module Gitlab
|
|
|
|
class SubmoduleLinks
|
|
|
|
include Gitlab::Utils::StrongMemoize
|
|
|
|
|
|
|
|
def initialize(repository)
|
|
|
|
@repository = repository
|
|
|
|
end
|
|
|
|
|
|
|
|
def for(submodule, sha)
|
2019-07-25 18:01:17 -04:00
|
|
|
submodule_url = submodule_url_for(sha, submodule.path)
|
2019-07-17 09:06:19 -04:00
|
|
|
SubmoduleHelper.submodule_links_for_url(submodule.id, submodule_url, repository)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
attr_reader :repository
|
|
|
|
|
2019-07-25 18:01:17 -04:00
|
|
|
def submodule_urls_for(sha)
|
|
|
|
strong_memoize(:"submodule_urls_for_#{sha}") do
|
2019-07-17 09:06:19 -04:00
|
|
|
repository.submodule_urls_for(sha)
|
|
|
|
end
|
|
|
|
end
|
2019-07-25 18:01:17 -04:00
|
|
|
|
|
|
|
def submodule_url_for(sha, path)
|
|
|
|
urls = submodule_urls_for(sha)
|
|
|
|
urls && urls[path]
|
|
|
|
end
|
2019-07-17 09:06:19 -04:00
|
|
|
end
|
|
|
|
end
|