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
2942221e
Commit
2942221e
authored
Mar 08, 2022
by
Alishan Ladhani
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor Deployments::ApprovalService interface
- Pass params to constructor
parent
4c3e65b0
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
23 additions
and
14 deletions
+23
-14
ee/app/services/deployments/approval_service.rb
ee/app/services/deployments/approval_service.rb
+2
-2
ee/lib/ee/api/deployments.rb
ee/lib/ee/api/deployments.rb
+2
-2
ee/spec/services/deployments/approval_service_spec.rb
ee/spec/services/deployments/approval_service_spec.rb
+19
-10
No files found.
ee/app/services/deployments/approval_service.rb
View file @
2942221e
...
...
@@ -2,11 +2,11 @@
module
Deployments
class
ApprovalService
<
::
BaseService
def
execute
(
deployment
:,
status
:,
comment:
nil
)
def
execute
(
deployment
,
status
)
error_message
=
validate
(
deployment
,
status
)
return
error
(
error_message
)
if
error_message
approval
=
upsert_approval
(
deployment
,
status
,
comment
)
approval
=
upsert_approval
(
deployment
,
status
,
params
[
:comment
]
)
return
error
(
approval
.
errors
.
full_messages
)
if
approval
.
errors
.
any?
process_build!
(
deployment
,
approval
)
...
...
ee/lib/ee/api/deployments.rb
View file @
2942221e
...
...
@@ -22,8 +22,8 @@ module EE
post
':id/deployments/:deployment_id/approval'
do
deployment
=
user_project
.
deployments
.
find
(
params
[
:deployment_id
])
result
=
::
Deployments
::
ApprovalService
.
new
(
user_project
,
current_user
)
.
execute
(
deployment
:
deployment
,
status:
params
[
:status
],
comment:
params
[
:comment
])
result
=
::
Deployments
::
ApprovalService
.
new
(
user_project
,
current_user
,
declared_params
(
include_missing:
false
)
)
.
execute
(
deployment
,
params
[
:status
])
if
result
[
:status
]
==
:success
present
(
result
[
:approval
],
with:
::
API
::
Entities
::
Deployments
::
Approval
,
current_user:
current_user
)
...
...
ee/spec/services/deployments/approval_service_spec.rb
View file @
2942221e
...
...
@@ -5,7 +5,8 @@ require 'spec_helper'
RSpec
.
describe
Deployments
::
ApprovalService
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
)
}
let
(
:service
)
{
described_class
.
new
(
project
,
user
,
params
)
}
let
(
:params
)
{
{
comment:
comment
}
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
let
(
:status
)
{
'approved'
}
...
...
@@ -28,7 +29,7 @@ RSpec.describe Deployments::ApprovalService do
end
shared_examples_for
'reject'
do
it
'rejects the deployment'
do
it
'rejects the deployment'
,
:aggregate_failures
do
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:approval
].
status
).
to
eq
(
'rejected'
)
expect
(
subject
[
:approval
].
user
).
to
eq
(
user
)
...
...
@@ -39,7 +40,7 @@ RSpec.describe Deployments::ApprovalService do
end
shared_examples_for
'approve'
do
it
'approves the deployment'
do
it
'approves the deployment'
,
:aggregate_failures
do
expect
(
subject
[
:status
]).
to
eq
(
:success
)
expect
(
subject
[
:approval
].
status
).
to
eq
(
'approved'
)
expect
(
subject
[
:approval
].
user
).
to
eq
(
user
)
...
...
@@ -61,7 +62,7 @@ RSpec.describe Deployments::ApprovalService do
end
describe
'#execute'
do
subject
{
service
.
execute
(
deployment
:
deployment
,
status:
status
,
comment:
comment
)
}
subject
{
service
.
execute
(
deployment
,
status
)
}
context
'when status is approved'
do
include_examples
'approve'
...
...
@@ -76,17 +77,21 @@ RSpec.describe Deployments::ApprovalService do
end
context
'when user already approved'
do
let
(
:comment
)
{
'
Changed
comment'
}
let
(
:comment
)
{
'
Original
comment'
}
before
do
service
.
execute
(
deployment
:
deployment
,
status: :approved
,
comment:
'Original comment'
)
service
.
execute
(
deployment
,
:approved
)
end
context
'and is approving again'
do
include_examples
'approve'
context
'with a different comment'
do
it
'does not change the comment'
do
expect
(
subject
[
:approval
].
comment
).
to
eq
(
'Original comment'
)
service
=
described_class
.
new
(
project
,
user
,
params
.
merge
(
comment:
'Changed comment'
))
expect
(
service
.
execute
(
deployment
,
status
)[
:approval
].
comment
).
to
eq
(
'Original comment'
)
end
end
end
...
...
@@ -95,8 +100,12 @@ RSpec.describe Deployments::ApprovalService do
include_examples
'reject'
it
'saves the changed comment'
do
expect
(
subject
[
:approval
].
comment
).
to
eq
(
'Changed comment'
)
context
'with a different comment'
do
it
'changes the comment'
do
service
=
described_class
.
new
(
project
,
user
,
params
.
merge
(
comment:
'Changed comment'
))
expect
(
service
.
execute
(
deployment
,
status
)[
:approval
].
comment
).
to
eq
(
'Changed comment'
)
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