Commit 9b2ae90d authored by Z.J. van de Weg's avatar Z.J. van de Weg

Remove references to build in pipeline charts

Being the good boyscouts, but mainly because of [the comment in the
review](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12378#note_33302115)
the words used for classes and variables are changed to not use builds
anymore.
parent 13d39971
...@@ -135,7 +135,7 @@ class Projects::PipelinesController < Projects::ApplicationController ...@@ -135,7 +135,7 @@ class Projects::PipelinesController < Projects::ApplicationController
@charts[:week] = Ci::Charts::WeekChart.new(project) @charts[:week] = Ci::Charts::WeekChart.new(project)
@charts[:month] = Ci::Charts::MonthChart.new(project) @charts[:month] = Ci::Charts::MonthChart.new(project)
@charts[:year] = Ci::Charts::YearChart.new(project) @charts[:year] = Ci::Charts::YearChart.new(project)
@charts[:build_times] = Ci::Charts::BuildTime.new(project) @charts[:pipeline_times] = Ci::Charts::PipelineTime.new(project)
@counts = {} @counts = {}
@counts[:total] = @project.pipelines.count(:all) @counts[:total] = @project.pipelines.count(:all)
......
...@@ -17,10 +17,10 @@ module GraphHelper ...@@ -17,10 +17,10 @@ module GraphHelper
ids.zip(parent_spaces) ids.zip(parent_spaces)
end end
def success_ratio(success:, failed:) def success_ratio(counts)
return 100 if failed.zero? return 100 if counts[:failed].zero?
ratio = (success.to_f / (success + failed)) * 100 ratio = (counts[:success].to_f / (counts[:success] + counts[:failed])) * 100
ratio.to_i ratio.to_i
end end
end end
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
.col-md-6 .col-md-6
= render 'projects/pipelines/charts/overall' = render 'projects/pipelines/charts/overall'
.col-md-6 .col-md-6
= render 'projects/pipelines/charts/build_times' = render 'projects/pipelines/charts/pipeline_times'
%hr %hr
= render 'projects/pipelines/charts/builds' = render 'projects/pipelines/charts/pipelines'
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
:javascript :javascript
var data = { var data = {
labels : #{@charts[:build_times].labels.to_json}, labels : #{@charts[:pipeline_times].labels.to_json},
datasets : [ datasets : [
{ {
fillColor : "rgba(220,220,220,0.5)", fillColor : "rgba(220,220,220,0.5)",
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
barStrokeWidth: 1, barStrokeWidth: 1,
barValueSpacing: 1, barValueSpacing: 1,
barDatasetSpacing: 1, barDatasetSpacing: 1,
data : #{@charts[:build_times].build_times.to_json} data : #{@charts[:pipeline_times].pipeline_times.to_json}
} }
] ]
} }
......
...@@ -33,13 +33,13 @@ module Ci ...@@ -33,13 +33,13 @@ module Ci
end end
class Chart class Chart
attr_reader :labels, :total, :success, :project, :build_times attr_reader :labels, :total, :success, :project, :pipeline_times
def initialize(project) def initialize(project)
@labels = [] @labels = []
@total = [] @total = []
@success = [] @success = []
@build_times = [] @pipeline_times = []
@project = project @project = project
collect collect
...@@ -101,14 +101,14 @@ module Ci ...@@ -101,14 +101,14 @@ module Ci
end end
end end
class BuildTime < Chart class PipelineTime < Chart
def collect def collect
commits = project.pipelines.last(30) commits = project.pipelines.last(30)
commits.each do |commit| commits.each do |commit|
@labels << commit.short_sha @labels << commit.short_sha
duration = commit.duration || 0 duration = commit.duration || 0
@build_times << (duration / 60) @pipeline_times << (duration / 60)
end end
end end
end end
......
require 'spec_helper' require 'spec_helper'
describe Ci::Charts, lib: true do describe Ci::Charts, lib: true do
context "build_times" do context "pipeline_times" do
let(:project) { create(:empty_project) } let(:project) { create(:empty_project) }
let(:chart) { Ci::Charts::BuildTime.new(project) } let(:chart) { Ci::Charts::PipelineTime.new(project) }
subject { chart.build_times } subject { chart.pipeline_times }
before do before do
create(:ci_empty_pipeline, project: project, duration: 120) create(:ci_empty_pipeline, project: project, duration: 120)
end end
it 'returns build times in minutes' do it 'returns pipeline times in minutes' do
is_expected.to contain_exactly(2) is_expected.to contain_exactly(2)
end end
it 'handles nil build times' do it 'handles nil pipeline times' do
create(:ci_empty_pipeline, project: project, duration: nil) create(:ci_empty_pipeline, project: project, duration: nil)
is_expected.to contain_exactly(2, 0) is_expected.to contain_exactly(2, 0)
......
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