From a569e0b9fc920655d2204ad4999121bb9f244f2d Mon Sep 17 00:00:00 2001 From: Adam Leach Date: Fri, 18 Oct 2024 16:52:48 +0100 Subject: [PATCH 1/3] Update RuboCop configuration, bump dependencies, and enhance error messaging in action and command classes --- .rubocop_todo.yml | 17 ++++++++++++----- Gemfile.lock | 14 +++++++------- lib/action.rb | 1 + lib/command.rb | 8 +++++++- lib/utils/bump.rb | 19 +++++++++++++++++-- spec/lib/action_spec.rb | 3 ++- spec/spec_helper.rb | 4 ++++ temp.md | 4 ++++ 8 files changed, 54 insertions(+), 16 deletions(-) create mode 100644 temp.md diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ae2f053..7c94953 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,23 +1,30 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-01-15 19:01:58 UTC using RuboCop version 1.57.2. +# on 2024-10-18 15:50:54 UTC using RuboCop version 1.66.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 +# Offense count: 2 # Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. Metrics/AbcSize: Max: 34 -# Offense count: 1 +# Offense count: 3 # Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. Metrics/MethodLength: - Max: 17 + Max: 20 -# Offense count: 6 +# Offense count: 5 # Configuration parameters: IgnoreNameless, IgnoreSymbolicNames. RSpec/VerifiedDoubles: Exclude: - 'spec/lib/utils/bump_spec.rb' + +# Offense count: 3 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 169 diff --git a/Gemfile.lock b/Gemfile.lock index 2bd6bf5..0e3113d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (7.2.1) + activesupport (7.2.1.1) base64 bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) @@ -21,7 +21,7 @@ GEM concurrent-ruby (1.3.4) connection_pool (2.4.1) diff-lcs (1.5.1) - docile (1.4.0) + docile (1.4.1) drb (2.2.1) faraday (2.12.0) faraday-net_http (>= 2.0, < 3.4) @@ -38,7 +38,7 @@ GEM base64 language_server-protocol (3.17.0.3) logger (1.6.1) - method_source (1.0.0) + method_source (1.1.0) minitest (5.25.1) net-http (0.4.1) uri @@ -54,16 +54,16 @@ GEM method_source (~> 1.0) public_suffix (6.0.1) racc (1.8.1) - rack (3.1.7) + rack (3.1.8) rainbow (3.1.1) regexp_parser (2.9.2) rspec (3.13.0) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) rspec-mocks (~> 3.13.0) - rspec-core (3.13.0) + rspec-core (3.13.1) rspec-support (~> 3.13.0) - rspec-expectations (3.13.0) + rspec-expectations (3.13.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) rspec-mocks (3.13.2) @@ -139,4 +139,4 @@ DEPENDENCIES simplycop (= 2.5.1) BUNDLED WITH - 2.4.12 + 2.5.22 diff --git a/lib/action.rb b/lib/action.rb index cada2ce..68fe72f 100644 --- a/lib/action.rb +++ b/lib/action.rb @@ -26,6 +26,7 @@ def initiate_version_update(level) else add_reaction('confused') puts "::error title=Unknown semver level::The semver level #{level} is not valid" + "## :boom: Error:boom: \n\nThe semver level #{level} is not valid so failing the action. Expecting a semver level of #{VALID_SEMVER_LEVELS.join(', ')}" end end diff --git a/lib/command.rb b/lib/command.rb index 0d41644..97f510e 100644 --- a/lib/command.rb +++ b/lib/command.rb @@ -10,10 +10,12 @@ class Command def initialize(config) @config = config + @message = "### Dobby bumping the version\n" comment = config.payload['comment']['body'].strip.downcase unless comment.start_with?(COMMAND_PREFIX) error_msg = "Comment must start with #{COMMAND_PREFIX}" puts "::error title=Argument Error::#{error_msg}" + @message += "## :boom: Error:boom:\n\n The comment must start with #{COMMAND_PREFIX} so failing the action." raise ArgumentError, error_msg end @@ -26,10 +28,14 @@ def call action = Action.new(config) case command when 'version' - action.initiate_version_update(options) + @message += action.initiate_version_update(options).to_s else + @message += "## :boom: Error:boom:\n\nThe command #{command} is not valid so failing the action. Expecting a command of 'version'." puts "::error title=Unknown command::The command #{command} is not valid" action.add_reaction('confused') end + File.open(ENV.fetch('GITHUB_STEP_SUMMARY', nil), 'w') do |file| + file.puts @message + end end end diff --git a/lib/utils/bump.rb b/lib/utils/bump.rb index 86b5371..707c451 100644 --- a/lib/utils/bump.rb +++ b/lib/utils/bump.rb @@ -24,28 +24,32 @@ def initialize(config, level) def bump_everything commit = Commit.new(@config) files = [] + files_messages = {} @other_version_file_paths.push(@version_file_path).each do |version_file_path| head_branch_content = Content.new(config: @config, ref: @head_branch, path: version_file_path) updated_base_branch_content = head_branch_content.content.gsub @version.to_s, @updated_version.to_s if head_branch_content.content == updated_base_branch_content puts "::notice title=Nothing to update::The desired version bump is already present for: #{version_file_path}" + files_messages[version_file_path] = 'Nothing to update as the desired version bump is already present' else files.push( { :path => version_file_path, :mode => '100644', :type => 'blob', :content => updated_base_branch_content } ) + files_messages[version_file_path] = "Bump #{@level} version from #{@version} to #{@updated_version}" end end commit.multiple_files(files, "Bump #{@level} version") if files.any? + generate_message(files_messages) end private def calculate_bumping_data! - base_branch_content = Content.new(config: @config, ref: @base_branch, path: @version_file_path) - @version = fetch_version(base_branch_content) + head_branch_content = Content.new(config: @config, ref: @head_branch, path: @version_file_path) + @version = fetch_version(head_branch_content) @updated_version = bump_version(@version, @level) end @@ -63,4 +67,15 @@ def fetch_version(content) def bump_version(version, level) version.increment!(level.to_sym) end + + def generate_message(files_messages) + message = "### Bump version from #{@version} to #{@updated_version}\n" + message += "| File Name | Message |\n" + message += "|-----------|---------|\n" + files_messages.each do |file_name, msg| + message += "| #{file_name} | #{msg} |\n" + end + message += "|-----------|---------|\n" + message + end end diff --git a/spec/lib/action_spec.rb b/spec/lib/action_spec.rb index b7292cd..fe0a217 100644 --- a/spec/lib/action_spec.rb +++ b/spec/lib/action_spec.rb @@ -35,7 +35,8 @@ describe '#initiate_version_update' do it 'reacts with confused emoji for invalid semver' do expect(action).to receive(:add_reaction).with('confused') - action.initiate_version_update('invalid_semver') + message = action.initiate_version_update('invalid_semver') + expect(message).to eq("## :boom: Error:boom: The semver level invalid_semver is not valid so failing the action. Expecting a semver level of minor, major, patch") end it 'bumps major version' do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 9448e43..7ee72a8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,4 +17,8 @@ end config.shared_context_metadata_behavior = :apply_to_host_groups + + config.before do + ENV['GITHUB_STEP_SUMMARY'] = 'temp.md' + end end diff --git a/temp.md b/temp.md new file mode 100644 index 0000000..0115fc5 --- /dev/null +++ b/temp.md @@ -0,0 +1,4 @@ +### Dobby bumping the version +## :boom: Error:boom: + +The command barney is not valid so failing the action. Expecting a command of 'version'. From 6422fe294305c6adb51e0330899780a5f8b8f0c6 Mon Sep 17 00:00:00 2001 From: Adam Leach Date: Fri, 18 Oct 2024 16:56:51 +0100 Subject: [PATCH 2/3] Refactor version fetching to use base branch content and improve error message formatting in action specs --- lib/utils/bump.rb | 4 ++-- spec/lib/action_spec.rb | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/utils/bump.rb b/lib/utils/bump.rb index 707c451..9e10f9f 100644 --- a/lib/utils/bump.rb +++ b/lib/utils/bump.rb @@ -48,8 +48,8 @@ def bump_everything private def calculate_bumping_data! - head_branch_content = Content.new(config: @config, ref: @head_branch, path: @version_file_path) - @version = fetch_version(head_branch_content) + base_branch_content = Content.new(config: @config, ref: @base_branch, path: @version_file_path) + @version = fetch_version(base_branch_content) @updated_version = bump_version(@version, @level) end diff --git a/spec/lib/action_spec.rb b/spec/lib/action_spec.rb index fe0a217..07faecd 100644 --- a/spec/lib/action_spec.rb +++ b/spec/lib/action_spec.rb @@ -36,7 +36,7 @@ it 'reacts with confused emoji for invalid semver' do expect(action).to receive(:add_reaction).with('confused') message = action.initiate_version_update('invalid_semver') - expect(message).to eq("## :boom: Error:boom: The semver level invalid_semver is not valid so failing the action. Expecting a semver level of minor, major, patch") + expect(message).to eq("## :boom: Error:boom: \n\nThe semver level invalid_semver is not valid so failing the action. Expecting a semver level of minor, major, patch") end it 'bumps major version' do From cc9498730d4c0e4142cd99fff56454efd6c32076 Mon Sep 17 00:00:00 2001 From: Adam Leach Date: Fri, 18 Oct 2024 16:57:56 +0100 Subject: [PATCH 3/3] Update RuboCop TODO configuration with new timestamp and increase line length limit to 173 --- .rubocop_todo.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7c94953..27e83c7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2024-10-18 15:50:54 UTC using RuboCop version 1.66.1. +# on 2024-10-18 15:57:43 UTC using RuboCop version 1.66.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -27,4 +27,4 @@ RSpec/VerifiedDoubles: # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. # URISchemes: http, https Layout/LineLength: - Max: 169 + Max: 173