debian-mirror-gitlab/lib/api/release/links.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

130 lines
4.6 KiB
Ruby
Raw Normal View History

2019-02-15 15:39:39 +05:30
# frozen_string_literal: true
module API
module Release
2021-01-03 14:25:43 +05:30
class Links < ::API::Base
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)
2019-03-13 22:55:13 +05:30
before { authorize! :read_release, user_project }
2021-01-29 00:20:46 +05:30
feature_category :release_orchestration
2022-07-16 23:28:13 +05:30
urgency :low
2021-01-29 00:20:46 +05:30
2019-02-15 15:39:39 +05:30
params do
requires :id, type: String, desc: 'The ID of a project'
end
resource 'projects/:id', requirements: API::NAMESPACE_OR_PROJECT_REQUIREMENTS do
params do
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
end
2019-12-04 20:38:33 +05:30
resource 'releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMENTS do
2019-02-15 15:39:39 +05:30
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
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
get 'links' do
authorize! :read_release, release
present paginate(release.links.sorted), with: Entities::Releases::Link
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-04-08 14:13:33 +05:30
optional :filepath, type: String, desc: 'The filepath of the link'
2020-10-24 23:57:45 +05:30
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
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
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
render_api_error!(new_link.errors.messages, 400)
end
end
params do
2021-02-22 17:27:13 +05:30
requires :link_id, type: String, desc: 'The ID of the link'
2019-02-15 15:39:39 +05:30
end
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
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
get do
authorize! :read_release, release
present link, with: Entities::Releases::Link
end
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-04-08 14:13:33 +05:30
optional :filepath, type: String, desc: 'The filepath of the link'
2020-06-23 00:09:42 +05:30
optional :link_type, type: String, desc: 'The link type'
2019-02-15 15:39:39 +05:30
at_least_one_of :name, :url
end
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
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
desc 'Delete a link of a release' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Releases::Link
end
2022-07-23 23:45:48 +05:30
route_setting :authentication, job_token_allowed: true
2019-02-15 15:39:39 +05:30
delete do
authorize! :destroy_release, release
if link.destroy
present link, with: Entities::Releases::Link
else
render_api_error!(link.errors.messages, 400)
end
end
end
end
end
end
helpers do
def release
@release ||= user_project.releases.find_by_tag!(params[:tag])
end
def link
@link ||= release.links.find(params[:link_id])
end
end
end
end
end