2015-08-25 21:42:46 -04:00
|
|
|
module Ci
|
|
|
|
module Charts
|
|
|
|
class Chart
|
|
|
|
attr_reader :labels, :total, :success, :project, :build_times
|
|
|
|
|
|
|
|
def initialize(project)
|
|
|
|
@labels = []
|
|
|
|
@total = []
|
|
|
|
@success = []
|
|
|
|
@build_times = []
|
|
|
|
@project = project
|
|
|
|
|
|
|
|
collect
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def push(from, to, format)
|
|
|
|
@labels << from.strftime(format)
|
2015-12-10 11:44:06 -05:00
|
|
|
@total << project.builds.
|
2015-08-26 20:47:18 -04:00
|
|
|
where("? > #{Ci::Build.table_name}.created_at AND #{Ci::Build.table_name}.created_at > ?", to, from).
|
2015-08-25 21:42:46 -04:00
|
|
|
count(:all)
|
2015-12-10 11:44:06 -05:00
|
|
|
@success << project.builds.
|
2015-08-26 20:47:18 -04:00
|
|
|
where("? > #{Ci::Build.table_name}.created_at AND #{Ci::Build.table_name}.created_at > ?", to, from).
|
2015-08-25 21:42:46 -04:00
|
|
|
success.count(:all)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class YearChart < Chart
|
|
|
|
def collect
|
|
|
|
13.times do |i|
|
|
|
|
start_month = (Date.today.years_ago(1) + i.month).beginning_of_month
|
|
|
|
end_month = start_month.end_of_month
|
|
|
|
|
|
|
|
push(start_month, end_month, "%d %B %Y")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class MonthChart < Chart
|
|
|
|
def collect
|
|
|
|
30.times do |i|
|
|
|
|
start_day = Date.today - 30.days + i.days
|
|
|
|
end_day = Date.today - 30.days + i.day + 1.day
|
|
|
|
|
|
|
|
push(start_day, end_day, "%d %B")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class WeekChart < Chart
|
|
|
|
def collect
|
|
|
|
7.times do |i|
|
|
|
|
start_day = Date.today - 7.days + i.days
|
|
|
|
end_day = Date.today - 7.days + i.day + 1.day
|
|
|
|
|
|
|
|
push(start_day, end_day, "%d %B")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class BuildTime < Chart
|
|
|
|
def collect
|
2015-12-04 06:55:23 -05:00
|
|
|
commits = project.ci_commits.last(30)
|
2015-11-10 05:49:38 -05:00
|
|
|
|
2015-08-25 21:42:46 -04:00
|
|
|
commits.each do |commit|
|
|
|
|
@labels << commit.short_sha
|
|
|
|
@build_times << (commit.duration / 60)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|