1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
# frozen_string_literal: true
module API
class Releases < Grape::API
include PaginationParams
RELEASE_ENDPOINT_REQUIREMETS = API::NAMESPACE_OR_PROJECT_REQUIREMENTS.merge(tag_name: API::NO_SLASH_URL_PART_REGEX)
before { error!('404 Not Found', 404) unless Feature.enabled?(:releases_page, user_project) }
before { authorize_read_release! }
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
present paginate(releases), with: Entities::Release
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'
end
get ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do
release = user_project.releases.find_by_tag(params[:tag_name])
not_found!('Release') unless release
present release, with: Entities::Release
end
desc 'Create a new release' do
detail 'This feature was introduced in GitLab 11.7.'
success Entities::Release
end
params do
requires :name, type: String, desc: 'The name of the release'
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
requires :description, type: String, desc: 'The release notes'
optional :ref, type: String, desc: 'The commit sha or branch name'
end
post ':id/releases' do
authorize_create_release!
attributes = declared(params)
ref = attributes.delete(:ref)
attributes.delete(:id)
result = ::CreateReleaseService.new(user_project, current_user, attributes)
.execute(ref)
if result[:status] == :success
present result[:release], with: Entities::Release
else
render_api_error!(result[:message], 400)
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
requires :name, type: String, desc: 'The name of the release'
requires :description, type: String, desc: 'Release notes with markdown support'
end
put ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do
authorize_update_release!
attributes = declared(params)
attributes.delete(:id)
result = UpdateReleaseService.new(user_project, current_user, attributes).execute
if result[:status] == :success
present result[:release], with: Entities::Release
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
requires :tag_name, type: String, desc: 'The name of the tag', as: :tag
end
delete ':id/releases/:tag_name', requirements: RELEASE_ENDPOINT_REQUIREMETS do
authorize_update_release!
attributes = declared(params)
attributes.delete(:id)
result = DeleteReleaseService.new(user_project, current_user, attributes).execute
if result[:status] == :success
present result[:release], with: Entities::Release
else
render_api_error!(result[:message], result[:http_status])
end
end
end
end
end
|