Class: CodeclimateDiff::IssueSorter
- Inherits:
-
Object
- Object
- CodeclimateDiff::IssueSorter
- Defined in:
- lib/codeclimate_diff/issue_sorter.rb
Class Method Summary collapse
- .remove_closest_match_from_list(issue_to_match, list) ⇒ Object
- .sort_issues(preexisting_issues, changed_file_issues) ⇒ Object
Class Method Details
.remove_closest_match_from_list(issue_to_match, list) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/codeclimate_diff/issue_sorter.rb', line 5 def self.remove_closest_match_from_list(issue_to_match, list) # check for exact match first index = list.index do |issue| issue["fingerprint"] == issue_to_match["fingerprint"] && issue["location"]["lines"]["begin"] == issue_to_match["location"]["lines"]["begin"] && issue["description"] == issue_to_match["description"] end if index list.delete_at(index) return end # check for same method name (description often has method name or variable name in it) index = list.index do |issue| issue["fingerprint"] == issue_to_match["fingerprint"] && issue["description"] == issue_to_match["description"] end if index list.delete_at(index) return end # otherwise just remove the first one list.pop end |
.sort_issues(preexisting_issues, changed_file_issues) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/codeclimate_diff/issue_sorter.rb', line 33 def self.sort_issues(preexisting_issues, changed_file_issues) puts "Sorting into :preexisting, :new and :fixed lists..." result = {} result[:preexisting] = [] result[:new] = [] result[:fixed] = [] # fingerprints are unique per issue type and file # so there could be multiple if the same issue shows up multiple times # plus line numbers and method names could have changed unique_fingerprints = (preexisting_issues + changed_file_issues).map { |issue| issue["fingerprint"] }.uniq unique_fingerprints.each do |fingerprint| baseline_issues = preexisting_issues.filter { |issue| issue["fingerprint"] == fingerprint } current_issues = changed_file_issues.filter { |issue| issue["fingerprint"] == fingerprint } if baseline_issues.count == current_issues.count # current issues are most up to date (line numbers could have changed etc.) result[:preexisting] += current_issues elsif current_issues.count < baseline_issues.count # less issues than there were before current_issues.each do |issue_to_match| CodeclimateDiff.remove_closest_match_from_list(issue_to_match, baseline_issues) end result[:fixed] += baseline_issues else # more issues than there were before baseline_issues.each do |issue_to_match| CodeclimateDiff.remove_closest_match_from_list(issue_to_match, current_issues) end result[:new] += current_issues end end # do a check to make sure the maths works out puts "#{preexisting_issues.count} issues in matching files in baseline" puts "#{changed_file_issues.count} current issues in matching files" result end |