diff --git a/tasks/changelog.rb b/tasks/changelog.rb index e446e5a30b..2773b1631e 100644 --- a/tasks/changelog.rb +++ b/tasks/changelog.rb @@ -58,10 +58,9 @@ def extract_id(body) def str_to_filename(str) str - .downcase .split - .each { |s| s.gsub!(/\W/, '') } .reject(&:empty?) + .map { |s| prettify(s) } .inject do |result, word| s = "#{result}_#{word}" return result if s.length > MAX_LENGTH @@ -76,6 +75,21 @@ def github_user user end + + private + + def prettify(str) + str.gsub!(/\W/, '_') + + # Separate word boundaries by `_`. + str.gsub!(/([A-Z]+)(?=[A-Z][a-z])|([a-z\d])(?=[A-Z])/) do + (Regexp.last_match(1) || Regexp.last_match(2)) << '_' + end + + str.gsub!(/\A_+|_+\z/, '') + str.downcase! + str + end end def self.pending?