2019-01-03 06:37:02 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module API
|
|
|
|
module Release
|
2020-10-14 20:08:42 -04:00
|
|
|
class Links < ::API::Base
|
2019-01-03 06:37:02 -05:00
|
|
|
include PaginationParams
|
|
|
|
|
2019-09-02 03:03:07 -04:00
|
|
|
RELEASE_ENDPOINT_REQUIREMENTS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS
|
2019-01-03 06:37:02 -05:00
|
|
|
.merge(tag_name: API::NO_SLASH_URL_PART_REGEX)
|
|
|
|
|
2019-02-08 11:11:37 -05:00
|
|
|
before { authorize! :read_release, user_project }
|
|
|
|
|
2020-10-30 14:08:56 -04:00
|
|
|
feature_category :release_orchestration
|
|
|
|
|
2019-01-03 06:37:02 -05:00
|
|
|
params do
|
|
|
|
requires :id, type: String, desc: 'The ID of a project'
|
|
|
|
end
|
|
|
|
resource 'projects/:id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
|
2019-01-04 01:29:04 -05:00
|
|
|
params do
|
|
|
|
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
|
|
|
|
end
|
2019-09-02 03:03:07 -04:00
|
|
|
resource 'releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do
|
2019-01-03 06:37:02 -05:00
|
|
|
resource :assets do
|
|
|
|
desc 'Get a list of links of a release' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.7.'
|
|
|
|
success Entities::Releases::Link
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
use :pagination
|
|
|
|
end
|
|
|
|
get 'links' do
|
|
|
|
authorize! :read_release, release
|
|
|
|
|
2019-01-04 01:29:04 -05:00
|
|
|
present paginate(release.links.sorted), with: Entities::Releases::Link
|
2019-01-03 06:37:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
desc 'Create a link of a release' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.7.'
|
|
|
|
success Entities::Releases::Link
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
requires :name, type: String, desc: 'The name of the link'
|
|
|
|
requires :url, type: String, desc: 'The URL of the link'
|
2020-02-27 10:09:24 -05:00
|
|
|
optional :filepath, type: String, desc: 'The filepath of the link'
|
2020-07-23 14:10:06 -04:00
|
|
|
optional :link_type, type: String, desc: 'The link type, one of: "runbook", "image", "package" or "other"'
|
2019-01-03 06:37:02 -05:00
|
|
|
end
|
|
|
|
post 'links' do
|
|
|
|
authorize! :create_release, release
|
|
|
|
|
|
|
|
new_link = release.links.create(declared_params(include_missing: false))
|
|
|
|
|
|
|
|
if new_link.persisted?
|
|
|
|
present new_link, with: Entities::Releases::Link
|
|
|
|
else
|
2019-01-04 01:29:04 -05:00
|
|
|
render_api_error!(new_link.errors.messages, 400)
|
2019-01-03 06:37:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
params do
|
2020-12-07 10:09:49 -05:00
|
|
|
requires :link_id, type: String, desc: 'The ID of the link'
|
2019-01-03 06:37:02 -05:00
|
|
|
end
|
2019-01-04 01:29:04 -05:00
|
|
|
resource 'links/:link_id' do
|
|
|
|
desc 'Get a link detail of a release' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.7.'
|
|
|
|
success Entities::Releases::Link
|
|
|
|
end
|
|
|
|
get do
|
|
|
|
authorize! :read_release, release
|
2019-01-03 06:37:02 -05:00
|
|
|
|
|
|
|
present link, with: Entities::Releases::Link
|
|
|
|
end
|
|
|
|
|
2019-01-04 01:29:04 -05:00
|
|
|
desc 'Update a link of a release' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.7.'
|
|
|
|
success Entities::Releases::Link
|
|
|
|
end
|
|
|
|
params do
|
|
|
|
optional :name, type: String, desc: 'The name of the link'
|
|
|
|
optional :url, type: String, desc: 'The URL of the link'
|
2020-02-27 10:09:24 -05:00
|
|
|
optional :filepath, type: String, desc: 'The filepath of the link'
|
2020-06-02 17:08:00 -04:00
|
|
|
optional :link_type, type: String, desc: 'The link type'
|
2019-01-04 01:29:04 -05:00
|
|
|
at_least_one_of :name, :url
|
|
|
|
end
|
|
|
|
put do
|
|
|
|
authorize! :update_release, release
|
|
|
|
|
|
|
|
if link.update(declared_params(include_missing: false))
|
|
|
|
present link, with: Entities::Releases::Link
|
|
|
|
else
|
|
|
|
render_api_error!(link.errors.messages, 400)
|
|
|
|
end
|
|
|
|
end
|
2019-01-03 06:37:02 -05:00
|
|
|
|
2019-01-04 01:29:04 -05:00
|
|
|
desc 'Delete a link of a release' do
|
|
|
|
detail 'This feature was introduced in GitLab 11.7.'
|
|
|
|
success Entities::Releases::Link
|
|
|
|
end
|
|
|
|
delete do
|
|
|
|
authorize! :destroy_release, release
|
|
|
|
|
|
|
|
if link.destroy
|
|
|
|
present link, with: Entities::Releases::Link
|
|
|
|
else
|
|
|
|
render_api_error!(link.errors.messages, 400)
|
|
|
|
end
|
2019-01-03 06:37:02 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
helpers do
|
|
|
|
def release
|
2019-01-04 01:29:04 -05:00
|
|
|
@release ||= user_project.releases.find_by_tag!(params[:tag])
|
2019-01-03 06:37:02 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def link
|
|
|
|
@link ||= release.links.find(params[:link_id])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|