2020-07-28 23:09:34 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FactoryBot.define do
|
|
|
|
factory :go_module_version, class: 'Packages::Go::ModuleVersion' do
|
|
|
|
skip_create
|
|
|
|
|
|
|
|
initialize_with do
|
2022-06-21 17:19:12 +05:30
|
|
|
s = Packages::SemVer.parse(semver, prefixed: true)
|
|
|
|
raise ArgumentError, "invalid sematic version: #{semver.inspect}" if !s && semver
|
2020-07-28 23:09:34 +05:30
|
|
|
|
2022-06-21 17:19:12 +05:30
|
|
|
new(mod, type, commit, name: name, semver: s, ref: ref)
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
2021-04-17 20:07:23 +05:30
|
|
|
mod { association(:go_module) }
|
2020-07-28 23:09:34 +05:30
|
|
|
type { :commit }
|
|
|
|
commit { mod.project.repository.head_commit }
|
|
|
|
name { nil }
|
|
|
|
semver { nil }
|
|
|
|
ref { nil }
|
|
|
|
|
|
|
|
trait :tagged do
|
|
|
|
ref { mod.project.repository.find_tag(name) }
|
|
|
|
commit { ref.dereferenced_target }
|
|
|
|
name do
|
|
|
|
# This provides a sane default value, but in reality the caller should
|
|
|
|
# specify `name:`
|
|
|
|
|
|
|
|
# Find 'latest' semver tag (does not actually use semver precedence rules)
|
|
|
|
mod.project.repository.tags
|
|
|
|
.filter { |t| Packages::SemVer.match?(t.name, prefixed: true) }
|
|
|
|
.map { |t| Packages::SemVer.parse(t.name, prefixed: true) }
|
2021-04-17 20:07:23 +05:30
|
|
|
.max_by(&:to_s)
|
2020-07-28 23:09:34 +05:30
|
|
|
.to_s
|
|
|
|
end
|
2022-06-21 17:19:12 +05:30
|
|
|
type { :ref }
|
|
|
|
semver { name }
|
2020-07-28 23:09:34 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|