diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-05-20 17:34:42 +0300 |
commit | 9f46488805e86b1bc341ea1620b866016c2ce5ed (patch) | |
tree | f9748c7e287041e37d6da49e0a29c9511dc34768 /lib/gitlab/url_builder.rb | |
parent | dfc92d081ea0332d69c8aca2f0e745cb48ae5e6d (diff) |
Add latest changes from gitlab-org/gitlab@13-0-stable-ee
Diffstat (limited to 'lib/gitlab/url_builder.rb')
-rw-r--r-- | lib/gitlab/url_builder.rb | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/lib/gitlab/url_builder.rb b/lib/gitlab/url_builder.rb index 4c56b9bb3c9..329f87d8be8 100644 --- a/lib/gitlab/url_builder.rb +++ b/lib/gitlab/url_builder.rb @@ -11,6 +11,10 @@ module Gitlab class << self include ActionView::RecordIdentifier + # Using a case statement here is preferable for readability and maintainability. + # See discussion in https://gitlab.com/gitlab-org/gitlab/-/issues/217397 + # + # rubocop:disable Metrics/CyclomaticComplexity def build(object, **options) # Objects are sometimes wrapped in a BatchLoader instance case object.itself @@ -34,14 +38,17 @@ module Gitlab snippet_url(object, **options) when User instance.user_url(object, **options) - when ProjectWiki - instance.project_wiki_url(object.project, :home, **options) + when Wiki + wiki_url(object, **options) when WikiPage instance.project_wiki_url(object.wiki.project, object.slug, **options) + when ::DesignManagement::Design + design_url(object, **options) else raise NotImplementedError.new("No URL builder defined for #{object.inspect}") end end + # rubocop:enable Metrics/CyclomaticComplexity def commit_url(commit, **options) return '' unless commit.project @@ -70,6 +77,25 @@ module Gitlab instance.gitlab_snippet_url(snippet, **options) end end + + def wiki_url(object, **options) + if object.container.is_a?(Project) + instance.project_wiki_url(object.container, Wiki::HOMEPAGE, **options) + else + raise NotImplementedError.new("No URL builder defined for #{object.inspect}") + end + end + + def design_url(design, **options) + size, ref = options.values_at(:size, :ref) + options.except!(:size, :ref) + + if size + instance.project_design_management_designs_resized_image_url(design.project, design, ref, size, **options) + else + instance.project_design_management_designs_raw_image_url(design.project, design, ref, **options) + end + end end end end |