gitlab-org--gitlab-foss/lib/gitlab/submodule_links.rb
Douwe Maan cfef1e8e99
Fix error rendering submodules in MR diffs when there is no .gitmodules
Without this change, we get a NoMethodError on nil
2019-07-26 11:05:56 +01:00

31 lines
673 B
Ruby

# frozen_string_literal: true
module Gitlab
class SubmoduleLinks
include Gitlab::Utils::StrongMemoize
def initialize(repository)
@repository = repository
end
def for(submodule, sha)
submodule_url = submodule_url_for(sha, submodule.path)
SubmoduleHelper.submodule_links_for_url(submodule.id, submodule_url, repository)
end
private
attr_reader :repository
def submodule_urls_for(sha)
strong_memoize(:"submodule_urls_for_#{sha}") do
repository.submodule_urls_for(sha)
end
end
def submodule_url_for(sha, path)
urls = submodule_urls_for(sha)
urls && urls[path]
end
end
end