summaryrefslogtreecommitdiff
path: root/app/helpers/routing/projects_helper.rb
blob: f4732e398f0041316050ef719a0955280354dc19 (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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# frozen_string_literal: true

module Routing
  module ProjectsHelper
    def project_tree_path(project, ref = nil, *args)
      namespace_project_tree_path(project.namespace, project, ref || @ref || project.repository.root_ref, *args) # rubocop:disable Cop/ProjectPathHelper
    end

    def project_commits_path(project, ref = nil, *args)
      namespace_project_commits_path(project.namespace, project, ref || @ref || project.repository.root_ref, *args) # rubocop:disable Cop/ProjectPathHelper
    end

    def project_ref_path(project, ref_name, *args)
      project_commits_path(project, ref_name, *args)
    end

    def environment_path(environment, *args)
      project_environment_path(environment.project, environment, *args)
    end

    def environment_delete_path(environment, *args)
      expose_path(api_v4_projects_environments_path(id: environment.project.id, environment_id: environment.id))
    end

    def issue_path(entity, *args)
      project_issue_path(entity.project, entity, *args)
    end

    def merge_request_path(entity, *args)
      project_merge_request_path(entity.project, entity, *args)
    end

    def pipeline_path(pipeline, *args)
      project_pipeline_path(pipeline.project, pipeline.id, *args)
    end

    def issue_url(entity, *args)
      if use_work_items_path?(entity)
        work_item_url(entity, *args)
      else
        project_issue_url(entity.project, entity, *args)
      end
    end

    def work_item_url(entity, *args)
      unless Feature.enabled?(:use_iid_in_work_items_path, entity.project.group)
        return project_work_items_url(entity.project, entity.id, *args)
      end

      options = args.first || {}
      options[:iid_path] = true

      project_work_items_url(entity.project, entity.iid, **options)
    end

    def merge_request_url(entity, *args)
      project_merge_request_url(entity.project, entity, *args)
    end

    def pipeline_url(pipeline, *args)
      project_pipeline_url(pipeline.project, pipeline.id, *args)
    end

    def pipeline_job_url(pipeline, build, *args)
      project_job_url(pipeline.project, build.id, *args)
    end

    def commits_url(entity, *args)
      project_commits_url(entity.project, entity.source_ref, *args)
    end

    def commit_url(entity, *args)
      project_commit_url(entity.project, entity.sha, *args)
    end

    def release_url(entity, *args)
      project_release_url(entity.project, entity, *args)
    end

    def edit_milestone_path(entity, *args)
      if entity.resource_parent.is_a?(Group)
        edit_group_milestone_path(entity.resource_parent, entity, *args)
      else
        edit_project_milestone_path(entity.resource_parent, entity, *args)
      end
    end

    def toggle_subscription_path(entity, *args)
      if entity.is_a?(Issue)
        toggle_subscription_project_issue_path(entity.project, entity)
      else
        toggle_subscription_project_merge_request_path(entity.project, entity)
      end
    end

    private

    def use_work_items_path?(issue)
      issue.issue_type == 'task'
    end
  end
end

Routing::ProjectsHelper.prepend_mod