Skip to content
Snippets Groups Projects
Commit b08e4751 authored by Robert Speicher's avatar Robert Speicher
Browse files

Merge branch 'validate-omnibus-version' into 'master'

Parse version strings using the omnibus version syntax

Closes #61

See merge request !129
parents 3d0bc0af f49e04d5
No related branches found
No related tags found
1 merge request!129Parse version strings using the omnibus version syntax
Pipeline #
require_relative 'version'
 
class OmnibusGitLabVersion < Version
VERSION_REGEX = %r{
\A(?<major>\d+)
\.(?<minor>\d+)
(\.(?<patch>\d+))?
(\+)?
(?<rc>rc(?<rc_number>\d*))?
(\.)?
(?<edition>ce|ee)?
(\.\d+)?\z
}x
def ee?
edition == 'ee'
end
def edition
@edition ||= extract_from_version(:edition, fallback: 'ce')
end
def tag
str = "#{to_patch}+"
str << "rc#{rc}." if rc?
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@ class PatchIssue < BaseIssue
 
def initialize(version)
@version = version
@omnibus_version = OmnibusGitLabVersion.new(version)
@omnibus_version = OmnibusGitLabVersion.new(version.to_omnibus(ee: version.ee?))
end
 
def title
Loading
Loading
Loading
Loading
@@ -18,7 +18,7 @@ module Release
 
def after_execute_hook
Release::OmnibusGitLabRelease.new(
version,
version.to_omnibus(ee: version.ee?),
options.merge(gitlab_repo_path: repository.path)
).execute
end
Loading
Loading
Loading
Loading
@@ -67,7 +67,7 @@ class Version < String
end
 
def version?
self =~ VERSION_REGEX
self =~ self.class::VERSION_REGEX
end
 
def release?
Loading
Loading
@@ -147,7 +147,7 @@ class Version < String
end
 
def valid?
self =~ VERSION_REGEX
self =~ self.class::VERSION_REGEX
end
 
private
Loading
Loading
@@ -159,10 +159,9 @@ class Version < String
end
 
def extract_from_version(part, fallback: 0)
match_data = VERSION_REGEX.match(self)
if match_data && match_data.names.include?(part.to_s)
match_data[part]
match_data = self.class::VERSION_REGEX.match(self)
if match_data && match_data.names.include?(part.to_s) && match_data[part]
String.new(match_data[part])
else
fallback
end
Loading
Loading
Loading
Loading
@@ -9,9 +9,37 @@ describe OmnibusGitLabVersion do
 
describe '#tag' do
it { expect(version('1.2.3').tag).to eq('1.2.3+ce.0') }
it { expect(version('1.2.3-ee').tag).to eq('1.2.3+ee.0') }
it { expect(version('1.2.0-rc1').tag).to eq('1.2.0+rc1.ce.0') }
it { expect(version('1.2.0-rc2-ee').tag).to eq('1.2.0+rc2.ee.0') }
it { expect(version('1.2.3+ee').tag).to eq('1.2.3+ee.0') }
it { expect(version('1.2.0+rc1').tag).to eq('1.2.0+rc1.ce.0') }
it { expect(version('1.2.0+rc2.ee').tag).to eq('1.2.0+rc2.ee.0') }
it { expect(version('wow.1').tag).to eq('0.0.0+ce.0') }
end
describe '#edition' do
it 'returns ee when EE' do
expect(version('8.3.2+ee').edition).to eq('ee')
end
it 'returns ce when not EE' do
expect(version('8.3.2+ce').edition).to eq('ce')
end
it 'returns ce when not specified' do
expect(version('8.3.2').edition).to eq('ce')
end
end
describe '#ee?' do
it 'returns true when EE' do
expect(version('8.3.2+ee')).to be_ee
end
it 'returns false when not EE' do
expect(version('8.3.2+ce')).not_to be_ee
end
it 'returns false when not specified' do
expect(version('8.3.2')).not_to be_ee
end
end
end
Loading
Loading
@@ -50,7 +50,7 @@ describe PatchIssue do
 
describe '#labels' do
it 'returns a list of labels' do
issue = described_class.new('')
issue = described_class.new(Version.new(''))
 
expect(issue.labels).to eq 'Release'
end
Loading
Loading
Loading
Loading
@@ -6,7 +6,7 @@ require 'version'
describe SecurityPatchIssue do
describe '#confidential?' do
it 'is always confidential' do
issue = described_class.new('')
issue = described_class.new(Version.new(''))
 
expect(issue).to be_confidential
end
Loading
Loading
@@ -14,7 +14,7 @@ describe SecurityPatchIssue do
 
describe '#labels' do
it 'includes the "security" label' do
issue = described_class.new('')
issue = described_class.new(Version.new(''))
 
expect(issue.labels).to eq 'Release,security'
end
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment