Class: Danger::DangerComposeCompilerMetrics
- Inherits:
-
Plugin
- Object
- Plugin
- Danger::DangerComposeCompilerMetrics
- Includes:
- Helper
- Defined in:
- lib/compose_compiler_metrics/plugin.rb
Instance Method Summary collapse
- #report(metrics_dir) ⇒ Object
- #report_difference(metrics_dir, reference_metrics_dir) ⇒ Object
- #report_file_difference(title, metrics_path, reference_metrics_path) ⇒ Object
- #report_metrics_report(title, metrics_path, reference_metrics_path) ⇒ Object
Methods included from Helper
#build_markdown_table, #build_variants, #class_report_path, #composable_report_path, #composable_stats_report_path, #folding, #installed?, #metrics_filename
Instance Method Details
#report(metrics_dir) ⇒ Object
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/compose_compiler_metrics/plugin.rb', line 122 def report(metrics_dir) markdown("# Compose Compiler Metrics Report") build_variants(metrics_dir).each do |module_name, build_variant| markdown("## #{module_name} - #{build_variant}") # Metrics Report metrics_path = File.join(metrics_dir, metrics_filename(module_name, build_variant)) table_headers = %w(name value) table_rows = JSON.load_file(metrics_path).to_a markdown( folding( "### Metrics", build_markdown_table(table_headers, table_rows) ) ) # Composable Stats Report composable_stats_report_path = File.join(metrics_dir, composable_stats_report_path(module_name, build_variant)) csv = CSV.read(composable_stats_report_path, headers: true) markdown( folding( "### Composable Stats Report", build_markdown_table(csv.headers, csv.map(&:fields)) ) ) # Composable Report composable_report_path = File.join(metrics_dir, composable_report_path(module_name, build_variant)) markdown( folding( "### Composable Report", " ```kotlin\n \#{File.read(composable_report_path)}\n ```\n MARKDOWN\n )\n )\n\n # Class Report\n class_report_path = File.join(metrics_dir, class_report_path(module_name, build_variant))\n markdown(\n folding(\n \"### Class Report\",\n <<~MARKDOWN\n ```kotlin\n \#{File.read(class_report_path)}\n ```\n MARKDOWN\n )\n )\n end\nend\n" |
#report_difference(metrics_dir, reference_metrics_dir) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/compose_compiler_metrics/plugin.rb', line 13 def report_difference(metrics_dir, reference_metrics_dir) unless installed?("diff") failure "diff command not found. Please install diff command." return end markdown("# Compose Compiler Metrics Difference Report") build_variants(metrics_dir).each do |module_name, build_variant| markdown("## #{module_name} - #{build_variant}") # Metrics Report metrics_path = File.join(metrics_dir, metrics_filename(module_name, build_variant)) reference_metrics_path = File.join(reference_metrics_dir, metrics_filename(module_name, build_variant)) report_metrics_report("Metrics Summary", metrics_path, reference_metrics_path) report_file_difference("Metrics", metrics_path, reference_metrics_path) # Composable Stats Report composable_stats_report_path = File.join(metrics_dir, composable_stats_report_path(module_name, build_variant)) reference_composable_stats_report_path = File.join(reference_metrics_dir, composable_stats_report_path(module_name, build_variant)) report_file_difference("Composable Stats Report", composable_stats_report_path, reference_composable_stats_report_path) # Composable Report composable_report_path = File.join(metrics_dir, composable_report_path(module_name, build_variant)) reference_composable_report_path = File.join(reference_metrics_dir, composable_report_path(module_name, build_variant)) report_file_difference("Composable Report", composable_report_path, reference_composable_report_path) # Class Report class_report_path = File.join(metrics_dir, class_report_path(module_name, build_variant)) reference_class_report_path = File.join(reference_metrics_dir, class_report_path(module_name, build_variant)) report_file_difference("Class Report", class_report_path, reference_class_report_path) end end |
#report_file_difference(title, metrics_path, reference_metrics_path) ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/compose_compiler_metrics/plugin.rb', line 93 def report_file_difference(title, metrics_path, reference_metrics_path) unless File.exist?(metrics_path) warn "DangerComposeCompilerMetrics: new file not found at #{metrics_path}. Skipping file difference report." return end unless File.exist?(reference_metrics_path) warn "DangerComposeCompilerMetrics: reference file not found at #{reference_metrics_path}. Skipping file difference report." return end report = `diff -u #{reference_metrics_path} #{metrics_path}` markdown( folding( "### #{title}", if report.empty? "No difference found." else " ```diff\n \#{report}\n ```\n MARKDOWN\n end\n )\n )\nend\n" |
#report_metrics_report(title, metrics_path, reference_metrics_path) ⇒ Object
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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/compose_compiler_metrics/plugin.rb', line 47 def report_metrics_report(title, metrics_path, reference_metrics_path) unless File.exist?(metrics_path) warn "DangerComposeCompilerMetrics: new file not found at #{metrics_path}. Skipping file difference report." return end unless File.exist?(reference_metrics_path) warn "DangerComposeCompilerMetrics: reference file not found at #{reference_metrics_path}. Skipping file difference report." return end metrics = Metrics.load(metrics_path) reference_metrics = Metrics.load(reference_metrics_path) tables = reference_metrics.grouped_metrics.map do |group_key, grouped_reference_metrics| grouped_metrics = metrics.grouped_metrics[group_key] table_headers = %w(name reference new diff) table_rows = grouped_reference_metrics.keys.map do |key| new_value = grouped_metrics.send(key.to_sym) reference_value = grouped_reference_metrics.send(key.to_sym) diff_value = (new_value - reference_value).then do |v| next "+#{v}" if v.positive? next v.to_s if v.negative? "" end [key, reference_value, new_value, diff_value] end [ "#### #{group_key}", build_markdown_table(table_headers, table_rows) ].join("\n\n") end markdown( folding( "### #{title}", tables.join("\n\n") ) ) end |