2020-07-08 08:09:33 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
FactoryBot.define do
|
|
|
|
factory :go_module_version, class: 'Packages::Go::ModuleVersion' do
|
|
|
|
skip_create
|
|
|
|
|
|
|
|
initialize_with do
|
2022-04-01 11:08:40 -04:00
|
|
|
s = Packages::SemVer.parse(semver, prefixed: true)
|
|
|
|
raise ArgumentError, "invalid sematic version: #{semver.inspect}" if !s && semver
|
2020-07-08 08:09:33 -04:00
|
|
|
|
2022-04-01 11:08:40 -04:00
|
|
|
new(mod, type, commit, name: name, semver: s, ref: ref)
|
2020-07-08 08:09:33 -04:00
|
|
|
end
|
|
|
|
|
2021-03-08 13:09:12 -05:00
|
|
|
mod { association(:go_module) }
|
2020-07-08 08:09:33 -04:00
|
|
|
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-03-08 13:09:12 -05:00
|
|
|
.max_by(&:to_s)
|
2020-07-08 08:09:33 -04:00
|
|
|
.to_s
|
|
|
|
end
|
2022-04-01 11:08:40 -04:00
|
|
|
type { :ref }
|
|
|
|
semver { name }
|
2020-07-08 08:09:33 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|