Commit 16592e2b authored by Kamil Trzcinski's avatar Kamil Trzcinski

Fix review comments

- Remove unused Gitlab::Application.routes.url_helpers from Ci::Build
- Remove too much logic from a view, use Ci::Commit.matrix_builds
- Use ci_status_with_icon
- Don't describe symbols
parent f32e28f6
...@@ -37,8 +37,6 @@ ...@@ -37,8 +37,6 @@
module Ci module Ci
class Build < CommitStatus class Build < CommitStatus
include Gitlab::Application.routes.url_helpers
LAZY_ATTRIBUTES = ['trace'] LAZY_ATTRIBUTES = ['trace']
belongs_to :runner, class_name: 'Ci::Runner' belongs_to :runner, class_name: 'Ci::Runner'
......
...@@ -113,6 +113,12 @@ module Ci ...@@ -113,6 +113,12 @@ module Ci
latest_statuses.select { |status| status.ref == ref } latest_statuses.select { |status| status.ref == ref }
end end
def matrix_builds(build = nil)
matrix_builds = builds.latest.ordered
matrix_builds = matrix_builds.similar(build) if build
matrix_builds.to_a
end
def retried def retried
@retried ||= (statuses.order(id: :desc) - statuses.latest) @retried ||= (statuses.order(id: :desc) - statuses.latest)
end end
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
= link_to "merge request ##{merge_request.iid}", merge_request_path(merge_request) = link_to "merge request ##{merge_request.iid}", merge_request_path(merge_request)
#up-build-trace #up-build-trace
- builds = @build.commit.builds.similar(@build).latest.ordered.to_a - builds = @build.commit.matrix_builds(@build)
- if builds.size > 1 - if builds.size > 1
%ul.nav-links.no-top.no-bottom %ul.nav-links.no-top.no-bottom
- builds.each do |build| - builds.each do |build|
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
%td.status %td.status
- if can?(current_user, :read_build, build) - if can?(current_user, :read_build, build)
= link_to namespace_project_build_url(build.project.namespace, build.project, build), class: "ci-status ci-#{build.status}" do = link_to namespace_project_build_url(build.project.namespace, build.project, build), class: "ci-status ci-#{build.status}" do
= ci_icon_for_status(build.status) = ci_status_with_icon(build.status)
= build.status
- else - else
= ci_status_with_icon(build.status) = ci_status_with_icon(build.status)
......
...@@ -2,8 +2,7 @@ ...@@ -2,8 +2,7 @@
%td.status %td.status
- if can?(current_user, :read_commit_status, generic_commit_status) && generic_commit_status.target_url - if can?(current_user, :read_commit_status, generic_commit_status) && generic_commit_status.target_url
= link_to generic_commit_status.target_url, class: "ci-status ci-#{generic_commit_status.status}" do = link_to generic_commit_status.target_url, class: "ci-status ci-#{generic_commit_status.status}" do
= ci_icon_for_status(generic_commit_status.status) = ci_status_with_icon(generic_commit_status.status)
= generic_commit_status.status
- else - else
= ci_status_with_icon(generic_commit_status.status) = ci_status_with_icon(generic_commit_status.status)
......
...@@ -9,7 +9,7 @@ describe Ci::Build, models: true do ...@@ -9,7 +9,7 @@ describe Ci::Build, models: true do
it { is_expected.to respond_to :trace_html } it { is_expected.to respond_to :trace_html }
describe :first_pending do describe '#first_pending' do
let(:first) { FactoryGirl.create :ci_build, commit: commit, status: 'pending', created_at: Date.yesterday } let(:first) { FactoryGirl.create :ci_build, commit: commit, status: 'pending', created_at: Date.yesterday }
let(:second) { FactoryGirl.create :ci_build, commit: commit, status: 'pending' } let(:second) { FactoryGirl.create :ci_build, commit: commit, status: 'pending' }
before { first; second } before { first; second }
...@@ -19,7 +19,7 @@ describe Ci::Build, models: true do ...@@ -19,7 +19,7 @@ describe Ci::Build, models: true do
it('returns with the first pending build') { is_expected.to eq(first) } it('returns with the first pending build') { is_expected.to eq(first) }
end end
describe :create_from do describe '#create_from' do
before do before do
build.status = 'success' build.status = 'success'
build.save build.save
...@@ -33,7 +33,7 @@ describe Ci::Build, models: true do ...@@ -33,7 +33,7 @@ describe Ci::Build, models: true do
end end
end end
describe :ignored? do describe '#ignored?' do
subject { build.ignored? } subject { build.ignored? }
context 'if build is not allowed to fail' do context 'if build is not allowed to fail' do
...@@ -69,7 +69,7 @@ describe Ci::Build, models: true do ...@@ -69,7 +69,7 @@ describe Ci::Build, models: true do
end end
end end
describe :trace do describe '#trace' do
subject { build.trace_html } subject { build.trace_html }
it { is_expected.to be_empty } it { is_expected.to be_empty }
...@@ -101,7 +101,7 @@ describe Ci::Build, models: true do ...@@ -101,7 +101,7 @@ describe Ci::Build, models: true do
# it { is_expected.to eq(commit.project.timeout) } # it { is_expected.to eq(commit.project.timeout) }
# end # end
describe :options do describe '#options' do
let(:options) do let(:options) do
{ {
image: "ruby:2.1", image: "ruby:2.1",
...@@ -122,25 +122,25 @@ describe Ci::Build, models: true do ...@@ -122,25 +122,25 @@ describe Ci::Build, models: true do
# it { is_expected.to eq(project.allow_git_fetch) } # it { is_expected.to eq(project.allow_git_fetch) }
# end # end
describe :project do describe '#project' do
subject { build.project } subject { build.project }
it { is_expected.to eq(commit.project) } it { is_expected.to eq(commit.project) }
end end
describe :project_id do describe '#project_id' do
subject { build.project_id } subject { build.project_id }
it { is_expected.to eq(commit.project_id) } it { is_expected.to eq(commit.project_id) }
end end
describe :project_name do describe '#project_name' do
subject { build.project_name } subject { build.project_name }
it { is_expected.to eq(project.name) } it { is_expected.to eq(project.name) }
end end
describe :extract_coverage do describe '#extract_coverage' do
context 'valid content & regex' do context 'valid content & regex' do
subject { build.extract_coverage('Coverage 1033 / 1051 LOC (98.29%) covered', '\(\d+.\d+\%\) covered') } subject { build.extract_coverage('Coverage 1033 / 1051 LOC (98.29%) covered', '\(\d+.\d+\%\) covered') }
...@@ -172,7 +172,7 @@ describe Ci::Build, models: true do ...@@ -172,7 +172,7 @@ describe Ci::Build, models: true do
end end
end end
describe :variables do describe '#variables' do
context 'returns variables' do context 'returns variables' do
subject { build.variables } subject { build.variables }
...@@ -242,7 +242,7 @@ describe Ci::Build, models: true do ...@@ -242,7 +242,7 @@ describe Ci::Build, models: true do
end end
end end
describe :can_be_served? do describe '#can_be_served?' do
let(:runner) { FactoryGirl.create :ci_runner } let(:runner) { FactoryGirl.create :ci_runner }
before { build.project.runners << runner } before { build.project.runners << runner }
...@@ -277,7 +277,7 @@ describe Ci::Build, models: true do ...@@ -277,7 +277,7 @@ describe Ci::Build, models: true do
end end
end end
describe :any_runners_online? do describe '#any_runners_online?' do
subject { build.any_runners_online? } subject { build.any_runners_online? }
context 'when no runners' do context 'when no runners' do
...@@ -312,7 +312,7 @@ describe Ci::Build, models: true do ...@@ -312,7 +312,7 @@ describe Ci::Build, models: true do
end end
end end
describe :stuck? do describe '#stuck?' do
subject { build.stuck? } subject { build.stuck? }
%w(pending).each do |state| %w(pending).each do |state|
...@@ -343,7 +343,7 @@ describe Ci::Build, models: true do ...@@ -343,7 +343,7 @@ describe Ci::Build, models: true do
end end
end end
describe :artifacts? do describe '#artifacts?' do
subject { build.artifacts? } subject { build.artifacts? }
context 'artifacts archive does not exist' do context 'artifacts archive does not exist' do
...@@ -358,7 +358,7 @@ describe Ci::Build, models: true do ...@@ -358,7 +358,7 @@ describe Ci::Build, models: true do
end end
describe :artifacts_metadata? do describe '#artifacts_metadata?' do
subject { build.artifacts_metadata? } subject { build.artifacts_metadata? }
context 'artifacts metadata does not exist' do context 'artifacts metadata does not exist' do
it { is_expected.to be_falsy } it { is_expected.to be_falsy }
...@@ -370,7 +370,7 @@ describe Ci::Build, models: true do ...@@ -370,7 +370,7 @@ describe Ci::Build, models: true do
end end
end end
describe :repo_url do describe '#repo_url' do
let(:build) { FactoryGirl.create :ci_build } let(:build) { FactoryGirl.create :ci_build }
let(:project) { build.project } let(:project) { build.project }
...@@ -384,7 +384,7 @@ describe Ci::Build, models: true do ...@@ -384,7 +384,7 @@ describe Ci::Build, models: true do
it { is_expected.to include(project.web_url[7..-1]) } it { is_expected.to include(project.web_url[7..-1]) }
end end
describe :depends_on_builds do describe '#depends_on_builds' do
let!(:build) { FactoryGirl.create :ci_build, commit: commit, name: 'build', stage_idx: 0, stage: 'build' } let!(:build) { FactoryGirl.create :ci_build, commit: commit, name: 'build', stage_idx: 0, stage: 'build' }
let!(:rspec_test) { FactoryGirl.create :ci_build, commit: commit, name: 'rspec', stage_idx: 1, stage: 'test' } let!(:rspec_test) { FactoryGirl.create :ci_build, commit: commit, name: 'rspec', stage_idx: 1, stage: 'test' }
let!(:rubocop_test) { FactoryGirl.create :ci_build, commit: commit, name: 'rubocop', stage_idx: 1, stage: 'test' } let!(:rubocop_test) { FactoryGirl.create :ci_build, commit: commit, name: 'rubocop', stage_idx: 1, stage: 'test' }
...@@ -416,7 +416,7 @@ describe Ci::Build, models: true do ...@@ -416,7 +416,7 @@ describe Ci::Build, models: true do
created_at: created_at) created_at: created_at)
end end
describe :merge_request do describe '#merge_request' do
context 'when a MR has a reference to the commit' do context 'when a MR has a reference to the commit' do
before do before do
@merge_request = create_mr(build, commit, factory: :merge_request) @merge_request = create_mr(build, commit, factory: :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