Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
955b9347
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,体验更适合开发者的 AI 搜索 >>
提交
955b9347
编写于
9月 21, 2016
作者:
K
Kamil Trzcinski
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests to verify the correctness of returned environments
上级
d891051c
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
93 addition
and
11 deletion
+93
-11
CHANGELOG
CHANGELOG
+1
-0
app/models/merge_request.rb
app/models/merge_request.rb
+3
-3
app/models/project.rb
app/models/project.rb
+1
-1
app/views/projects/merge_requests/widget/_heading.html.haml
app/views/projects/merge_requests/widget/_heading.html.haml
+1
-1
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+46
-6
spec/models/project_spec.rb
spec/models/project_spec.rb
+41
-0
未找到文件。
CHANGELOG
浏览文件 @
955b9347
...
...
@@ -24,6 +24,7 @@ v 8.12.0 (unreleased)
- Cycle analytics (first iteration) !5986
- Remove vendor prefixes for linear-gradient CSS (ClemMakesApps)
- Move pushes_since_gc from the database to Redis
- Limit number of shown environments on Merge Request: show only environments for target_branch, source_branch and tags
- Add font color contrast to external label in admin area (ClemMakesApps)
- Change logo animation to CSS (ClemMakesApps)
- Instructions for enabling Git packfile bitmaps !6104
...
...
app/models/merge_request.rb
浏览文件 @
955b9347
...
...
@@ -672,10 +672,10 @@ class MergeRequest < ActiveRecord::Base
environments
=
source_project
.
environments_for
(
source_branch
,
diff_head_commit
)
environments
<<
=
target_project
.
environments_for
(
source
_branch
,
diff_head_commit
,
with_tags:
true
)
environments
+
=
target_project
.
environments_for
(
target
_branch
,
diff_head_commit
,
with_tags:
true
)
environments
environments
.
uniq
end
def
state_human_name
...
...
app/models/project.rb
浏览文件 @
955b9347
...
...
@@ -1304,7 +1304,7 @@ class Project < ActiveRecord::Base
environment_ids
.
where
(
ref:
ref
)
end
Environment
.
where
(
id:
environment_ids
).
map
do
|
environment
|
Environment
.
where
(
id:
environment_ids
).
select
do
|
environment
|
environment
.
includes_commit?
(
commit
)
end
end
...
...
app/views/projects/merge_requests/widget/_heading.html.haml
浏览文件 @
955b9347
...
...
@@ -43,7 +43,7 @@
=
icon
(
"times-circle"
)
Could not connect to the CI server. Please check your settings and try again.
-
@merge_request
.
environments
.
each
do
|
environment
|
-
@merge_request
.
environments
.
sort_by
(
&
:name
).
each
do
|
environment
|
-
if
can?
(
current_user
,
:read_environment
,
environment
)
.mr-widget-heading
.ci_widget.ci-success
...
...
spec/models/merge_request_spec.rb
浏览文件 @
955b9347
...
...
@@ -701,16 +701,56 @@ describe MergeRequest, models: true do
end
end
describe
"#environments"
do
describe
'#environments'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:merge_request
)
{
create
(
:merge_request
,
source_project:
project
)
}
it
'selects deployed environments'
do
environments
=
create_list
(
:environment
,
3
,
project:
project
)
create
(
:deployment
,
environment:
environments
.
first
,
sha:
project
.
commit
(
'master'
).
id
)
create
(
:deployment
,
environment:
environments
.
second
,
sha:
project
.
commit
(
'feature'
).
id
)
context
'with multiple environments'
do
let
(
:environments
)
{
create_list
(
:environment
,
3
,
project:
project
)
}
expect
(
merge_request
.
environments
).
to
eq
[
environments
.
first
]
before
do
create
(
:deployment
,
environment:
environments
.
first
,
ref:
'master'
,
sha:
project
.
commit
(
'master'
).
id
)
create
(
:deployment
,
environment:
environments
.
second
,
ref:
'feature'
,
sha:
project
.
commit
(
'feature'
).
id
)
end
it
'selects deployed environments'
do
expect
(
merge_request
.
environments
).
to
contain_exactly
(
environments
.
first
)
end
end
context
'with environments on source project'
do
let
(
:source_project
)
do
create
(
:project
)
do
|
fork_project
|
fork_project
.
create_forked_project_link
(
forked_to_project_id:
fork_project
.
id
,
forked_from_project_id:
project
.
id
)
end
end
let
(
:merge_request
)
do
create
(
:merge_request
,
source_project:
source_project
,
source_branch:
'feature'
,
target_project:
project
)
end
let
(
:source_environment
)
{
create
(
:environment
,
project:
source_project
)
}
before
do
create
(
:deployment
,
environment:
source_environment
,
ref:
'feature'
,
sha:
merge_request
.
diff_head_sha
)
end
it
'selects deployed environments'
do
expect
(
merge_request
.
environments
).
to
contain_exactly
(
source_environment
)
end
context
'with environments on target project'
do
let
(
:target_environment
)
{
create
(
:environment
,
project:
project
)
}
before
do
create
(
:deployment
,
environment:
target_environment
,
tag:
true
,
sha:
merge_request
.
diff_head_sha
)
end
it
'selects deployed environments'
do
expect
(
merge_request
.
environments
).
to
contain_exactly
(
source_environment
,
target_environment
)
end
end
end
context
'without a diff_head_commit'
do
...
...
spec/models/project_spec.rb
浏览文件 @
955b9347
...
...
@@ -1647,6 +1647,47 @@ describe Project, models: true do
end
end
describe
'#environments_for'
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:environment
)
{
create
(
:environment
,
project:
project
)
}
context
'tagged deployment'
do
before
do
create
(
:deployment
,
environment:
environment
,
ref:
'1.0'
,
tag:
true
,
sha:
project
.
commit
.
id
)
end
it
'returns environment when with_tags is set'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
,
with_tags:
true
)).
to
contain_exactly
(
environment
)
end
it
'does not return environment when no with_tags is set'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
)).
not_to
contain_exactly
(
environment
)
end
it
'does not return environment when commit is not part of deployment'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
(
'feature'
))).
not_to
contain_exactly
(
environment
)
end
end
context
'branch deployment'
do
before
do
create
(
:deployment
,
environment:
environment
,
ref:
'master'
,
sha:
project
.
commit
.
id
)
end
it
'returns environment when ref is set'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
)).
to
contain_exactly
(
environment
)
end
it
'does not environment when ref is different'
do
expect
(
project
.
environments_for
(
'feature'
,
project
.
commit
)).
not_to
contain_exactly
(
environment
)
end
it
'does not return environment when commit is not part of deployment'
do
expect
(
project
.
environments_for
(
'master'
,
project
.
commit
(
'feature'
))).
not_to
contain_exactly
(
environment
)
end
end
end
def
enable_lfs
allow
(
Gitlab
.
config
.
lfs
).
to
receive
(
:enabled
).
and_return
(
true
)
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录