debian-mirror-gitlab/lib/api/releases.rb

178 lines
6.2 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module API
2020-07-28 23:09:34 +05:30
class Releases < Grape::API::Instance
2019-02-15 15:39:39 +05:30
include PaginationParams
2019-12-04 20:38:33 +05:30
RELEASE_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS
2019-02-15 15:39:39 +05:30
.merge(tag_name: API::NO_SLASH_URL_PART_REGEX)
before { authorize_read_releases! }
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource :projects, requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
desc 'Get a project releases' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Release
end
params do
use :pagination
end
get ':id/releases' do
releases = ::ReleasesFinder.new(user_project, current_user).execute
2019-07-31 22:56:46 +05:30
present paginate(releases), with: Entities::Release, current_user: current_user
2019-02-15 15:39:39 +05:30
end
desc 'Get a single project release' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Release
end
params do
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
end
2019-12-04 20:38:33 +05:30
get ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do
2019-07-31 22:56:46 +05:30
authorize_download_code!
2019-02-15 15:39:39 +05:30
2019-07-31 22:56:46 +05:30
present release, with: Entities::Release, current_user: current_user
2019-02-15 15:39:39 +05:30
end
desc 'Create a new release' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Release
end
params do
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
2019-12-26 22:10:19 +05:30
optional :name, type: String, desc: 'The name of the release'
2020-04-08 14:13:33 +05:30
optional :description, type: String, desc: 'The release notes'
2019-02-15 15:39:39 +05:30
optional :ref, type: String, desc: 'The commit sha or branch name'
optional :assets, type: Hash do
optional :links, type: Array do
2020-10-24 23:57:45 +05:30
requires :name, type: String, desc: 'The name of the link'
requires :url, type: String, desc: 'The URL of the link'
optional :filepath, type: String, desc: 'The filepath of the link'
optional :link_type, type: String, desc: 'The link type, one of: "runbook", "image", "package" or "other"'
2019-02-15 15:39:39 +05:30
end
end
2020-07-28 23:09:34 +05:30
optional :milestones, type: Array[String], coerce_with: ::API::Validations::Types::CommaSeparatedToArray.coerce, desc: 'The titles of the related milestones', default: []
2019-09-30 21:07:59 +05:30
optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready. Defaults to the current time.'
2019-02-15 15:39:39 +05:30
end
2020-01-01 13:55:28 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
post ':id/releases' do
authorize_create_release!
result = ::Releases::CreateService
.new(user_project, current_user, declared_params(include_missing: false))
.execute
if result[:status] == :success
2020-03-13 15:44:24 +05:30
log_release_created_audit_event(result[:release])
2019-07-31 22:56:46 +05:30
present result[:release], with: Entities::Release, current_user: current_user
2019-02-15 15:39:39 +05:30
else
render_api_error!(result[:message], result[:http_status])
end
end
desc 'Update a release' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Release
end
params do
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
optional :name, type: String, desc: 'The name of the release'
optional :description, type: String, desc: 'Release notes with markdown support'
2019-09-30 21:07:59 +05:30
optional :released_at, type: DateTime, desc: 'The date when the release will be/was ready.'
2019-12-04 20:38:33 +05:30
optional :milestones, type: Array, desc: 'The titles of the related milestones'
2019-02-15 15:39:39 +05:30
end
2019-12-04 20:38:33 +05:30
put ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do
2019-02-15 15:39:39 +05:30
authorize_update_release!
result = ::Releases::UpdateService
.new(user_project, current_user, declared_params(include_missing: false))
.execute
if result[:status] == :success
2020-03-13 15:44:24 +05:30
log_release_updated_audit_event
log_release_milestones_updated_audit_event if result[:milestones_updated]
2019-07-31 22:56:46 +05:30
present result[:release], with: Entities::Release, current_user: current_user
2019-02-15 15:39:39 +05:30
else
render_api_error!(result[:message], result[:http_status])
end
end
desc 'Delete a release' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Release
end
params do
2019-03-02 22:35:43 +05:30
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
2019-02-15 15:39:39 +05:30
end
2019-12-04 20:38:33 +05:30
delete ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do
2019-02-15 15:39:39 +05:30
authorize_destroy_release!
result = ::Releases::DestroyService
.new(user_project, current_user, declared_params(include_missing: false))
.execute
if result[:status] == :success
2019-07-31 22:56:46 +05:30
present result[:release], with: Entities::Release, current_user: current_user
2019-02-15 15:39:39 +05:30
else
render_api_error!(result[:message], result[:http_status])
end
end
end
helpers do
def authorize_create_release!
authorize! :create_release, user_project
end
def authorize_read_releases!
authorize! :read_release, user_project
end
def authorize_read_release!
authorize! :read_release, release
end
def authorize_update_release!
authorize! :update_release, release
end
def authorize_destroy_release!
authorize! :destroy_release, release
end
2019-07-31 22:56:46 +05:30
def authorize_download_code!
authorize! :download_code, release
end
2020-04-22 19:07:51 +05:30
def authorize_create_evidence!
# This is a separate method so that EE can extend its behaviour
end
2019-02-15 15:39:39 +05:30
def release
@release ||= user_project.releases.find_by_tag(params[:tag])
end
2020-03-13 15:44:24 +05:30
def log_release_created_audit_event(release)
# This is a separate method so that EE can extend its behaviour
end
def log_release_updated_audit_event
# This is a separate method so that EE can extend its behaviour
end
def log_release_milestones_updated_audit_event
# This is a separate method so that EE can extend its behaviour
end
2019-02-15 15:39:39 +05:30
end
end
end
2020-03-13 15:44:24 +05:30
API::Releases.prepend_if_ee('EE::API::Releases')