Skip to content

Commit 5911c68

Browse files
committed
Update generated changelog filenames
Follow up rubocop/rubocop#11385.
1 parent c0e3784 commit 5911c68

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

tasks/changelog.rb

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ def extract_id(body)
5858

5959
def str_to_filename(str)
6060
str
61-
.downcase
6261
.split
63-
.each { |s| s.gsub!(/\W/, '') }
6462
.reject(&:empty?)
63+
.map { |s| prettify(s) }
6564
.inject do |result, word|
6665
s = "#{result}_#{word}"
6766
return result if s.length > MAX_LENGTH
@@ -76,6 +75,21 @@ def github_user
7675

7776
user
7877
end
78+
79+
private
80+
81+
def prettify(str)
82+
str.gsub!(/\W/, '_')
83+
84+
# Separate word boundaries by `_`.
85+
str.gsub!(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do
86+
(Regexp.last_match(1) || Regexp.last_match(2)) << '_'
87+
end
88+
89+
str.gsub!(/\A_+|_+\z/, '')
90+
str.downcase!
91+
str
92+
end
7993
end
8094

8195
def self.pending?

0 commit comments

Comments
 (0)