Skip to content

Commit

Permalink
Merge pull request #174 from simplybusiness/handle-sb-versioning
Browse files Browse the repository at this point in the history
Update version_setting regex and generate tests for bump
  • Loading branch information
peaky76 authored Jan 16, 2024
2 parents 63f31d6 + c149077 commit 6fa8cf9
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 3 deletions.
8 changes: 7 additions & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-09-26 09:04:51 UTC using RuboCop version 1.56.3.
# on 2024-01-15 19:01:58 UTC using RuboCop version 1.57.2.
# 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
Expand All @@ -15,3 +15,9 @@ Metrics/AbcSize:
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 17

# Offense count: 6
# Configuration parameters: IgnoreNameless, IgnoreSymbolicNames.
RSpec/VerifiedDoubles:
Exclude:
- 'spec/lib/utils/bump_spec.rb'
4 changes: 2 additions & 2 deletions lib/utils/bump.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
class Bump
SEMVER = /["']*(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?["']*/ # rubocop:disable Layout/LineLength
SEPARATOR = /\s*[:=]\s*/
VERSION_KEY = /(^|\.|\s)version/
VERSION_KEY = /(?:^|\.|\s|"|')(?:base|version)["']*/
VERSION_SETTING = Regexp.new(VERSION_KEY.source + SEPARATOR.source + SEMVER.source, Regexp::IGNORECASE).freeze

def initialize(config, level)
Expand Down Expand Up @@ -39,7 +39,7 @@ def bump_everything
)
end
end
commit.multiple_files(files, "Bump #{@level} version")
commit.multiple_files(files, "Bump #{@level} version") if files.any?
end

private
Expand Down
72 changes: 72 additions & 0 deletions spec/lib/utils/bump_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
require 'spec_helper'
require 'utils/bump'

RSpec.describe Bump do
let(:config) { double('config') }
let(:payload) { { 'repository' => { 'full_name' => 'owner/repo' }, 'issue' => { 'number' => 123 } } }
let(:client) { double('client') }
let(:version_file_path) { 'path/to/version/file' }
let(:other_version_file_paths) { ['path/to/other/version/file'] }
let(:base_content) { double('content') }
let(:head_content) { double('content') }
let(:commit) { double('commit') }

before do
allow(config).to receive_messages(
payload: payload, client: client, version_file_path: version_file_path,
other_version_file_paths: other_version_file_paths
)
allow(Content).to receive(:new).with(
config: config, ref: 'base_branch',
path: anything
).and_return(base_content)
allow(Content).to receive(:new).with(
config: config, ref: 'head_branch',
path: anything
).and_return(head_content)

allow(client).to receive(:pull_request).with(
'owner/repo',
123
).and_return({
'head' => { 'ref' => 'head_branch' },
'base' => { 'ref' => 'base_branch' }
})

allow(Commit).to receive(:new).with(config).and_return(commit)
allow(commit).to receive(:multiple_files)
end

describe '#bump_everything' do
it 'bumps the version and commits the changes' do
allow(head_content).to receive(:content).and_return('version: 1.0.0')
allow(base_content).to receive(:content).and_return('version: 1.0.0')

bump = Bump.new(config, 'patch')
expect(commit).to receive(:multiple_files).with(
[
{ path: other_version_file_paths[0], mode: '100644', type: 'blob', content: 'version: 1.0.1' },
{ path: version_file_path, mode: '100644', type: 'blob', content: 'version: 1.0.1' }
],
'Bump patch version'
)
bump.bump_everything
end

it 'skips updating if the desired version bump is already present' do
allow(head_content).to receive(:content).and_return('version: 1.0.1')
allow(base_content).to receive(:content).and_return('version: 1.0.0')

bump = Bump.new(config, 'patch')
expect(commit).not_to receive(:multiple_files)
expect do
bump.bump_everything
end.to output(
"::notice title=Nothing to update::The desired version bump is already present for: " \
"#{other_version_file_paths[0]}\n" \
"::notice title=Nothing to update::The desired version bump is already present for: " \
"#{version_file_path}\n"
).to_stdout
end
end
end

0 comments on commit 6fa8cf9

Please sign in to comment.