diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-21 19:08:37 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-02-21 19:08:37 +0200 |
commit | 9f40af47f5dfdf3bd20501331963dbcae3780915 (patch) | |
tree | 68218bb94136be437c55e9a3a363bd624e1ff43d | |
parent | f45d6436df1c34efab1b38fc01dd20149f6ab02f (diff) | |
download | gitlab-ci-9f40af47f5dfdf3bd20501331963dbcae3780915.tar.gz |
more stats. Show link to build on projects page
-rw-r--r-- | app/helpers/builds_helper.rb | 4 | ||||
-rw-r--r-- | app/helpers/projects_helper.rb | 13 | ||||
-rw-r--r-- | app/models/build.rb | 12 | ||||
-rw-r--r-- | app/views/projects/index.html.haml | 5 | ||||
-rw-r--r-- | app/views/projects/stats.html.haml | 63 | ||||
-rw-r--r-- | db/schema.rb | 4 |
6 files changed, 67 insertions, 34 deletions
diff --git a/app/helpers/builds_helper.rb b/app/helpers/builds_helper.rb index 81307ea..c247d39 100644 --- a/app/helpers/builds_helper.rb +++ b/app/helpers/builds_helper.rb @@ -28,4 +28,8 @@ module BuildsHelper build.short_sha end end + + def build_link build + link_to(build.short_sha, project_build_path(build.project, build)) + end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index bdee3e7..ff60438 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -23,14 +23,13 @@ module ProjectsHelper 'active' if ref == @ref end - def success_ratio(project) - failed_builds = project.builds.failed.count - success_buids = project.builds.success.count + def success_ratio(success_builds, failed_builds) + failed_builds = failed_builds.count + success_builds = success_builds.count - if failed_builds.zero? - return 100 - end + return 100 if failed_builds.zero? - (success_buids.to_f / (success_buids + failed_builds)) * 100 + ratio = (success_builds.to_f / (success_builds + failed_builds)) * 100 + ratio.to_i end end diff --git a/app/models/build.rb b/app/models/build.rb index 4726d96..f346842 100644 --- a/app/models/build.rb +++ b/app/models/build.rb @@ -10,10 +10,14 @@ class Build < ActiveRecord::Base scope :latest_sha, where("id IN(SELECT MAX(id) FROM #{self.table_name} group by sha)") - scope :running, where(status: "running") - scope :pending, where(status: "pending") - scope :success, where(status: "success") - scope :failed, where(status: "failed") + scope :running, ->() { where(status: "running") } + scope :pending, ->() { where(status: "pending") } + scope :success, ->() { where(status: "success") } + scope :failed, ->() { where(status: "failed") } + + def self.last_month + where('created_at > ?', Date.today - 1.month) + end state_machine :status, initial: :pending do event :run do diff --git a/app/views/projects/index.html.haml b/app/views/projects/index.html.haml index 206b8f0..adec9f3 100644 --- a/app/views/projects/index.html.haml +++ b/app/views/projects/index.html.haml @@ -1,12 +1,13 @@ %h3 Projects - @projects.each do |project| + - last_build = project.last_build .project_box .title = link_to project do %strong= project.name .alert{class: project_statuc_class(project) } - - if project.last_build - #{project.human_status} + - if last_build + #{last_build.status} (#{build_link(last_build)}) .right = time_ago_in_words project.last_build_date ago diff --git a/app/views/projects/stats.html.haml b/app/views/projects/stats.html.haml index a5e765a..e6c4e12 100644 --- a/app/views/projects/stats.html.haml +++ b/app/views/projects/stats.html.haml @@ -3,24 +3,49 @@ %p.lead Some stats related to the project -%fieldset - %legend Builds - %p - Total: - %strong= pluralize @project.builds.count, 'build' - %p - Successful: - %strong= pluralize @project.builds.success.count, 'build' - %p - Failed: - %strong= pluralize @project.builds.failed.count, 'build' +.row-fluid + .span6 + %fieldset + %legend Last month + %p + Total: + %strong= pluralize @project.builds.last_month.count, 'build' + %p + Successful: + %strong= pluralize @project.builds.last_month.success.count, 'build' + %p + Failed: + %strong= pluralize @project.builds.last_month.failed.count, 'build' - %p - Success ratio: - %strong - #{success_ratio(@project)}% + %p + Success ratio: + %strong + #{success_ratio(@project.builds.last_month.success, @project.builds.last_month.failed)}% + %p + Commits covered: + %strong + = @project.builds.last_month.latest_sha.count + + .span6 + %fieldset + %legend Overall + %p + Total: + %strong= pluralize @project.builds.count, 'build' + %p + Successful: + %strong= pluralize @project.builds.success.count, 'build' + %p + Failed: + %strong= pluralize @project.builds.failed.count, 'build' + + %p + Success ratio: + %strong + #{success_ratio(@project.builds.success, @project.builds.failed)}% + + %p + Commits covered: + %strong + = @project.builds.latest_sha.count - %p - Commits covered: - %strong - = @project.builds.latest_sha.count diff --git a/db/schema.rb b/db/schema.rb index a782fe4..299cb2b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -19,8 +19,8 @@ ActiveRecord::Schema.define(:version => 20130129121754) do t.string "status" t.datetime "finished_at" t.text "trace" - t.datetime "created_at", :null => false - t.datetime "updated_at", :null => false + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false t.string "sha" t.datetime "started_at" t.string "tmp_file" |