Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
d6167a92
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,发现更多精彩内容 >>
未验证
提交
d6167a92
编写于
10月 04, 2017
作者:
A
Alexis Reigel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
split up Ci::Runner.owned_or_shared scope
上级
81c0c57a
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
34 deletion
+40
-34
app/models/ci/runner.rb
app/models/ci/runner.rb
+16
-16
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+24
-18
未找到文件。
app/models/ci/runner.rb
浏览文件 @
d6167a92
...
...
@@ -21,17 +21,17 @@ module Ci
before_validation
:set_default_values
scope
:specific
,
->
()
{
where
(
is_shared:
false
)
}
scope
:shared
,
->
()
{
where
(
is_shared:
true
)
}
scope
:active
,
->
()
{
where
(
active:
true
)
}
scope
:paused
,
->
()
{
where
(
active:
false
)
}
scope
:online
,
->
()
{
where
(
'contacted_at > ?'
,
contact_time_deadline
)
}
scope
:ordered
,
->
()
{
order
(
id: :desc
)
}
scope
:owned_or_shared
,
->
(
project_id
)
do
project_runners
=
joins
(
:runner_projects
).
where
(
ci_runner_projects:
{
project_id:
project_id
})
group_runners
=
joins
(
scope
:specific
,
->
{
where
(
is_shared:
false
)
}
scope
:shared
,
->
{
where
(
is_shared:
true
)
}
scope
:active
,
->
{
where
(
active:
true
)
}
scope
:paused
,
->
{
where
(
active:
false
)
}
scope
:online
,
->
{
where
(
'contacted_at > ?'
,
contact_time_deadline
)
}
scope
:ordered
,
->
{
order
(
id: :desc
)
}
scope
:belonging_to_project
,
->
(
project_id
)
{
joins
(
:runner_projects
).
where
(
ci_runner_projects:
{
project_id:
project_id
})
}
scope
:belonging_to_group
,
->
(
project_id
)
{
joins
(
%{
INNER JOIN ci_runner_groups ON ci_runner_groups.runner_id = ci_runners.id
INNER JOIN namespaces ON namespaces.id = ci_runner_groups.group_id
...
...
@@ -43,13 +43,13 @@ module Ci
AND
projects.group_runners_enabled = :true
}
,
project_id:
project_id
,
true:
true
project_id:
project_id
,
true:
true
)
}
shared_runners
=
where
(
is_shared:
true
)
union
=
Gitlab
::
SQL
::
Union
.
new
([
project_runners
,
group_runners
,
shared_runners
])
scope
:owned_or_shared
,
->
(
project_id
)
do
union
=
Gitlab
::
SQL
::
Union
.
new
([
belonging_to_project
(
project_id
),
belonging_to_group
(
project_id
),
shared
])
from
(
"(
#{
union
.
to_sql
}
) ci_runners"
)
end
...
...
spec/models/ci/runner_spec.rb
浏览文件 @
d6167a92
...
...
@@ -49,7 +49,23 @@ describe Ci::Runner do
end
end
describe
'.owned_or_shared'
do
describe
'.shared'
do
it
'returns the shared group runner'
do
group
=
create
:group
runner
=
create
:ci_runner
,
:shared
,
groups:
[
group
]
expect
(
described_class
.
shared
).
to
eq
[
runner
]
end
it
'returns the shared project runner'
do
project
=
create
:project
runner
=
create
:ci_runner
,
:shared
,
projects:
[
project
]
expect
(
described_class
.
shared
).
to
eq
[
runner
]
end
end
describe
'.belonging_to_project'
do
it
'returns the specific project runner'
do
# own
specific_project
=
create
:project
...
...
@@ -59,16 +75,11 @@ describe Ci::Runner do
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 project runner'
do
project
=
create
:project
runner
=
create
:ci_runner
,
:shared
,
projects:
[
project
]
expect
(
described_class
.
owned_or_shared
(
0
)).
to
eq
[
runner
]
expect
(
described_class
.
belonging_to_project
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
end
end
describe
'.belonging_to_group'
do
it
'returns the specific group runner'
do
# own
specific_group
=
create
:group
...
...
@@ -80,7 +91,7 @@ describe Ci::Runner do
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
]
expect
(
described_class
.
belonging_to_group
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
end
it
'does not return the group runner if the project has group runners disabled'
do
...
...
@@ -88,16 +99,11 @@ describe Ci::Runner do
specific_project
=
create
:project
,
group:
specific_group
,
group_runners_enabled:
false
create
:ci_runner
,
:specific
,
groups:
[
specific_group
]
expect
(
described_class
.
owned_or_shared
(
specific_project
.
id
)).
to
be_empty
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
]
expect
(
described_class
.
belonging_to_group
(
specific_project
.
id
)).
to
be_empty
end
end
describe
'.owned_or_shared'
do
it
'returns a globally shared, a project specific and a group specific runner'
do
# group specific
group
=
create
:group
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录