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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
fbd0f162
Commit
fbd0f162
authored
Jul 30, 2018
by
Peter Leitzen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Let Commits::TagService return a result hash
parent
9c6fc59c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
13 deletions
+30
-13
app/services/commits/tag_service.rb
app/services/commits/tag_service.rb
+7
-3
spec/services/commits/tag_service_spec.rb
spec/services/commits/tag_service_spec.rb
+23
-10
No files found.
app/services/commits/tag_service.rb
View file @
fbd0f162
...
...
@@ -3,7 +3,9 @@
module
Commits
class
TagService
<
BaseService
def
execute
(
commit
)
return
unless
params
[
:tag_name
]
unless
params
[
:tag_name
]
return
error
(
'Missing parameter tag_name'
)
end
tag_name
=
params
[
:tag_name
]
message
=
params
[
:tag_message
]
...
...
@@ -13,10 +15,12 @@ module Commits
.
new
(
commit
.
project
,
current_user
)
.
execute
(
tag_name
,
commit
.
sha
,
message
,
release_description
)
if
result
[
:status
]
==
:success
&&
(
tag
=
result
[
:tag
])
if
result
[
:status
]
==
:success
tag
=
result
[
:tag
]
SystemNoteService
.
tag_commit
(
commit
,
commit
.
project
,
current_user
,
tag
.
name
)
commit
end
result
end
end
end
spec/services/commits/tag_service_spec.rb
View file @
fbd0f162
...
...
@@ -13,11 +13,12 @@ describe Commits::TagService do
describe
'#execute'
do
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
opts
)
}
shared_examples
'tag
ging fails
'
do
it
'returns
nil
'
do
tagged_commi
t
=
service
.
execute
(
commit
)
shared_examples
'tag
failure
'
do
it
'returns
a hash with the :error status
'
do
resul
t
=
service
.
execute
(
commit
)
expect
(
tagged_commit
).
to
be_nil
expect
(
result
[
:status
]).
to
eq
(
:error
)
expect
(
result
[
:message
]).
to
eq
(
error_message
)
end
it
'does not add a system note'
do
...
...
@@ -51,10 +52,14 @@ describe Commits::TagService do
end
context
'when tagging succeeds'
do
it
'returns
the commit
'
do
tagged_commi
t
=
service
.
execute
(
commit
)
it
'returns
a hash with the :success status and created tag
'
do
resul
t
=
service
.
execute
(
commit
)
expect
(
tagged_commit
).
to
eq
(
commit
)
expect
(
result
[
:status
]).
to
eq
(
:success
)
tag
=
result
[
:tag
]
expect
(
tag
.
name
).
to
eq
(
opts
[
:tag_name
])
expect
(
tag
.
message
).
to
eq
(
opts
[
:tag_message
])
end
it
'adds a system note'
do
...
...
@@ -66,13 +71,19 @@ describe Commits::TagService do
end
context
'when tagging fails'
do
let
(
:tag_error
)
{
'GitLab: You are not allowed to push code to this project.'
}
before
do
tag_stub
=
instance_double
(
Tags
::
CreateService
)
allow
(
Tags
::
CreateService
).
to
receive
(
:new
).
and_return
(
tag_stub
)
allow
(
tag_stub
).
to
receive
(
:execute
).
and_return
({
status: :error
})
allow
(
tag_stub
).
to
receive
(
:execute
).
and_return
({
status: :error
,
message:
tag_error
})
end
include_examples
'tagging fails'
it_behaves_like
'tag failure'
do
let
(
:error_message
)
{
tag_error
}
end
end
end
...
...
@@ -81,7 +92,9 @@ describe Commits::TagService do
{}
end
include_examples
'tagging fails'
it_behaves_like
'tag failure'
do
let
(
:error_message
)
{
'Missing parameter tag_name'
}
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