merge_requests_helper.rb 1.55 KB
Newer Older
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
1
module MergeRequestsHelper
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
2 3
  def new_mr_path_from_push_event(event)
    new_project_merge_request_path(
4 5
      event.project,
      new_mr_from_push_event(event, event.project)
6 7 8 9 10
    )
  end

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

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

  def mr_css_classes mr
27
    classes = "merge-request"
28
    classes << " closed" if mr.closed?
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
29 30 31
    classes << " merged" if mr.merged?
    classes
  end
32

33
  def ci_build_details_path merge_request
34
    merge_request.source_project.gitlab_ci_service.build_page(merge_request.last_commit.sha)
35
  end
36 37 38

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

  def merge_request_alert_class(merge_request)
    if merge_request.merged?
      'alert-info'
    elsif merge_request.closed?
      'alert-danger'
    else
      'alert-success'
    end
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
54
end