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
1acd8eb7
Commit
1acd8eb7
authored
Dec 07, 2017
by
Alexis Reigel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ci runners: assigned to either projects or group
parent
316ccb64
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
68 additions
and
0 deletions
+68
-0
app/models/ci/runner.rb
app/models/ci/runner.rb
+11
-0
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+57
-0
No files found.
app/models/ci/runner.rb
View file @
1acd8eb7
...
...
@@ -50,6 +50,7 @@ module Ci
end
validate
:tag_constraints
validate
:either_projects_or_group
validates
:access_level
,
presence:
true
acts_as_taggable
...
...
@@ -227,6 +228,16 @@ module Ci
self
.
class
.
owned_or_shared
(
project_id
).
where
(
id:
self
.
id
).
any?
end
def
either_projects_or_group
if
groups
.
length
>
1
errors
.
add
(
:runner
,
'can only be assigned to one group'
)
end
if
groups
.
length
>
0
&&
projects
.
length
>
0
errors
.
add
(
:runner
,
'can only be assigned either to projects or to a group'
)
end
end
def
accepting_tags?
(
build
)
(
run_untagged?
||
build
.
has_tags?
)
&&
(
build
.
tag_list
-
tag_list
).
empty?
end
...
...
spec/models/ci/runner_spec.rb
View file @
1acd8eb7
...
...
@@ -19,6 +19,63 @@ describe Ci::Runner do
end
end
end
context
'either_projects_or_group'
do
it
'disallows assigning to a group if already assigned to a group'
do
group
=
create
(
:group
)
runner
=
create
(
:ci_runner
,
groups:
[
group
])
runner
.
groups
<<
build
(
:group
)
expect
(
runner
).
not_to
be_valid
expect
(
runner
.
errors
.
full_messages
).
to
eq
[
'Runner can only be assigned to one group'
]
end
it
'disallows assigning to a group if already assigned to a project'
do
project
=
create
(
:project
)
runner
=
create
(
:ci_runner
,
projects:
[
project
])
runner
.
groups
<<
build
(
:group
)
expect
(
runner
).
not_to
be_valid
expect
(
runner
.
errors
.
full_messages
).
to
eq
[
'Runner can only be assigned either to projects or to a group'
]
end
it
'disallows assigning to a project if already assigned to a group'
do
group
=
create
(
:group
)
runner
=
create
(
:ci_runner
,
groups:
[
group
])
runner
.
projects
<<
build
(
:project
)
expect
(
runner
).
not_to
be_valid
expect
(
runner
.
errors
.
full_messages
).
to
eq
[
'Runner can only be assigned either to projects or to a group'
]
end
it
'allows assigning to a group if not assigned to a group nor a project'
do
runner
=
create
(
:ci_runner
)
runner
.
groups
<<
build
(
:group
)
expect
(
runner
).
to
be_valid
end
it
'allows assigning to a project if not assigned to a group nor a project'
do
runner
=
create
(
:ci_runner
)
runner
.
projects
<<
build
(
:project
)
expect
(
runner
).
to
be_valid
end
it
'allows assigning to a project if already assigned to a project'
do
project
=
create
(
:project
)
runner
=
create
(
:ci_runner
,
projects:
[
project
])
runner
.
projects
<<
build
(
:project
)
expect
(
runner
).
to
be_valid
end
end
end
describe
'#access_level'
do
...
...
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