From 642121248a32a31142d3aa6f33ce93c0ab817a3d Mon Sep 17 00:00:00 2001 From: William Bradford Clark Date: Wed, 6 Sep 2023 22:36:20 -0400 Subject: [PATCH 1/2] Make changelog generation more robust and resilient --- lib/tool_belt/changelog.rb | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/tool_belt/changelog.rb b/lib/tool_belt/changelog.rb index 624058fe..46b426c4 100644 --- a/lib/tool_belt/changelog.rb +++ b/lib/tool_belt/changelog.rb @@ -4,7 +4,7 @@ module ToolBelt class Changelog - attr_accessor :issues, :bugs, :features, :release_environment, :config + attr_accessor :issues, :bugs, :features, :release_environment, :config, :cached_changelog_content def initialize(config, release_environment, issues) self.config = config @@ -13,13 +13,26 @@ def initialize(config, release_environment, issues) self.issues = issues self.release_environment = release_environment + cache_existing_changelog generate_entries(@issues) changelog = format_entries - write_changelog(changelog, config.release, release_environment.main_repo, config.code_name) + releases = config.releases.keys.map { |key| key.to_s } + minor_release = releases.sort_by { |v| v.split('.').map(&:to_i) }.last + write_changelog(changelog, minor_release, release_environment.main_repo, config.code_name) + end + + def cache_existing_changelog + filepath = File.join(release_environment.repo_location(config.project), 'CHANGELOG.md') + @cached_changelog_content = File.exist?(filepath) ? File.read(filepath) : '' + end + + def issue_already_in_changelog?(issue) + @cached_changelog_content.include?(issue.html_url) end def generate_entries(issues) issues.select(&:closed?).each do |issue| + next if issue_already_in_changelog?(issue) generate_entry(issue) end end @@ -118,7 +131,7 @@ def write_changelog(changelog, release, repo, code_name = '') else file.puts("# #{release} (#{Date.today.to_s})") end - file.write(changelog) + file.write(changelog + '\n\n' + @cached_changelog_content) if File.exist?('CHANGELOG.md.backup') File.open('CHANGELOG.md.backup', 'r') { |backup| file.write(backup.read) } From de713cf3c0d0a9dd03801b6c233ea1dd9399d0f7 Mon Sep 17 00:00:00 2001 From: William Bradford Clark Date: Thu, 7 Sep 2023 15:48:54 -0400 Subject: [PATCH 2/2] Revert caching and duplicate checking --- lib/tool_belt/changelog.rb | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/lib/tool_belt/changelog.rb b/lib/tool_belt/changelog.rb index 46b426c4..46832673 100644 --- a/lib/tool_belt/changelog.rb +++ b/lib/tool_belt/changelog.rb @@ -4,7 +4,7 @@ module ToolBelt class Changelog - attr_accessor :issues, :bugs, :features, :release_environment, :config, :cached_changelog_content + attr_accessor :issues, :bugs, :features, :release_environment, :config def initialize(config, release_environment, issues) self.config = config @@ -13,7 +13,6 @@ def initialize(config, release_environment, issues) self.issues = issues self.release_environment = release_environment - cache_existing_changelog generate_entries(@issues) changelog = format_entries releases = config.releases.keys.map { |key| key.to_s } @@ -21,18 +20,8 @@ def initialize(config, release_environment, issues) write_changelog(changelog, minor_release, release_environment.main_repo, config.code_name) end - def cache_existing_changelog - filepath = File.join(release_environment.repo_location(config.project), 'CHANGELOG.md') - @cached_changelog_content = File.exist?(filepath) ? File.read(filepath) : '' - end - - def issue_already_in_changelog?(issue) - @cached_changelog_content.include?(issue.html_url) - end - def generate_entries(issues) issues.select(&:closed?).each do |issue| - next if issue_already_in_changelog?(issue) generate_entry(issue) end end @@ -131,7 +120,7 @@ def write_changelog(changelog, release, repo, code_name = '') else file.puts("# #{release} (#{Date.today.to_s})") end - file.write(changelog + '\n\n' + @cached_changelog_content) + file.write(changelog) if File.exist?('CHANGELOG.md.backup') File.open('CHANGELOG.md.backup', 'r') { |backup| file.write(backup.read) }