From a1e0556bfe07e27b2295c15f6c77653f7f0a75c5 Mon Sep 17 00:00:00 2001 From: Koichi ITO Date: Sat, 7 Jan 2023 09:40:21 +0900 Subject: [PATCH] Update generated changelog filenames Follow up https://github.com/rubocop/rubocop/pull/11385. --- tasks/changelog.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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?