Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
7421604b
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,发现更多精彩内容 >>
提交
7421604b
编写于
3月 06, 2018
作者:
S
Shinya Maeda
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduce FailedToExtractError. Fix spec. Add DNS test mock.
上级
031794f5
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
22 addition
and
10 deletion
+22
-10
app/services/projects/update_pages_service.rb
app/services/projects/update_pages_service.rb
+8
-7
spec/features/projects/jobs/user_browses_job_spec.rb
spec/features/projects/jobs/user_browses_job_spec.rb
+0
-2
spec/features/projects/pages_spec.rb
spec/features/projects/pages_spec.rb
+1
-1
spec/services/projects/update_pages_service_spec.rb
spec/services/projects/update_pages_service_spec.rb
+13
-0
未找到文件。
app/services/projects/update_pages_service.rb
浏览文件 @
7421604b
module
Projects
class
UpdatePagesService
<
BaseService
InvaildStateError
=
Class
.
new
(
StandardError
)
FailedToExtractError
=
Class
.
new
(
StandardError
)
BLOCK_SIZE
=
32
.
kilobytes
MAX_SIZE
=
1
.
terabyte
...
...
@@ -30,13 +31,13 @@ module Projects
# Check if we did extract public directory
archive_public_path
=
File
.
join
(
archive_path
,
'public'
)
raise
InvaildState
Error
,
'pages miss the public folder'
unless
Dir
.
exist?
(
archive_public_path
)
raise
FailedToExtract
Error
,
'pages miss the public folder'
unless
Dir
.
exist?
(
archive_public_path
)
raise
InvaildStateError
,
'pages are outdated'
unless
latest?
deploy_page!
(
archive_public_path
)
success
end
rescue
InvaildStateError
=>
e
rescue
InvaildStateError
,
FailedToExtractError
=>
e
register_failure
error
(
e
.
message
)
end
...
...
@@ -75,7 +76,7 @@ module Projects
elsif
artifacts
.
ends_with?
(
'.zip'
)
extract_zip_archive!
(
temp_path
)
else
raise
'unsupported artifacts format'
raise
FailedToExtractError
,
'unsupported artifacts format'
end
end
...
...
@@ -84,17 +85,17 @@ module Projects
%W(dd bs=
#{
BLOCK_SIZE
}
count=
#{
blocks
}
)
,
%W(tar -x -C
#{
temp_path
}
#{
SITE_PATH
}
)
,
err:
'/dev/null'
)
raise
'pages failed to extract'
unless
results
.
compact
.
all?
(
&
:success?
)
raise
FailedToExtractError
,
'pages failed to extract'
unless
results
.
compact
.
all?
(
&
:success?
)
end
def
extract_zip_archive!
(
temp_path
)
raise
'missing artifacts metadata'
unless
build
.
artifacts_metadata?
raise
FailedToExtractError
,
'missing artifacts metadata'
unless
build
.
artifacts_metadata?
# Calculate page size after extract
public_entry
=
build
.
artifacts_metadata_entry
(
SITE_PATH
,
recursive:
true
)
if
public_entry
.
total_size
>
max_size
raise
"artifacts for pages are too large:
#{
public_entry
.
total_size
}
"
raise
FailedToExtractError
,
"artifacts for pages are too large:
#{
public_entry
.
total_size
}
"
end
# Requires UnZip at least 6.00 Info-ZIP.
...
...
@@ -103,7 +104,7 @@ module Projects
# We add * to end of SITE_PATH, because we want to extract SITE_PATH and all subdirectories
site_path
=
File
.
join
(
SITE_PATH
,
'*'
)
unless
system
(
*
%W(unzip -qq -n
#{
artifacts
}
#{
site_path
}
-d
#{
temp_path
}
)
)
raise
'pages failed to extract'
raise
FailedToExtractError
,
'pages failed to extract'
end
end
...
...
spec/features/projects/jobs/user_browses_job_spec.rb
浏览文件 @
7421604b
...
...
@@ -31,7 +31,5 @@ describe 'User browses a job', :js do
page
.
within
(
'.erased'
)
do
expect
(
page
).
to
have_content
(
'Job has been erased'
)
end
expect
(
build
.
project
.
running_or_pending_build_count
).
to
eq
(
build
.
project
.
builds
.
running_or_pending
.
count
(
:all
))
end
end
spec/features/projects/pages_spec.rb
浏览文件 @
7421604b
...
...
@@ -258,7 +258,7 @@ feature 'Pages' do
end
let
(
:ci_build
)
do
build
(
create
(
:ci_build
,
project:
project
,
pipeline:
pipeline
,
...
...
spec/services/projects/update_pages_service_spec.rb
浏览文件 @
7421604b
...
...
@@ -34,6 +34,7 @@ describe Projects::UpdatePagesService do
context
'with expiry date'
do
before
do
build
.
artifacts_expire_in
=
"2 days"
build
.
save!
end
it
"doesn't delete artifacts"
do
...
...
@@ -105,6 +106,7 @@ describe Projects::UpdatePagesService do
context
'with expiry date'
do
before
do
build
.
artifacts_expire_in
=
"2 days"
build
.
save!
end
it
"doesn't delete artifacts"
do
...
...
@@ -159,6 +161,17 @@ describe Projects::UpdatePagesService do
expect
(
execute
).
not_to
eq
(
:success
)
end
context
'when timeout happens by DNS error'
do
before
do
allow_any_instance_of
(
Projects
::
UpdatePagesService
)
.
to
receive
(
:extract_zip_archive!
).
and_raise
(
SocketError
)
end
it
'raises an error'
do
expect
{
execute
}.
to
raise_error
(
SocketError
)
end
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录