Module: PmdTester::ProjectHasher
Overview
Turn a project report into a hash that can be rendered somewhere else
Constant Summary
Constants included
from PmdTester
BASE, PATCH, PR_NUM_ENV_VAR, VERSION
Instance Method Summary
collapse
Methods included from PmdTester
#logger, logger
Instance Method Details
#change_type(item) ⇒ Object
92
93
94
95
96
97
98
99
100
|
# File 'lib/pmdtester/builders/project_hasher.rb', line 92
def change_type(item)
if item.branch == BASE
'removed'
elsif item.changed?
'changed'
else
'added'
end
end
|
#configerror_to_hash(configerror) ⇒ Object
84
85
86
87
88
89
90
|
# File 'lib/pmdtester/builders/project_hasher.rb', line 84
def configerror_to_hash(configerror)
{
'rule' => configerror.rulename,
'message' => configerror.msg,
'change_type' => change_type(configerror)
}
end
|
#configerrors_to_h(project) ⇒ Object
53
54
55
56
|
# File 'lib/pmdtester/builders/project_hasher.rb', line 53
def configerrors_to_h(project)
configerrors = project.report_diff.configerror_diffs_by_rule.values.flatten
configerrors.map { |e| configerror_to_hash(e) }
end
|
#error_to_hash(error, project) ⇒ Object
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
# File 'lib/pmdtester/builders/project_hasher.rb', line 63
def error_to_hash(error, project)
escaped_stacktrace = sanitize_stacktrace(error)
old_stacktrace = error.old_error.nil? ? nil : sanitize_stacktrace(error.old_error)
{
'file_url' => project.get_webview_url(error.filename),
'stack_trace_html' => escaped_stacktrace,
'old_stack_trace_html' => old_stacktrace,
'short_message' => error.short_message,
'short_filename' => error.short_filename,
'filename' => error.filename,
'change_type' => change_type(error)
}
end
|
#errors_to_h(project) ⇒ Object
48
49
50
51
|
# File 'lib/pmdtester/builders/project_hasher.rb', line 48
def errors_to_h(project)
errors = project.report_diff.error_diffs_by_file.values.flatten
errors.map { |e| error_to_hash(e, project) }
end
|
#link_template(project) ⇒ Object
58
59
60
61
|
# File 'lib/pmdtester/builders/project_hasher.rb', line 58
def link_template(project)
l_str = project.type == 'git' ? 'L' : 'l'
"#{project.webview_url}/{file}##{l_str}{line}"
end
|
#report_diff_to_h(rdiff) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/pmdtester/builders/project_hasher.rb', line 10
def report_diff_to_h(rdiff)
{
'violation_counts' => rdiff.violation_counts.to_h.transform_keys(&:to_s),
'error_counts' => rdiff.error_counts.to_h.transform_keys(&:to_s),
'configerror_counts' => rdiff.configerror_counts.to_h.transform_keys(&:to_s),
'base_execution_time' => PmdReportDetail.convert_seconds(rdiff.base_report.exec_time),
'patch_execution_time' => PmdReportDetail.convert_seconds(rdiff.patch_report.exec_time),
'diff_execution_time' => PmdReportDetail.convert_seconds(rdiff.patch_report.exec_time -
rdiff.base_report.exec_time),
'base_timestamp' => rdiff.base_report.timestamp,
'patch_timestamp' => rdiff.patch_report.timestamp,
'base_exit_code' => rdiff.base_report.exit_code,
'patch_exit_code' => rdiff.patch_report.exit_code,
'rule_diffs' => rdiff.rule_summaries
}
end
|
#sanitize_stacktrace(error) ⇒ Object
78
79
80
81
82
|
# File 'lib/pmdtester/builders/project_hasher.rb', line 78
def sanitize_stacktrace(error)
CGI.escapeHTML(error.stack_trace)
.gsub(error.filename, '<span class="meta-var">$FILE</span>')
.gsub(/\w++(?=\(\w++\.java:\d++\))/, '<span class="stack-trace-method">\\0</span>')
end
|
#violations_to_hash(project, violations_by_file, is_diff) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/pmdtester/builders/project_hasher.rb', line 31
def violations_to_hash(project, violations_by_file, is_diff)
filename_index = []
all_vs = []
violations_by_file.each do |file, vs|
file_ref = filename_index.size
filename_index.push(project.get_local_path(file))
vs.each do |v|
all_vs.push(make_violation_hash(file_ref, v, is_diff))
end
end
{
'file_index' => filename_index,
'violations' => all_vs
}
end
|