Skip to content

Commit dc06238

Browse files
committed
Format
1 parent c817c6d commit dc06238

File tree

1 file changed

+66
-15
lines changed

1 file changed

+66
-15
lines changed

.github/scripts/typing_stats_compare.rb

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,15 @@
77
head_stats = JSON.parse(File.read(ENV["CURRENT_STATS_PATH"]), symbolize_names: true)
88
base_stats = JSON.parse(File.read(ENV["BASE_STATS_PATH"]), symbolize_names: true)
99

10+
def format_for_code_block(data)
11+
data.map do |item|
12+
formatted_string = +"#{item[:path]}:#{item[:line]}"
13+
formatted_string << "\n└── #{item[:line_content]}" if item[:line_content]
14+
formatted_string
15+
end.join("\n")
16+
end
1017

11-
def create_summary(
18+
def create_intro(
1219
added:,
1320
removed:,
1421
data_name:,
@@ -19,48 +26,73 @@ def create_summary(
1926
head_percentage: nil,
2027
percentage_data_name: nil
2128
)
22-
return nil if added.empty? && removed.empty?
23-
2429
intro = +"This PR "
2530
intro << "introduces " if added.any? || added_partially.any?
26-
intro << "**#{added.size}** #{data_name} " if added.any?
27-
intro << "and " if added.any? && added_partially.any?
28-
intro << "**#{added_partially.size}** #{data_name_partially} " if added_partially.any?
29-
intro << "and " if (added.any? || added_partially.any?) && (removed.any? || removed_partially.any?)
31+
intro << "**#{added.size}** #{data_name}" if added.any?
32+
intro << " and " if added.any? && added_partially.any?
33+
intro << "**#{added_partially.size}** #{data_name_partially}" if added_partially.any?
34+
intro << ", and " if (added.any? || added_partially.any?) && (removed.any? || removed_partially.any?)
3035
intro << "clears " if removed.any? || removed_partially.any?
31-
intro << "**#{removed.size}** #{data_name} " if removed.any?
32-
intro << "and " if removed.any? && removed_partially.any?
33-
intro << "**#{removed_partially.size}** #{data_name_partially} " if removed_partially.any?
36+
intro << "**#{removed.size}** #{data_name}" if removed.any?
37+
intro << " and " if removed.any? && removed_partially.any?
38+
intro << "**#{removed_partially.size}** #{data_name_partially}" if removed_partially.any?
3439
if base_percentage != head_percentage
3540
intro << ". It #{(base_percentage > head_percentage) ? "decreases" : "increases"} "
3641
intro << "the percentage of #{percentage_data_name} from #{base_percentage}% to #{head_percentage}% "
3742
intro << "(**#{"+" if head_percentage > base_percentage}#{(head_percentage - base_percentage).round(2)}**%)"
3843
end
3944
intro << "."
45+
intro
46+
end
47+
48+
def create_summary(
49+
added:,
50+
removed:,
51+
data_name:,
52+
added_partially: [],
53+
removed_partially: [],
54+
data_name_partially: nil,
55+
base_percentage: nil,
56+
head_percentage: nil,
57+
percentage_data_name: nil
58+
)
59+
return nil if added.empty? && removed.empty? && added_partially.empty? && removed_partially.empty?
60+
61+
intro = create_intro(
62+
added: added,
63+
removed: removed,
64+
added_partially: added_partially,
65+
removed_partially: removed_partially,
66+
data_name: data_name,
67+
data_name_partially: data_name_partially,
68+
base_percentage: base_percentage,
69+
head_percentage: head_percentage,
70+
percentage_data_name: percentage_data_name
71+
)
4072

4173
summary = +"### #{data_name.capitalize}\n"
4274
summary << "#{intro}\n"
4375
if added.any? || removed.any?
4476
summary << "<details><summary>#{data_name.capitalize}</summary>\n"
4577
if added.any?
4678
summary << " ❌ <em>Introduced:</em>\n"
47-
summary << " <pre><code>#{added.join("\n")}</code></pre>\n"
79+
summary << " <pre><code>#{format_for_code_block(added)}</code></pre>\n"
4880
end
4981
if removed.any?
5082
summary << " ✅ <em>Cleared:</em>\n"
51-
summary << " <pre><code>#{removed.join("\n")}</code></pre>\n"
83+
summary << " <pre><code>#{format_for_code_block(removed)}</code></pre>\n"
5284
end
5385
summary << "</details>\n"
5486
end
5587
if added_partially.any? || removed_partially.any?
5688
summary << "<details><summary>#{data_name_partially.capitalize}</summary>\n"
5789
if added_partially.any?
5890
summary << " ❌ <em>Introduced:</em>\n"
59-
summary << " <pre><code>#{added_partially.join("\n")}</code></pre>\n"
91+
summary << " <pre><code>#{format_for_code_block(added_partially)}</code></pre>\n"
6092
end
6193
if removed_partially.any?
6294
summary << " ✅ <em>Cleared:</em>\n"
63-
summary << " <pre><code>#{removed_partially.join("\n")}</code></pre>\n"
95+
summary << " <pre><code>#{format_for_code_block(removed_partially)}</code></pre>\n"
6496
end
6597
summary << "</details>\n"
6698
end
@@ -73,17 +105,36 @@ def ignored_files_summary(head_stats, base_stats)
73105
# This will skip the summary if files are added/removed from contrib folders for now.
74106
ignored_files_added = head_stats[:ignored_files][:paths] - base_stats[:ignored_files][:paths]
75107
ignored_files_removed = base_stats[:ignored_files][:paths] - head_stats[:ignored_files][:paths]
108+
109+
return nil if ignored_files_added.empty? && ignored_files_removed.empty?
110+
76111
typed_files_percentage_base = ((base_stats[:total_files_size] - base_stats[:ignored_files][:size]) / base_stats[:total_files_size].to_f * 100).round(2)
77112
typed_files_percentage_head = ((head_stats[:total_files_size] - head_stats[:ignored_files][:size]) / head_stats[:total_files_size].to_f * 100).round(2)
78113

79-
create_summary(
114+
intro = create_intro(
80115
added: ignored_files_added,
81116
removed: ignored_files_removed,
82117
data_name: "ignored files",
83118
base_percentage: typed_files_percentage_base,
84119
head_percentage: typed_files_percentage_head,
85120
percentage_data_name: "typed files"
86121
)
122+
123+
summary = +"### Ignored files\n"
124+
summary << "#{intro}\n"
125+
summary << "<details><summary>Ignored files</summary>\n"
126+
if ignored_files_added.any?
127+
summary << " ❌ <em>Introduced:</em>\n"
128+
summary << " <pre><code>#{ignored_files_added.join("\n")}</code></pre>\n"
129+
end
130+
if ignored_files_removed.any?
131+
summary << " ✅ <em>Cleared:</em>\n"
132+
summary << " <pre><code>#{ignored_files_removed.join("\n")}</code></pre>\n"
133+
end
134+
summary << "</details>\n"
135+
summary << "\n"
136+
total_introduced = ignored_files_added&.size || 0
137+
[summary, total_introduced]
87138
end
88139

89140
def steep_ignore_summary(head_stats, base_stats)

0 commit comments

Comments
 (0)