|
1 | 1 | #!/usr/bin/env ruby |
2 | 2 |
|
3 | | -require 'json' |
| 3 | +# frozen_string_literal: true |
4 | 4 |
|
5 | | -current_stats = JSON.parse(File.read(ENV['CURRENT_STATS_PATH']), symbolize_names: true) |
6 | | -base_stats = JSON.parse(File.read(ENV['BASE_STATS_PATH']), symbolize_names: true) |
| 5 | +require "json" |
| 6 | + |
| 7 | +head_stats = JSON.parse(File.read(ENV["CURRENT_STATS_PATH"]), symbolize_names: true) |
| 8 | +base_stats = JSON.parse(File.read(ENV["BASE_STATS_PATH"]), symbolize_names: true) |
7 | 9 |
|
8 | 10 | # If a file is added in contrib, currently the paths will have no diff. |
9 | | -ignored_files_paths_added = current_stats[:ignored_files][:paths] - base_stats[:ignored_files][:paths] |
10 | | -ignored_files_paths_removed = base_stats[:ignored_files][:paths] - current_stats[:ignored_files][:paths] |
11 | | - |
12 | | -steep_ignores_added = current_stats[:steep_ignore_comments] - base_stats[:steep_ignore_comments] |
13 | | -steep_ignores_removed = base_stats[:steep_ignore_comments] - current_stats[:steep_ignore_comments] |
14 | | - |
15 | | -untyped_methods_added = current_stats[:untyped_methods] - base_stats[:untyped_methods] |
16 | | -untyped_methods_removed = base_stats[:untyped_methods] - current_stats[:untyped_methods] |
17 | | - |
18 | | -partially_typed_methods_added = current_stats[:partially_typed_methods] - base_stats[:partially_typed_methods] |
19 | | -partially_typed_methods_removed = base_stats[:partially_typed_methods] - current_stats[:partially_typed_methods] |
20 | | - |
21 | | -untyped_others_added = current_stats[:untyped_others] - base_stats[:untyped_others] |
22 | | -untyped_others_removed = base_stats[:untyped_others] - current_stats[:untyped_others] |
23 | | - |
24 | | -partially_typed_others_added = current_stats[:partially_typed_others] - base_stats[:partially_typed_others] |
25 | | -partially_typed_others_removed = base_stats[:partially_typed_others] - current_stats[:partially_typed_others] |
26 | | - |
27 | | -diff_stats = { |
28 | | - ignored_files: { |
29 | | - added: ignored_files_paths_added, |
30 | | - removed: ignored_files_paths_removed |
31 | | - }, |
32 | | - steep_ignores: { |
33 | | - added: steep_ignores_added, |
34 | | - removed: steep_ignores_removed |
35 | | - }, |
36 | | - methods: { |
37 | | - untyped: { |
38 | | - added: untyped_methods_added, |
39 | | - removed: untyped_methods_removed |
40 | | - }, |
41 | | - partially_typed: { |
42 | | - added: partially_typed_methods_added, |
43 | | - removed: partially_typed_methods_removed |
44 | | - } |
45 | | - }, |
46 | | - others: { |
47 | | - untyped: { |
48 | | - added: untyped_others_added, |
49 | | - removed: untyped_others_removed |
50 | | - }, |
51 | | - partially_typed: { |
52 | | - added: partially_typed_others_added, |
53 | | - removed: partially_typed_others_removed |
54 | | - } |
55 | | - } |
| 11 | +ignored_files = { |
| 12 | + added: head_stats[:ignored_files][:paths] - base_stats[:ignored_files][:paths], |
| 13 | + removed: base_stats[:ignored_files][:paths] - head_stats[:ignored_files][:paths] |
56 | 14 | } |
57 | 15 |
|
58 | | -puts diff_stats.to_json |
| 16 | +def ignored_files_summary(head_stats, base_stats) |
| 17 | + # This will skip the summary if files are added/removed from contrib folders for now. |
| 18 | + ignored_files_added = head_stats[:ignored_files][:paths] - base_stats[:ignored_files][:paths] |
| 19 | + ignored_files_removed = base_stats[:ignored_files][:paths] - head_stats[:ignored_files][:paths] |
| 20 | + return nil if ignored_files_added.empty? && ignored_files_removed.empty? |
| 21 | + |
| 22 | + typed_files_percentage_base = ((base_stats[:total_files_size] - base_stats[:ignored_files][:size]) / base_stats[:total_files_size].to_f * 100).round(2) |
| 23 | + typed_files_percentage_head = ((head_stats[:total_files_size] - head_stats[:ignored_files][:size]) / head_stats[:total_files_size].to_f * 100).round(2) |
| 24 | + |
| 25 | + summary = +"This PR " |
| 26 | + summary << "adds **#{ignored_files_added.size}** ignored files " if ignored_files_added.any? |
| 27 | + summary << "and " if ignored_files_added.any? && ignored_files_removed.any? |
| 28 | + summary << "removes **#{ignored_files_removed.size}** ignored files " if ignored_files_removed.any? |
| 29 | + if typed_files_percentage_base != typed_files_percentage_head |
| 30 | + summary << "which #{(typed_files_percentage_base > typed_files_percentage_head) ? "decreases" : "increases"} the percentage of typed files from #{typed_files_percentage_base}% to #{typed_files_percentage_head}% (**#{typed_files_percentage_head - typed_files_percentage_base}**%)" |
| 31 | + end |
| 32 | + summary << "." |
| 33 | + |
| 34 | + <<~IGNORED_FILES |
| 35 | + ### Ignored files |
| 36 | + #{summary} |
| 37 | + <details><summary>Ignored files</summary> |
| 38 | + #{"<em>Added:</em>" if ignored_files_added.any?} |
| 39 | + #{"<pre><code>#{ignored_files_added.join("\n")}</code></pre>" if ignored_files_added.any?} |
| 40 | + #{"<em>Removed:</em>" if ignored_files_removed.any?} |
| 41 | + #{"<pre><code>#{ignored_files_removed.join("\n")}</code></pre>" if ignored_files_removed.any?} |
| 42 | + </details> |
| 43 | +
|
| 44 | + *__Note__: Ignored files are excluded from the next sections.* |
| 45 | +
|
| 46 | + IGNORED_FILES |
| 47 | +end |
| 48 | + |
| 49 | +result = +"" |
| 50 | +result << ignored_files_summary(head_stats, base_stats) |
| 51 | +result |
0 commit comments