Commit 04a3d27e authored by Robert Schilling's avatar Robert Schilling

Allow editing a release in API via PUT method

parent 3ea05c5b
...@@ -10,7 +10,7 @@ class CreateReleaseService < BaseService ...@@ -10,7 +10,7 @@ class CreateReleaseService < BaseService
if existing_tag if existing_tag
release = project.releases.find_by(tag: tag_name) release = project.releases.find_by(tag: tag_name)
if(release) if release
error('Release already exists', 409) error('Release already exists', 409)
else else
release = project.releases.new({ tag: tag_name, description: release_description }) release = project.releases.new({ tag: tag_name, description: release_description })
......
require_relative 'base_service'
class UpdateReleaseService < BaseService
def execute(tag_name, release_description)
repository = project.repository
existing_tag = repository.find_tag(tag_name)
if existing_tag
release = project.releases.find_by(tag: tag_name)
if release
release.update_attributes(description: release_description)
success(release)
else
error('Release does not exist', 404)
end
else
error('Tag does not exist', 404)
end
end
def success(release)
out = super()
out[:release] = release
out
end
end
...@@ -106,3 +106,26 @@ Parameters: ...@@ -106,3 +106,26 @@ Parameters:
"description": "Amazing release. Wow" "description": "Amazing release. Wow"
} }
``` ```
## Update a release
Updates the release notes of a given release. It returns 200 if the release is
successfully updated. If the tag or the release does not exist, it returns 404
with a proper error message.
```
PUT /projects/:id/repository/tags/:tag_name/release
```
Parameters:
- `id` (required) - The ID of a project
- `tag_name` (required) - The name of a tag
- `description` (required) - Release notes with markdown support
```json
{
"tag_name": "1.0.0",
"description": "Amazing release. Wow"
}
```
\ No newline at end of file
...@@ -60,6 +60,27 @@ module API ...@@ -60,6 +60,27 @@ module API
render_api_error!(result[:message], result[:http_status]) render_api_error!(result[:message], result[:http_status])
end end
end end
# Updates a release notes of a tag
#
# Parameters:
# id (required) - The ID of a project
# tag_name (required) - The name of the tag
# description (required) - Release notes with markdown support
# Example Request:
# PUT /projects/:id/repository/tags/:tag_name/release
put ':id/repository/tags/:tag_name/release', requirements: { tag_name: /.*/ } do
authorize_push_project
required_attributes! [:description]
result = UpdateReleaseService.new(user_project, current_user).
execute(params[:tag_name], params[:description])
if result[:status] == :success
present result[:release], with: Entities::Release
else
render_api_error!(result[:message], result[:http_status])
end
end
end end
end end
end end
...@@ -155,4 +155,42 @@ describe API::API, api: true do ...@@ -155,4 +155,42 @@ describe API::API, api: true do
end end
end end
end end
describe 'PUT id/repository/tags/:tag_name/release' do
let(:tag_name) { project.repository.tag_names.first }
let(:description) { 'Awesome release!' }
let(:new_description) { 'The best release!' }
context 'on tag with existing release' do
before do
release = project.releases.find_or_initialize_by(tag: tag_name)
release.update_attributes(description: description)
end
it 'should update the release description' do
put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: new_description
expect(response.status).to eq(200)
expect(json_response['tag_name']).to eq(tag_name)
expect(json_response['description']).to eq(new_description)
end
end
it 'should return 404 if the tag does not exist' do
put api("/projects/#{project.id}/repository/tags/foobar/release", user),
description: new_description
expect(response.status).to eq(404)
expect(json_response['message']).to eq('Tag does not exist')
end
it 'should return 404 if the release does not exist' do
put api("/projects/#{project.id}/repository/tags/#{tag_name}/release", user),
description: new_description
expect(response.status).to eq(404)
expect(json_response['message']).to eq('Release does not exist')
end
end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment