Class: CodeClimate::CoverageReport
- Inherits:
-
Object
- Object
- CodeClimate::CoverageReport
- Defined in:
- app/models/code_climate/coverage_report.rb
Instance Attribute Summary collapse
-
#project ⇒ Object
readonly
Returns the value of attribute project.
-
#test_run ⇒ Object
readonly
Returns the value of attribute test_run.
Class Method Summary collapse
Instance Method Summary collapse
- #blob_id_of(filename) ⇒ Object
- #ci_service ⇒ Object
- #code_climate_payload ⇒ Object
- #commit_info ⇒ Object
- #committed_at ⇒ Object
- #covered_percent ⇒ Object
- #covered_strength ⇒ Object
- #environment ⇒ Object
-
#initialize(test_run) ⇒ CoverageReport
constructor
A new instance of CoverageReport.
- #line_counts ⇒ Object
- #publish! ⇒ Object
- #repo_token ⇒ Object
- #run_at ⇒ Object
- #short_filename(filename) ⇒ Object
- #source_files ⇒ Object
Constructor Details
#initialize(test_run) ⇒ CoverageReport
Returns a new instance of CoverageReport.
29 30 31 32 |
# File 'app/models/code_climate/coverage_report.rb', line 29 def initialize(test_run) @project = test_run.project @test_run = test_run end |
Instance Attribute Details
#project ⇒ Object (readonly)
Returns the value of attribute project.
34 35 36 |
# File 'app/models/code_climate/coverage_report.rb', line 34 def project @project end |
#test_run ⇒ Object (readonly)
Returns the value of attribute test_run.
34 35 36 |
# File 'app/models/code_climate/coverage_report.rb', line 34 def test_run @test_run end |
Class Method Details
.publish!(test_run) ⇒ Object
25 26 27 |
# File 'app/models/code_climate/coverage_report.rb', line 25 def self.publish!(test_run) self.new(test_run).publish! end |
Instance Method Details
#blob_id_of(filename) ⇒ Object
161 162 163 164 |
# File 'app/models/code_climate/coverage_report.rb', line 161 def blob_id_of(filename) blob = project.repo.find_file(filename, commit: test_run.sha) blob && blob.oid end |
#ci_service ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'app/models/code_climate/coverage_report.rb', line 129 def ci_service case project.ci_server when Houston::Adapters::CIServer::JenkinsAdapter::Job { name: "jenkins", build_identifier: test_run.results_url[/job\/#{project.slug}\/(\d+)/, 1], build_url: test_run.results_url, branch: test_run.branch, commit_sha: test_run.sha } else {} end end |
#code_climate_payload ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/code_climate/coverage_report.rb', line 45 def code_climate_payload { repo_token: repo_token, source_files: source_files, run_at: run_at, covered_percent: covered_percent, covered_strength: covered_strength, line_counts: line_counts, partial: false, git: commit_info, environment: environment, ci_service: ci_service } end |
#commit_info ⇒ Object
107 108 109 110 111 112 113 |
# File 'app/models/code_climate/coverage_report.rb', line 107 def commit_info { head: test_run.sha, committed_at: committed_at.to_i, branch: test_run.branch, } end |
#committed_at ⇒ Object
144 145 146 147 148 149 150 151 |
# File 'app/models/code_climate/coverage_report.rb', line 144 def committed_at # NB: CodeClimate actually uses committed_at return test_run.commit. if test_run.commit project.repo.native_commit(test_run.sha).committed_at rescue Houston::Adapters::VersionControl::CommitNotFound nil end |
#covered_percent ⇒ Object
89 90 91 |
# File 'app/models/code_climate/coverage_report.rb', line 89 def covered_percent (100 * test_run.covered_percent).round(2) end |
#covered_strength ⇒ Object
93 94 95 |
# File 'app/models/code_climate/coverage_report.rb', line 93 def covered_strength test_run.covered_strength.round(2) end |
#environment ⇒ Object
117 118 119 120 121 122 123 124 125 |
# File 'app/models/code_climate/coverage_report.rb', line 117 def environment { test_framework: "rspec", # result.command_name.downcase pwd: Dir.pwd, # Dir.pwd rails_root: nil, # (Rails.root.to_s rescue nil) simplecov_root: Dir.pwd, # ::SimpleCov.root gem_version: CodeClimate::TestReporter::VERSION } end |
#line_counts ⇒ Object
97 98 99 100 101 102 103 |
# File 'app/models/code_climate/coverage_report.rb', line 97 def line_counts @line_counts ||= source_files.each_with_object(Hash.new(0)) do |file, totals| totals[:total] += file[:line_counts][:total] totals[:covered] += file[:line_counts][:covered] totals[:missed] += file[:line_counts][:missed] end end |
#publish! ⇒ Object
36 37 38 39 |
# File 'app/models/code_climate/coverage_report.rb', line 36 def publish! code_climate = CodeClimate::TestReporter::Client.new code_climate.post_results code_climate_payload end |
#repo_token ⇒ Object
62 63 64 |
# File 'app/models/code_climate/coverage_report.rb', line 62 def repo_token project.code_climate_repo_token end |
#run_at ⇒ Object
85 86 87 |
# File 'app/models/code_climate/coverage_report.rb', line 85 def run_at test_run.completed_at.to_i end |
#short_filename(filename) ⇒ Object
156 157 158 |
# File 'app/models/code_climate/coverage_report.rb', line 156 def short_filename(filename) filename end |
#source_files ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'app/models/code_climate/coverage_report.rb', line 68 def source_files @source_files ||= test_run.coverage_detail.map do |file| { name: short_filename(file.filename), blob_id: blob_id_of(file.filename), coverage: file.coverage.to_json, covered_percent: file.covered_percent.round(2), covered_strength: file.covered_strength.round(2), line_counts: { total: file.lines.count, covered: file.covered_lines.count, missed: file.missed_lines.count } } end end |