diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-11-07 18:11:30 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-11-07 18:11:30 +0300 |
commit | 6d8810a64f944ff96af54e5c759f866bb68a7453 (patch) | |
tree | 8a7f19772e7f38c498cba6b73ca43b5e911705b3 /app | |
parent | f323d6148b7b71609cbd32ab9db4724fc108729d (diff) | |
parent | 28cbb2acfe413148ff23b8ed4b3293e09ab376f5 (diff) |
Merge branch 'fj-41213-api-update-submodule-commit' into 'master'
Add endpoint to update a git submodule reference
Closes #41213
See merge request gitlab-org/gitlab-ce!20949
Diffstat (limited to 'app')
-rw-r--r-- | app/models/repository.rb | 12 | ||||
-rw-r--r-- | app/services/submodules/update_service.rb | 38 |
2 files changed, 50 insertions, 0 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb index ee5579329a8..6e179f61a7b 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -1014,6 +1014,18 @@ class Repository message: merge_request.title) end + def update_submodule(user, submodule, commit_sha, message:, branch:) + with_cache_hooks do + raw.update_submodule( + user: user, + submodule: submodule, + commit_sha: commit_sha, + branch: branch, + message: message + ) + end + end + def blob_data_at(sha, path) blob = blob_at(sha, path) return unless blob diff --git a/app/services/submodules/update_service.rb b/app/services/submodules/update_service.rb new file mode 100644 index 00000000000..a6011a920bd --- /dev/null +++ b/app/services/submodules/update_service.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +module Submodules + class UpdateService < Commits::CreateService + include Gitlab::Utils::StrongMemoize + + def initialize(*args) + super + + @start_branch = @branch_name + @commit_sha = params[:commit_sha].presence + @submodule = params[:submodule].presence + @commit_message = params[:commit_message].presence || "Update submodule #{@submodule} with oid #{@commit_sha}" + end + + def validate! + super + + raise ValidationError, 'The repository is empty' if repository.empty? + end + + def execute + super + rescue StandardError => e + error(e.message) + end + + def create_commit! + repository.update_submodule(current_user, + @submodule, + @commit_sha, + message: @commit_message, + branch: @branch_name) + rescue ArgumentError, TypeError + raise ValidationError, 'Invalid parameters' + end + end +end |