Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RuboCop configuration, bump dependencies, and enhance error messaging in action and command classes #228

Merged
merged 3 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -139,4 +139,4 @@ DEPENDENCIES
simplycop (= 2.5.1)

BUNDLED WITH
2.4.12
2.5.22
1 change: 1 addition & 0 deletions lib/action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion lib/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
19 changes: 17 additions & 2 deletions lib/utils/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
3 changes: 2 additions & 1 deletion spec/lib/action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions temp.md
Original file line number Diff line number Diff line change
@@ -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'.
Loading