Commit 71e2ba4d authored by Stan Hu's avatar Stan Hu

Merge branch 'id-merge-request-state-name-icon' into 'master'

Move MR view methods from model to helper

See merge request gitlab-org/gitlab!20530
parents f7c88f11 2fb35639
...@@ -27,6 +27,16 @@ module MergeRequestsHelper ...@@ -27,6 +27,16 @@ module MergeRequestsHelper
classes.join(' ') classes.join(' ')
end end
def state_name_with_icon(merge_request)
if merge_request.merged?
[_("Merged"), "git-merge"]
elsif merge_request.closed?
[_("Closed"), "close"]
else
[_("Open"), "issue-open-m"]
end
end
def ci_build_details_path(merge_request) def ci_build_details_path(merge_request)
build_url = merge_request.source_project.ci_service.build_page(merge_request.diff_head_sha, merge_request.source_branch) build_url = merge_request.source_project.ci_service.build_page(merge_request.diff_head_sha, merge_request.source_branch)
return unless build_url return unless build_url
......
...@@ -1149,26 +1149,6 @@ class MergeRequest < ApplicationRecord ...@@ -1149,26 +1149,6 @@ class MergeRequest < ApplicationRecord
actual_head_pipeline.environments actual_head_pipeline.environments
end end
def state_human_name
if merged?
"Merged"
elsif closed?
"Closed"
else
"Open"
end
end
def state_icon_name
if merged?
"git-merge"
elsif closed?
"close"
else
"issue-open-m"
end
end
def fetch_ref! def fetch_ref!
target_project.repository.fetch_source_branch!(source_project.repository, source_branch, ref_path) target_project.repository.fetch_source_branch!(source_project.repository, source_branch, ref_path)
end end
......
- can_update_merge_request = can?(current_user, :update_merge_request, @merge_request) - can_update_merge_request = can?(current_user, :update_merge_request, @merge_request)
- can_reopen_merge_request = can?(current_user, :reopen_merge_request, @merge_request) - can_reopen_merge_request = can?(current_user, :reopen_merge_request, @merge_request)
- state_human_name, state_icon_name = state_name_with_icon(@merge_request)
- if @merge_request.closed_without_fork? - if @merge_request.closed_without_fork?
.alert.alert-danger .alert.alert-danger
...@@ -8,9 +9,9 @@ ...@@ -8,9 +9,9 @@
.detail-page-header .detail-page-header
.detail-page-header-body .detail-page-header-body
.issuable-status-box.status-box{ class: status_box_class(@merge_request) } .issuable-status-box.status-box{ class: status_box_class(@merge_request) }
= sprite_icon(@merge_request.state_icon_name, size: 16, css_class: 'd-block d-sm-none') = sprite_icon(state_icon_name, size: 16, css_class: 'd-block d-sm-none')
%span.d-none.d-sm-block %span.d-none.d-sm-block
= @merge_request.state_human_name = state_human_name
.issuable-meta .issuable-meta
- if @merge_request.discussion_locked? - if @merge_request.discussion_locked?
......
...@@ -26,6 +26,31 @@ describe MergeRequestsHelper do ...@@ -26,6 +26,31 @@ describe MergeRequestsHelper do
end end
end end
describe '#state_name_with_icon' do
using RSpec::Parameterized::TableSyntax
let(:merge_request) { MergeRequest.new }
where(:state, :expected_name, :expected_icon) do
:merged? | 'Merged' | 'git-merge'
:closed? | 'Closed' | 'close'
:opened? | 'Open' | 'issue-open-m'
end
with_them do
before do
allow(merge_request).to receive(state).and_return(true)
end
it 'returns name and icon' do
name, icon = helper.state_name_with_icon(merge_request)
expect(name).to eq(expected_name)
expect(icon).to eq(expected_icon)
end
end
end
describe '#format_mr_branch_names' do describe '#format_mr_branch_names' do
describe 'within the same project' do describe 'within the same project' do
let(:merge_request) { create(:merge_request) } let(:merge_request) { create(:merge_request) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment