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
838bd54a
Commit
838bd54a
authored
Aug 20, 2020
by
lauraMon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds better error handling and refactors specs
* Applies suggestions * Fixes rubocop formatting
parent
a5953474
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
34 additions
and
12 deletions
+34
-12
app/graphql/mutations/ci/base.rb
app/graphql/mutations/ci/base.rb
+0
-1
app/graphql/mutations/ci/pipeline_cancel.rb
app/graphql/mutations/ci/pipeline_cancel.rb
+2
-3
app/graphql/mutations/ci/pipeline_destroy.rb
app/graphql/mutations/ci/pipeline_destroy.rb
+2
-2
app/graphql/mutations/ci/pipeline_retry.rb
app/graphql/mutations/ci/pipeline_retry.rb
+0
-1
app/services/ci/cancel_user_pipelines_service.rb
app/services/ci/cancel_user_pipelines_service.rb
+2
-0
spec/requests/api/graphql/mutations/ci/pipeline_cancel_spec.rb
...requests/api/graphql/mutations/ci/pipeline_cancel_spec.rb
+13
-2
spec/requests/api/graphql/mutations/ci/pipeline_destroy_spec.rb
...equests/api/graphql/mutations/ci/pipeline_destroy_spec.rb
+1
-1
spec/requests/api/graphql/mutations/ci/pipeline_retry_spec.rb
.../requests/api/graphql/mutations/ci/pipeline_retry_spec.rb
+2
-2
spec/services/ci/cancel_user_pipelines_service_spec.rb
spec/services/ci/cancel_user_pipelines_service_spec.rb
+12
-0
No files found.
app/graphql/mutations/ci/base.rb
View file @
838bd54a
...
...
@@ -3,7 +3,6 @@
module
Mutations
module
Ci
class
Base
<
BaseMutation
argument
:id
,
GraphQL
::
ID_TYPE
,
required:
true
,
description:
'The id of the pipeline to mutate'
...
...
app/graphql/mutations/ci/pipeline_cancel.rb
View file @
838bd54a
...
...
@@ -8,13 +8,12 @@ module Mutations
authorize
:update_pipeline
def
resolve
::
Ci
::
CancelUserPipelinesService
.
new
.
execute
(
current_user
)
result
=
::
Ci
::
CancelUserPipelinesService
.
new
.
execute
(
current_user
)
{
errors:
[]
errors:
[
result
&
.
message
]
}
end
end
end
end
app/graphql/mutations/ci/pipeline_destroy.rb
View file @
838bd54a
...
...
@@ -12,11 +12,11 @@ module Mutations
project
=
pipeline
.
project
::
Ci
::
DestroyPipelineService
.
new
(
project
,
current_user
).
execute
(
pipeline
)
rescue
ActiveRecord
::
RecordNotFound
{
errors:
[]
errors:
[
'Pipeline not found'
]
}
end
end
end
end
app/graphql/mutations/ci/pipeline_retry.rb
View file @
838bd54a
...
...
@@ -17,7 +17,6 @@ module Mutations
errors:
errors_on_object
(
pipeline
)
}
end
end
end
end
app/services/ci/cancel_user_pipelines_service.rb
View file @
838bd54a
...
...
@@ -7,6 +7,8 @@ module Ci
# https://gitlab.com/gitlab-org/gitlab/issues/32332
def
execute
(
user
)
user
.
pipelines
.
cancelable
.
find_each
(
&
:cancel_running
)
rescue
ActiveRecord
::
StaleObjectError
ServiceResponse
.
error
(
message:
'Error canceling pipeline'
)
end
# rubocop: enable CodeReuse/ActiveRecord
end
...
...
spec/requests/api/graphql/mutations/ci/pipeline_cancel_spec.rb
View file @
838bd54a
...
...
@@ -7,7 +7,7 @@ RSpec.describe 'PipelineCancel' do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
:running
,
project:
project
,
user:
user
)
}
let
_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
:running
,
project:
project
,
user:
user
)
}
let
(
:mutation
)
do
graphql_mutation
(
:pipeline_cancel
,
{},
...
...
@@ -17,10 +17,21 @@ RSpec.describe 'PipelineCancel' do
)
end
before
do
let
(
:mutation_response
)
{
graphql_mutation_response
(
:pipeline_cancel
)
}
before
(
:all
)
do
project
.
add_maintainer
(
user
)
end
it
'reports the service-level error'
do
service
=
double
(
execute:
ServiceResponse
.
error
(
message:
'Error canceling pipeline'
))
allow
(
::
Ci
::
CancelUserPipelinesService
).
to
receive
(
:new
).
and_return
(
service
)
post_graphql_mutation
(
mutation
,
current_user:
create
(
:user
))
expect
(
mutation_response
).
to
include
(
'errors'
=>
[
'Error canceling pipeline'
])
end
it
'does not change any pipelines not owned by the current user'
do
build
=
create
(
:ci_build
,
:running
,
pipeline:
pipeline
)
...
...
spec/requests/api/graphql/mutations/ci/pipeline_destroy_spec.rb
View file @
838bd54a
...
...
@@ -7,7 +7,7 @@ RSpec.describe 'PipelineDestroy' do
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:user
)
{
project
.
owner
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
:success
,
project:
project
,
user:
user
)
}
let
_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
:success
,
project:
project
,
user:
user
)
}
let
(
:mutation
)
do
variables
=
{
...
...
spec/requests/api/graphql/mutations/ci/pipeline_retry_spec.rb
View file @
838bd54a
...
...
@@ -7,7 +7,7 @@ RSpec.describe 'PipelineRetry' do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
user:
user
)
}
let
_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
user:
user
)
}
let
(
:mutation
)
do
variables
=
{
...
...
@@ -25,7 +25,7 @@ RSpec.describe 'PipelineRetry' do
let
(
:mutation_response
)
{
graphql_mutation_response
(
:pipeline_retry
)
}
before
do
before
(
:all
)
do
project
.
add_maintainer
(
user
)
end
...
...
spec/services/ci/cancel_user_pipelines_service_spec.rb
View file @
838bd54a
...
...
@@ -19,5 +19,17 @@ RSpec.describe Ci::CancelUserPipelinesService do
expect
(
build
.
reload
).
to
be_canceled
end
end
context
'when an error ocurrs'
do
it
'raises a service level error'
do
service
=
double
(
execute:
ServiceResponse
.
error
(
message:
'Error canceling pipeline'
))
allow
(
::
Ci
::
CancelUserPipelinesService
).
to
receive
(
:new
).
and_return
(
service
)
result
=
subject
expect
(
result
).
to
be_a
(
ServiceResponse
)
expect
(
result
).
to
be_error
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