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
Léo-Paul Géneau
gitlab-ce
Commits
4899dfca
Commit
4899dfca
authored
Aug 26, 2018
by
Eva Kadlecová
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Redirect to the pipeline builds page when a build is canceled
parent
120ce02e
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
62 additions
and
18 deletions
+62
-18
app/controllers/projects/jobs_controller.rb
app/controllers/projects/jobs_controller.rb
+7
-1
app/views/projects/ci/builds/_build.html.haml
app/views/projects/ci/builds/_build.html.haml
+1
-1
changelogs/unreleased/Fix-pipeline-redirect.yml
changelogs/unreleased/Fix-pipeline-redirect.yml
+5
-0
spec/controllers/projects/jobs_controller_spec.rb
spec/controllers/projects/jobs_controller_spec.rb
+49
-16
No files found.
app/controllers/projects/jobs_controller.rb
View file @
4899dfca
class
Projects::JobsController
<
Projects
::
ApplicationController
class
Projects::JobsController
<
Projects
::
ApplicationController
include
SendFileUpload
include
SendFileUpload
include
ContinueParams
before_action
:build
,
except:
[
:index
,
:cancel_all
]
before_action
:build
,
except:
[
:index
,
:cancel_all
]
before_action
:authorize_read_build!
before_action
:authorize_read_build!
...
@@ -101,7 +102,12 @@ class Projects::JobsController < Projects::ApplicationController
...
@@ -101,7 +102,12 @@ class Projects::JobsController < Projects::ApplicationController
return
respond_422
unless
@build
.
cancelable?
return
respond_422
unless
@build
.
cancelable?
@build
.
cancel
@build
.
cancel
redirect_to
build_path
(
@build
)
if
continue_params
redirect_to
continue_params
[
:to
]
else
redirect_to
builds_project_pipeline_path
(
@project
,
@build
.
pipeline
.
id
)
end
end
end
def
status
def
status
...
...
app/views/projects/ci/builds/_build.html.haml
View file @
4899dfca
...
@@ -99,7 +99,7 @@
...
@@ -99,7 +99,7 @@
=
sprite_icon
(
'download'
)
=
sprite_icon
(
'download'
)
-
if
can?
(
current_user
,
:update_build
,
job
)
-
if
can?
(
current_user
,
:update_build
,
job
)
-
if
job
.
active?
-
if
job
.
active?
=
link_to
cancel_project_job_path
(
job
.
project
,
job
,
return_to:
request
.
original_url
),
method: :post
,
title:
'Cancel'
,
class:
'btn btn-build'
do
=
link_to
cancel_project_job_path
(
job
.
project
,
job
,
continue:
{
to:
request
.
fullpath
}
),
method: :post
,
title:
'Cancel'
,
class:
'btn btn-build'
do
=
icon
(
'remove'
,
class:
'cred'
)
=
icon
(
'remove'
,
class:
'cred'
)
-
elsif
allow_retry
-
elsif
allow_retry
-
if
job
.
playable?
&&
!
admin
&&
can?
(
current_user
,
:update_build
,
job
)
-
if
job
.
playable?
&&
!
admin
&&
can?
(
current_user
,
:update_build
,
job
)
...
...
changelogs/unreleased/Fix-pipeline-redirect.yml
0 → 100644
View file @
4899dfca
---
title
:
Redirect to the pipeline builds page when a build is canceled
merge_request
:
author
:
Eva Kadlecova
type
:
fixed
spec/controllers/projects/jobs_controller_spec.rb
View file @
4899dfca
...
@@ -356,35 +356,68 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
...
@@ -356,35 +356,68 @@ describe Projects::JobsController, :clean_gitlab_redis_shared_state do
before
do
before
do
project
.
add_developer
(
user
)
project
.
add_developer
(
user
)
sign_in
(
user
)
sign_in
(
user
)
post_cancel
end
end
context
'when
job is cancelable
'
do
context
'when
continue url is present
'
do
let
(
:job
)
{
create
(
:ci_build
,
:cancelable
,
pipeline:
pipeline
)
}
let
(
:job
)
{
create
(
:ci_build
,
:cancelable
,
pipeline:
pipeline
)
}
it
'redirects to the canceled job page'
do
context
'when continue to is a safe url'
do
expect
(
response
).
to
have_gitlab_http_status
(
:found
)
let
(
:url
)
{
'/test'
}
expect
(
response
).
to
redirect_to
(
namespace_project_job_path
(
id:
job
.
id
))
before
do
post_cancel
(
continue:
{
to:
url
})
end
it
'redirects to the continue url'
do
expect
(
response
).
to
have_gitlab_http_status
(
:found
)
expect
(
response
).
to
redirect_to
(
url
)
end
it
'transits to canceled'
do
expect
(
job
.
reload
).
to
be_canceled
end
end
end
it
'transits to canceled'
do
context
'when continue to is not a safe url'
do
expect
(
job
.
reload
).
to
be_canceled
let
(
:url
)
{
'http://example.com'
}
it
'raises an error'
do
expect
{
cancel_with_redirect
(
url
)
}.
to
raise_error
end
end
end
end
end
context
'when job is not cancelable'
do
context
'when continue url is not present'
do
let
(
:job
)
{
create
(
:ci_build
,
:canceled
,
pipeline:
pipeline
)
}
before
do
post_cancel
end
it
'returns unprocessable_entity'
do
context
'when job is cancelable'
do
expect
(
response
).
to
have_gitlab_http_status
(
:unprocessable_entity
)
let
(
:job
)
{
create
(
:ci_build
,
:cancelable
,
pipeline:
pipeline
)
}
it
'redirects to the builds page'
do
expect
(
response
).
to
have_gitlab_http_status
(
:found
)
expect
(
response
).
to
redirect_to
(
builds_namespace_project_pipeline_path
(
id:
pipeline
.
id
))
end
it
'transits to canceled'
do
expect
(
job
.
reload
).
to
be_canceled
end
end
context
'when job is not cancelable'
do
let
(
:job
)
{
create
(
:ci_build
,
:canceled
,
pipeline:
pipeline
)
}
it
'returns unprocessable_entity'
do
expect
(
response
).
to
have_gitlab_http_status
(
:unprocessable_entity
)
end
end
end
end
end
def
post_cancel
def
post_cancel
(
additional_params
=
{})
post
:cancel
,
namespace_id:
project
.
namespace
,
post
:cancel
,
{
namespace_id:
project
.
namespace
,
project_id:
project
,
project_id:
project
,
id:
job
.
id
id:
job
.
id
}.
merge
(
additional_params
)
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