Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
iv
gitlab-ce
Commits
faef95af
Commit
faef95af
authored
Nov 21, 2015
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
API: Return 404 if the tag for a release does not exist
parent
2cba93a0
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
9 deletions
+47
-9
app/services/create_release_service.rb
app/services/create_release_service.rb
+25
-0
app/services/create_tag_service.rb
app/services/create_tag_service.rb
+5
-5
doc/api/tags.md
doc/api/tags.md
+2
-1
lib/api/tags.rb
lib/api/tags.rb
+7
-3
spec/requests/api/tags_spec.rb
spec/requests/api/tags_spec.rb
+8
-0
No files found.
app/services/create_release_service.rb
0 → 100644
View file @
faef95af
require_relative
'base_service'
class
CreateReleaseService
<
BaseService
def
execute
(
tag_name
,
release_description
)
repository
=
project
.
repository
existing_tag
=
repository
.
find_tag
(
tag_name
)
# Only create a release if the tag exists
if
existing_tag
release
=
project
.
releases
.
find_or_initialize_by
(
tag:
tag_name
)
release
.
update_attributes
(
description:
release_description
)
success
(
release
)
else
error
(
'Tag does not exist'
)
end
end
def
success
(
release
)
out
=
super
()
out
[
:release
]
=
release
out
end
end
app/services/create_tag_service.rb
View file @
faef95af
...
...
@@ -19,16 +19,16 @@ class CreateTagService < BaseService
new_tag
=
repository
.
find_tag
(
tag_name
)
if
new_tag
if
release_description
release
=
project
.
releases
.
find_or_initialize_by
(
tag:
tag_name
)
release
.
update_attributes
(
description:
release_description
)
end
push_data
=
create_push_data
(
project
,
current_user
,
new_tag
)
EventCreateService
.
new
.
push
(
project
,
current_user
,
push_data
)
project
.
execute_hooks
(
push_data
.
dup
,
:tag_push_hooks
)
project
.
execute_services
(
push_data
.
dup
,
:tag_push_hooks
)
if
release_description
CreateReleaseService
.
new
(
@project
,
@current_user
).
execute
(
tag_name
,
release_description
)
end
success
(
new_tag
)
else
error
(
'Invalid reference name'
)
...
...
doc/api/tags.md
View file @
faef95af
...
...
@@ -86,7 +86,8 @@ It returns 200 if the operation succeed. In case of an error,
## New release
Add release notes to the existing git tag
Add release notes to the existing git tag. It returns 200 if the release is
created successfully. If the tag does not exist, 404 is returned.
```
PUT /projects/:id/repository/tags/:tag_name/release
...
...
lib/api/tags.rb
View file @
faef95af
...
...
@@ -51,10 +51,14 @@ module API
put
':id/repository/tags/:tag_name/release'
,
requirements:
{
tag_name:
/.*/
}
do
authorize_push_project
required_attributes!
[
:description
]
re
lease
=
user_project
.
releases
.
find_or_initialize_by
(
tag:
params
[
:tag_name
])
release
.
update_attributes
(
description:
params
[
:description
])
re
sult
=
CreateReleaseService
.
new
(
user_project
,
current_user
).
execute
(
params
[
:tag_name
],
params
[
:description
])
present
release
,
with:
Entities
::
Release
if
result
[
:status
]
==
:success
present
result
[
:release
],
with:
Entities
::
Release
else
render_api_error!
(
result
[
:message
],
404
)
end
end
end
end
...
...
spec/requests/api/tags_spec.rb
View file @
faef95af
...
...
@@ -131,5 +131,13 @@ describe API::API, api: true do
expect
(
json_response
[
'tag_name'
]).
to
eq
(
tag_name
)
expect
(
json_response
[
'description'
]).
to
eq
(
description
)
end
it
'should return 404 if the tag does not exist'
do
put
api
(
"/projects/
#{
project
.
id
}
/repository/tags/foobar/release"
,
user
),
description:
description
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Tag does not exist'
)
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment