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
dd6983a5
Commit
dd6983a5
authored
Feb 17, 2022
by
Pedro Pombeiro
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract AssignRunnerService
parent
0175304d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
63 additions
and
3 deletions
+63
-3
app/controllers/admin/runner_projects_controller.rb
app/controllers/admin/runner_projects_controller.rb
+1
-1
app/controllers/projects/runner_projects_controller.rb
app/controllers/projects/runner_projects_controller.rb
+1
-1
app/services/ci/assign_runner_service.rb
app/services/ci/assign_runner_service.rb
+20
-0
lib/api/ci/runners.rb
lib/api/ci/runners.rb
+1
-1
spec/services/ci/assign_runner_service_spec.rb
spec/services/ci/assign_runner_service_spec.rb
+40
-0
No files found.
app/controllers/admin/runner_projects_controller.rb
View file @
dd6983a5
...
@@ -8,7 +8,7 @@ class Admin::RunnerProjectsController < Admin::ApplicationController
...
@@ -8,7 +8,7 @@ class Admin::RunnerProjectsController < Admin::ApplicationController
def
create
def
create
@runner
=
Ci
::
Runner
.
find
(
params
[
:runner_project
][
:runner_id
])
@runner
=
Ci
::
Runner
.
find
(
params
[
:runner_project
][
:runner_id
])
if
@runner
.
assign_to
(
@project
,
current_user
)
if
::
Ci
::
AssignRunnerService
.
new
(
@runner
,
@project
,
current_user
).
execute
redirect_to
edit_admin_runner_url
(
@runner
),
notice:
s_
(
'Runners|Runner assigned to project.'
)
redirect_to
edit_admin_runner_url
(
@runner
),
notice:
s_
(
'Runners|Runner assigned to project.'
)
else
else
redirect_to
edit_admin_runner_url
(
@runner
),
alert:
'Failed adding runner to project'
redirect_to
edit_admin_runner_url
(
@runner
),
alert:
'Failed adding runner to project'
...
...
app/controllers/projects/runner_projects_controller.rb
View file @
dd6983a5
...
@@ -14,7 +14,7 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
...
@@ -14,7 +14,7 @@ class Projects::RunnerProjectsController < Projects::ApplicationController
path
=
project_runners_path
(
project
)
path
=
project_runners_path
(
project
)
if
@runner
.
assign_to
(
project
,
current_user
)
if
::
Ci
::
AssignRunnerService
.
new
(
@runner
,
@project
,
current_user
).
execute
redirect_to
path
,
notice:
s_
(
'Runners|Runner assigned to project.'
)
redirect_to
path
,
notice:
s_
(
'Runners|Runner assigned to project.'
)
else
else
assign_to_messages
=
@runner
.
errors
.
messages
[
:assign_to
]
assign_to_messages
=
@runner
.
errors
.
messages
[
:assign_to
]
...
...
app/services/ci/assign_runner_service.rb
0 → 100644
View file @
dd6983a5
# frozen_string_literal: true
module
Ci
class
AssignRunnerService
# @param [Ci::Runner] runner the runner to assign to a project
# @param [Project] project the new project to assign the runner to
# @param [User] user the user performing the operation
def
initialize
(
runner
,
project
,
user
)
@runner
=
runner
@project
=
project
@user
=
user
end
def
execute
return
false
unless
@user
.
nil?
||
@user
.
can?
(
:assign_runner
,
@runner
)
@runner
.
assign_to
(
@project
,
@user
)
end
end
end
lib/api/ci/runners.rb
View file @
dd6983a5
...
@@ -187,7 +187,7 @@ module API
...
@@ -187,7 +187,7 @@ module API
runner
=
get_runner
(
params
[
:runner_id
])
runner
=
get_runner
(
params
[
:runner_id
])
authenticate_enable_runner!
(
runner
)
authenticate_enable_runner!
(
runner
)
if
runner
.
assign_to
(
user_project
)
if
::
Ci
::
AssignRunnerService
.
new
(
runner
,
user_project
,
current_user
).
execute
present
runner
,
with:
Entities
::
Ci
::
Runner
present
runner
,
with:
Entities
::
Ci
::
Runner
else
else
render_validation_error!
(
runner
)
render_validation_error!
(
runner
)
...
...
spec/services/ci/assign_runner_service_spec.rb
0 → 100644
View file @
dd6983a5
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
::
Ci
::
AssignRunnerService
,
'#execute'
do
subject
{
described_class
.
new
(
runner
,
project
,
user
).
execute
}
let_it_be
(
:runner
)
{
build
(
:ci_runner
)
}
let_it_be
(
:project
)
{
build
(
:project
)
}
context
'without user'
do
let
(
:user
)
{
nil
}
it
'calls assign_to on runner and returns value unchanged'
do
expect
(
runner
).
to
receive
(
:assign_to
).
with
(
project
,
nil
).
once
.
and_return
(
'assign_to return value'
)
is_expected
.
to
eq
(
'assign_to return value'
)
end
end
context
'with unauthorized user'
do
let
(
:user
)
{
build
(
:user
)
}
it
'does not call assign_to on runner and returns false'
do
expect
(
runner
).
not_to
receive
(
:assign_to
)
is_expected
.
to
eq
(
false
)
end
end
context
'with admin user'
,
:enable_admin_mode
do
let
(
:user
)
{
create_default
(
:user
,
:admin
)
}
it
'calls assign_to on runner and returns value unchanged'
do
expect
(
runner
).
to
receive
(
:assign_to
).
with
(
project
,
user
).
once
.
and_return
(
'assign_to return value'
)
is_expected
.
to
eq
(
'assign_to return value'
)
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