diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-29 21:12:41 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-29 21:12:41 +0300 |
commit | 2d239d2421eea466ff5c51aebdbf05a18ded20c7 (patch) | |
tree | 85f9c0b6063158ff01112b9945f57bc35bd47970 /app/services/ml | |
parent | 762918f04a2ee8f4f7fac3d551c14af8dd30f17c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/ml')
-rw-r--r-- | app/services/ml/create_model_version_service.rb | 25 | ||||
-rw-r--r-- | app/services/ml/increment_version_service.rb | 35 |
2 files changed, 60 insertions, 0 deletions
diff --git a/app/services/ml/create_model_version_service.rb b/app/services/ml/create_model_version_service.rb new file mode 100644 index 00000000000..ff27e78221f --- /dev/null +++ b/app/services/ml/create_model_version_service.rb @@ -0,0 +1,25 @@ +# frozen_string_literal: true + +module Ml + class CreateModelVersionService + def initialize(model, params = {}) + @model = model + @version = params[:version] + @package = params[:package] + @description = params[:description] + end + + def execute + @version ||= Ml::IncrementVersionService.new(@model.latest_version.try(:version)).execute + + model_version = Ml::ModelVersion.find_or_create!(@model, @version, @package, @description) + + model_version.candidate = ::Ml::CreateCandidateService.new( + @model.default_experiment, + { model_version: model_version } + ).execute + + model_version + end + end +end diff --git a/app/services/ml/increment_version_service.rb b/app/services/ml/increment_version_service.rb new file mode 100644 index 00000000000..ef3cbf5269b --- /dev/null +++ b/app/services/ml/increment_version_service.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Ml + INITIAL_VERSION = '1.0.0' + ALLOWED_INCREMENT_TYPES = [:patch, :minor, :major].freeze + + class IncrementVersionService + def initialize(version, increment_type = nil) + @version = version + @increment_type = increment_type || :major + @parsed_version = Packages::SemVer.parse(@version.to_s) + + raise "Version must be in a valid SemVer format" unless @parsed_version || @version.nil? + + return if ALLOWED_INCREMENT_TYPES.include?(@increment_type) + + raise "Increment type must be one of :patch, :minor, or :major" + end + + def execute + return INITIAL_VERSION if @version.nil? + + case @increment_type + when :patch + @parsed_version.patch += 1 + when :minor + @parsed_version.minor += 1 + when :major + @parsed_version.major += 1 + end + + @parsed_version.to_s + end + end +end |