Class: Gitlab::Ci::Charts::Chart

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/ci/charts.rb

Direct Known Subclasses

MonthChart, PipelineTime, WeekChart, YearChart

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(project) ⇒ Chart

Returns a new instance of Chart.


39
40
41
42
43
44
45
46
47
# File 'lib/gitlab/ci/charts.rb', line 39

def initialize(project)
  @labels = []
  @total = []
  @success = []
  @pipeline_times = []
  @project = project

  collect
end

Instance Attribute Details

#labelsObject (readonly)

Returns the value of attribute labels


37
38
39
# File 'lib/gitlab/ci/charts.rb', line 37

def labels
  @labels
end

#pipeline_timesObject (readonly)

Returns the value of attribute pipeline_times


37
38
39
# File 'lib/gitlab/ci/charts.rb', line 37

def pipeline_times
  @pipeline_times
end

#projectObject (readonly)

Returns the value of attribute project


37
38
39
# File 'lib/gitlab/ci/charts.rb', line 37

def project
  @project
end

#successObject (readonly)

Returns the value of attribute success


37
38
39
# File 'lib/gitlab/ci/charts.rb', line 37

def success
  @success
end

#totalObject (readonly)

Returns the value of attribute total


37
38
39
# File 'lib/gitlab/ci/charts.rb', line 37

def total
  @total
end

Instance Method Details

#collectObject

rubocop: disable CodeReuse/ActiveRecord


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gitlab/ci/charts.rb', line 50

def collect
  query = project.all_pipelines
    .where("? > #{::Ci::Pipeline.table_name}.created_at AND #{::Ci::Pipeline.table_name}.created_at > ?", @to, @from) # rubocop:disable GitlabSecurity/SqlInjection

  totals_count  = grouped_count(query)
  success_count = grouped_count(query.success)

  current = @from
  while current < @to
    label = current.strftime(@format)

    @labels  << label
    @total   << (totals_count[label] || 0)
    @success << (success_count[label] || 0)

    current += interval_step
  end
end