Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
295184f6
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
295184f6
编写于
3月 01, 2017
作者:
A
Alexis Reigel
提交者:
Alexis Reigel
4月 23, 2018
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
include group runners in scope
上级
9a07bc81
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
75 addition
and
6 deletion
+75
-6
app/models/ci/runner.rb
app/models/ci/runner.rb
+29
-2
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+46
-4
未找到文件。
app/models/ci/runner.rb
浏览文件 @
295184f6
...
...
@@ -14,6 +14,8 @@ module Ci
has_many
:builds
has_many
:runner_projects
,
dependent: :destroy
# rubocop:disable Cop/ActiveRecordDependent
has_many
:projects
,
through: :runner_projects
has_many
:runner_groups
has_many
:groups
,
through: :runner_groups
has_one
:last_build
,
->
()
{
order
(
'id DESC'
)
},
class_name:
'Ci::Build'
...
...
@@ -27,8 +29,33 @@ module Ci
scope
:ordered
,
->
()
{
order
(
id: :desc
)
}
scope
:owned_or_shared
,
->
(
project_id
)
do
joins
(
'LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id'
)
.
where
(
"ci_runner_projects.project_id = :project_id OR ci_runners.is_shared = true"
,
project_id:
project_id
)
joins
(
%{
-- project runners
LEFT JOIN ci_runner_projects ON ci_runner_projects.runner_id = ci_runners.id
-- group runners
LEFT JOIN ci_runner_groups ON ci_runner_groups.runner_id = ci_runners.id
LEFT JOIN namespaces ON namespaces.id = ci_runner_groups.group_id
LEFT JOIN projects group_projects ON group_projects.namespace_id = namespaces.id
}
).
where
(
%{
-- project runners
ci_runner_projects.project_id = :project_id
OR
-- group runners
group_projects.id = :project_id
OR
-- shared runners
ci_runners.is_shared = true
}
,
project_id:
project_id
)
end
scope
:assignable_for
,
->
(
project
)
do
...
...
spec/models/ci/runner_spec.rb
浏览文件 @
295184f6
...
...
@@ -52,19 +52,61 @@ describe Ci::Runner do
describe
'scopes'
do
describe
'owned_or_shared'
do
it
'returns the specific project runner'
do
# own
specific_project
=
create
:project
other_project
=
create
:project
specific_runner
=
create
:ci_runner
,
:specific
,
projects:
[
specific_project
]
other_runner
=
create
:ci_runner
,
:specific
,
projects:
[
other_project
]
# other
other_project
=
create
:project
create
:ci_runner
,
:specific
,
projects:
[
other_project
]
expect
(
described_class
.
owned_or_shared
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
end
it
'returns the shared projects'
do
runner
=
create
:ci_runner
,
:shared
it
'returns the shared project runner'
do
project
=
create
:project
runner
=
create
:ci_runner
,
:shared
,
projects:
[
project
]
expect
(
described_class
.
owned_or_shared
(
0
)).
to
eq
[
runner
]
end
it
'returns the specific group runner'
do
# own
specific_group
=
create
:group
specific_project
=
create
:project
,
group:
specific_group
specific_runner
=
create
:ci_runner
,
:specific
,
groups:
[
specific_group
]
# other
other_group
=
create
:group
create
:project
,
group:
other_group
create
:ci_runner
,
:specific
,
groups:
[
other_group
]
expect
(
described_class
.
owned_or_shared
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
end
it
'returns the shared group runner'
do
group
=
create
:group
runner
=
create
:ci_runner
,
:shared
,
groups:
[
group
]
expect
(
described_class
.
owned_or_shared
(
0
)).
to
eq
[
runner
]
end
it
'returns a globally shared, a project specific and a group specific runner'
do
# group specific
group
=
create
:group
project
=
create
:project
,
group:
group
group_runner
=
create
:ci_runner
,
:specific
,
groups:
[
group
]
# project specific
project_runner
=
create
:ci_runner
,
:specific
,
projects:
[
project
]
# globally shared
shared_runner
=
create
:ci_runner
,
:shared
expect
(
described_class
.
owned_or_shared
(
project
.
id
)).
to
match_array
[
group_runner
,
project_runner
,
shared_runner
]
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录