summaryrefslogtreecommitdiff
path: root/app/helpers/releases_helper.rb
blob: a3d944c64cc77151f11fc13c1a890c0bce677c67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# frozen_string_literal: true

module ReleasesHelper
  IMAGE_PATH = 'illustrations/releases.svg'
  DOCUMENTATION_PATH = 'user/project/releases/index'

  def illustration
    image_path(IMAGE_PATH)
  end

  def help_page(anchor: nil)
    help_page_path(DOCUMENTATION_PATH, anchor: anchor)
  end

  def data_for_releases_page
    {
      project_id: @project.id,
      illustration_path: illustration,
      documentation_path: help_page
    }.tap do |data|
      if can?(current_user, :create_release, @project)
        data[:new_release_path] = if Feature.enabled?(:new_release_page, @project)
                                    new_project_release_path(@project)
                                  else
                                    new_project_tag_path(@project)
                                  end
      end
    end
  end

  def data_for_edit_release_page
    new_edit_pages_shared_data.merge(
      tag_name: @release.tag,
      releases_page_path: project_releases_path(@project, anchor: @release.tag)
    )
  end

  def data_for_new_release_page
    new_edit_pages_shared_data.merge(
      default_branch: @project.default_branch
    )
  end

  private

  def new_edit_pages_shared_data
    {
      project_id: @project.id,
      markdown_preview_path: preview_markdown_path(@project),
      markdown_docs_path: help_page_path('user/markdown'),
      update_release_api_docs_path: help_page_path('api/releases/index.md', anchor: 'update-a-release'),
      release_assets_docs_path: help_page(anchor: 'release-assets'),
      manage_milestones_path: project_milestones_path(@project),
      new_milestone_path: new_project_milestone_path(@project)
    }
  end
end