diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-11 12:38:03 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-15 14:39:46 +0200 |
commit | f0ff1bfdcc43decd1888f7b8d4a9e8c4dd5540d9 (patch) | |
tree | 0ed2fa8531ec046c9adc01c6086c13246231d099 /lib | |
parent | f3de46e6b0d4cc61e00c884753a8c9eec66f66c4 (diff) | |
download | gitlab-ce-f0ff1bfdcc43decd1888f7b8d4a9e8c4dd5540d9.tar.gz |
Implement the main class of test coverage badge
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/badge/coverage/report.rb | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/lib/gitlab/badge/coverage/report.rb b/lib/gitlab/badge/coverage/report.rb index e6de15e085f..f06142003e3 100644 --- a/lib/gitlab/badge/coverage/report.rb +++ b/lib/gitlab/badge/coverage/report.rb @@ -5,13 +5,42 @@ module Gitlab # Test coverage report badge # class Report < Badge::Base + attr_reader :project, :ref, :job + def initialize(project, ref, job = nil) @project = project @ref = ref @job = job + + @pipeline = @project.pipelines + .where(ref: @ref) + .where(sha: @project.commit(@ref).try(:sha)) + .first end - def coverage + def entity + 'coverage' + end + + def status + @coverage ||= raw_coverage + return unless @coverage + + @coverage.to_i + end + + private + + def raw_coverage + return unless @pipeline + + if @job.blank? + @pipeline.coverage + else + @pipeline.builds + .find_by(name: @job) + .try(:coverage) + end end end end |