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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
3ea05c5b
Commit
3ea05c5b
authored
Nov 21, 2015
by
Robert Schilling
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Only allow to create a release if it does not exist yet
parent
6f7e90f6
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
30 additions
and
8 deletions
+30
-8
app/services/create_release_service.rb
app/services/create_release_service.rb
+10
-4
doc/api/tags.md
doc/api/tags.md
+2
-1
lib/api/tags.rb
lib/api/tags.rb
+2
-2
spec/requests/api/tags_spec.rb
spec/requests/api/tags_spec.rb
+16
-1
No files found.
app/services/create_release_service.rb
View file @
3ea05c5b
...
...
@@ -8,12 +8,18 @@ class CreateReleaseService < BaseService
# 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
)
release
=
project
.
releases
.
find_by
(
tag:
tag_name
)
if
(
release
)
error
(
'Release already exists'
,
409
)
else
release
=
project
.
releases
.
new
({
tag:
tag_name
,
description:
release_description
})
release
.
save
success
(
release
)
end
else
error
(
'Tag does not exist'
)
error
(
'Tag does not exist'
,
404
)
end
end
...
...
doc/api/tags.md
View file @
3ea05c5b
...
...
@@ -87,7 +87,8 @@ It returns 200 if the operation succeed. In case of an error,
## Create a new release
Add release notes to the existing git tag. It returns 201 if the release is
created successfully. If the tag does not exist, 404 is returned.
created successfully. If the tag does not exist, 404 is returned. If there
already exists a release for the given tag, 409 is returned.
```
POST /projects/:id/repository/tags/:tag_name/release
...
...
lib/api/tags.rb
View file @
3ea05c5b
...
...
@@ -47,7 +47,7 @@ module API
# tag_name (required) - The name of the tag
# description (required) - Release notes with markdown support
# Example Request:
# P
U
T /projects/:id/repository/tags/:tag_name/release
# P
OS
T /projects/:id/repository/tags/:tag_name/release
post
':id/repository/tags/:tag_name/release'
,
requirements:
{
tag_name:
/.*/
}
do
authorize_push_project
required_attributes!
[
:description
]
...
...
@@ -57,7 +57,7 @@ module API
if
result
[
:status
]
==
:success
present
result
[
:release
],
with:
Entities
::
Release
else
render_api_error!
(
result
[
:message
],
404
)
render_api_error!
(
result
[
:message
],
result
[
:http_status
]
)
end
end
end
...
...
spec/requests/api/tags_spec.rb
View file @
3ea05c5b
...
...
@@ -28,10 +28,10 @@ describe API::API, api: true do
before
do
release
=
project
.
releases
.
find_or_initialize_by
(
tag:
tag_name
)
release
.
update_attributes
(
description:
description
)
get
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
)
end
it
"should return an array of project tags with release info"
do
get
api
(
"/projects/
#{
project
.
id
}
/repository/tags"
,
user
)
expect
(
response
.
status
).
to
eq
(
200
)
expect
(
json_response
).
to
be_an
Array
expect
(
json_response
.
first
[
'name'
]).
to
eq
(
tag_name
)
...
...
@@ -139,5 +139,20 @@ describe API::API, api: true do
expect
(
response
.
status
).
to
eq
(
404
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Tag does not exist'
)
end
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 return 409 if there is already a release'
do
post
api
(
"/projects/
#{
project
.
id
}
/repository/tags/
#{
tag_name
}
/release"
,
user
),
description:
description
expect
(
response
.
status
).
to
eq
(
409
)
expect
(
json_response
[
'message'
]).
to
eq
(
'Release already exists'
)
end
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