BigW Consortium Gitlab

merge_requests_helper.rb 1.49 KB
Newer Older
1
module MergeRequestsHelper
Dmitriy Zaporozhets committed
2
  def new_mr_path_from_push_event(event)
3
    target_project = event.project.forked_from_project || event.project
Dmitriy Zaporozhets committed
4
    new_project_merge_request_path(
5
      event.project,
6
      new_mr_from_push_event(event, target_project)
7 8 9 10 11
    )
  end

  def new_mr_path_for_fork_from_push_event(event)
    new_project_merge_request_path(
12 13
      event.project,
      new_mr_from_push_event(event, event.project.forked_from_project)
14 15 16 17
    )
  end

  def new_mr_from_push_event(event, target_project)
Dmitriy Zaporozhets committed
18 19 20 21 22 23 24
    return {
      merge_request: {
        source_project_id: event.project.id,
        target_project_id: target_project.id,
        source_branch: event.branch_name,
        target_branch: target_project.repository.root_ref
      }
25
    }
Dmitriy Zaporozhets committed
26
  end
Dmitriy Zaporozhets committed
27

28
  def mr_css_classes(mr)
29
    classes = "merge-request"
30
    classes << " closed" if mr.closed?
Dmitriy Zaporozhets committed
31 32 33
    classes << " merged" if mr.merged?
    classes
  end
34

35
  def ci_build_details_path(merge_request)
36
    merge_request.source_project.ci_service.build_page(merge_request.last_commit.sha)
37
  end
38 39 40

  def merge_path_description(merge_request, separator)
    if merge_request.for_fork?
41
      "Project:Branches: #{@merge_request.source_project_path}:#{@merge_request.source_branch} #{separator} #{@merge_request.target_project.path_with_namespace}:#{@merge_request.target_branch}"
42 43 44 45
    else
      "Branches: #{@merge_request.source_branch} #{separator} #{@merge_request.target_branch}"
    end
  end
46 47 48 49

  def issues_sentence(issues)
    issues.map { |i| "##{i.iid}" }.to_sentence
  end
50
end