diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2018-11-07 15:11:30 +0000 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2018-11-07 15:11:30 +0000 |
commit | 6d8810a64f944ff96af54e5c759f866bb68a7453 (patch) | |
tree | 8a7f19772e7f38c498cba6b73ca43b5e911705b3 /lib/api | |
parent | f323d6148b7b71609cbd32ab9db4724fc108729d (diff) | |
parent | 28cbb2acfe413148ff23b8ed4b3293e09ab376f5 (diff) | |
download | gitlab-ce-6d8810a64f944ff96af54e5c759f866bb68a7453.tar.gz |
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 'lib/api')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/submodules.rb | 47 |
2 files changed, 48 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index c49c52213bf..8e259961828 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -143,6 +143,7 @@ module API mount ::API::Settings mount ::API::SidekiqMetrics mount ::API::Snippets + mount ::API::Submodules mount ::API::Subscriptions mount ::API::SystemHooks mount ::API::Tags diff --git a/lib/api/submodules.rb b/lib/api/submodules.rb new file mode 100644 index 00000000000..72d7d994102 --- /dev/null +++ b/lib/api/submodules.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +module API + class Submodules < Grape::API + before { authenticate! } + + helpers do + def commit_params(attrs) + { + submodule: attrs[:submodule], + commit_sha: attrs[:commit_sha], + branch_name: attrs[:branch], + commit_message: attrs[:commit_message] + } + end + end + + params do + requires :id, type: String, desc: 'The project ID' + end + resource :projects, requirements: Files::FILE_ENDPOINT_REQUIREMENTS do + desc 'Update existing submodule reference in repository' do + success Entities::Commit + end + params do + requires :submodule, type: String, desc: 'Url encoded full path to submodule.' + requires :commit_sha, type: String, desc: 'Commit sha to update the submodule to.' + requires :branch, type: String, desc: 'Name of the branch to commit into.' + optional :commit_message, type: String, desc: 'Commit message. If no message is provided a default one will be set.' + end + put ":id/repository/submodules/:submodule", requirements: Files::FILE_ENDPOINT_REQUIREMENTS do + authorize! :push_code, user_project + + submodule_params = declared_params(include_missing: false) + + result = ::Submodules::UpdateService.new(user_project, current_user, commit_params(submodule_params)).execute + + if result[:status] == :success + commit_detail = user_project.repository.commit(result[:result]) + present commit_detail, with: Entities::CommitDetail + else + render_api_error!(result[:message], result[:http_status] || 400) + end + end + end + end +end |