Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
91761b06
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,发现更多精彩内容 >>
提交
91761b06
编写于
3月 31, 2015
作者:
D
Douwe Maan
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add tests.
上级
2fdae52f
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
244 addition
and
7 deletion
+244
-7
app/controllers/projects/repositories_controller.rb
app/controllers/projects/repositories_controller.rb
+1
-5
app/services/archive_repository_service.rb
app/services/archive_repository_service.rb
+4
-2
app/workers/repository_archive_worker.rb
app/workers/repository_archive_worker.rb
+1
-0
spec/controllers/projects/repositories_controller_spec.rb
spec/controllers/projects/repositories_controller_spec.rb
+65
-0
spec/services/archive_repository_service_spec.rb
spec/services/archive_repository_service_spec.rb
+93
-0
spec/workers/repository_archive_worker_spec.rb
spec/workers/repository_archive_worker_spec.rb
+80
-0
未找到文件。
app/controllers/projects/repositories_controller.rb
浏览文件 @
91761b06
...
...
@@ -11,14 +11,10 @@ class Projects::RepositoriesController < Projects::ApplicationController
end
def
archive
unless
can?
(
current_user
,
:download_code
,
@project
)
render_404
and
return
end
begin
file_path
=
ArchiveRepositoryService
.
new
(
@project
,
params
[
:ref
],
params
[
:format
]).
execute
rescue
return
render_404
return
head
:not_found
end
if
file_path
...
...
app/services/archive_repository_service.rb
浏览文件 @
91761b06
...
...
@@ -6,7 +6,7 @@ class ArchiveRepositoryService
@project
,
@ref
,
@format
=
project
,
ref
,
format
.
downcase
end
def
execute
def
execute
(
options
=
{})
project
.
repository
.
clean_old_archives
raise
"No archive file path"
unless
file_path
...
...
@@ -17,7 +17,7 @@ class ArchiveRepositoryService
RepositoryArchiveWorker
.
perform_async
(
project
.
id
,
ref
,
format
)
end
archived
=
wait_until_archived
archived
=
wait_until_archived
(
options
[
:timeout
]
||
5.0
)
file_path
if
archived
end
...
...
@@ -45,6 +45,8 @@ class ArchiveRepositoryService
end
def
wait_until_archived
(
timeout
=
5.0
)
return
archived?
if
timeout
==
0.0
t1
=
Time
.
now
begin
...
...
app/workers/repository_archive_worker.rb
浏览文件 @
91761b06
...
...
@@ -13,6 +13,7 @@ class RepositoryArchiveWorker
repository
.
clean_old_archives
return
unless
file_path
return
if
archived?
||
archiving?
repository
.
archive_repo
(
ref
,
storage_path
,
format
)
...
...
spec/controllers/projects/repositories_controller_spec.rb
0 → 100644
浏览文件 @
91761b06
require
"spec_helper"
describe
Projects
::
RepositoriesController
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:user
)
}
describe
"GET archive"
do
before
do
sign_in
(
user
)
project
.
team
<<
[
user
,
:developer
]
allow
(
ArchiveRepositoryService
).
to
receive
(
:new
).
and_return
(
service
)
end
let
(
:service
)
{
ArchiveRepositoryService
.
new
(
project
,
"master"
,
"zip"
)
}
it
"executes ArchiveRepositoryService"
do
expect
(
ArchiveRepositoryService
).
to
receive
(
:new
).
with
(
project
,
"master"
,
"zip"
)
expect
(
service
).
to
receive
(
:execute
)
get
:archive
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
ref:
"master"
,
format:
"zip"
end
context
"when the service raises an error"
do
before
do
allow
(
service
).
to
receive
(
:execute
).
and_raise
(
"Archive failed"
)
end
it
"renders Not Found"
do
get
:archive
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
ref:
"master"
,
format:
"zip"
expect
(
response
.
status
).
to
eq
(
404
)
end
end
context
"when the service doesn't return a path"
do
before
do
allow
(
service
).
to
receive
(
:execute
).
and_return
(
nil
)
end
it
"reloads the page"
do
get
:archive
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
ref:
"master"
,
format:
"zip"
expect
(
response
).
to
redirect_to
(
archive_namespace_project_repository_path
(
project
.
namespace
,
project
,
ref:
"master"
,
format:
"zip"
))
end
end
context
"when the service returns a path"
do
let
(
:path
)
{
Rails
.
root
.
join
(
"spec/fixtures/dk.png"
).
to_s
}
before
do
allow
(
service
).
to
receive
(
:execute
).
and_return
(
path
)
end
it
"sends the file"
do
get
:archive
,
namespace_id:
project
.
namespace
.
path
,
project_id:
project
.
path
,
ref:
"master"
,
format:
"zip"
expect
(
response
.
body
).
to
eq
(
File
.
binread
(
path
))
end
end
end
end
spec/services/archive_repository_service_spec.rb
0 → 100644
浏览文件 @
91761b06
require
'spec_helper'
describe
ArchiveRepositoryService
do
let
(
:project
)
{
create
(
:project
)
}
subject
{
ArchiveRepositoryService
.
new
(
project
,
"master"
,
"zip"
)
}
describe
"#execute"
do
it
"cleans old archives"
do
expect
(
project
.
repository
).
to
receive
(
:clean_old_archives
)
subject
.
execute
(
timeout:
0.0
)
end
context
"when the repository doesn't have an archive file path"
do
before
do
allow
(
project
.
repository
).
to
receive
(
:archive_file_path
).
and_return
(
nil
)
end
it
"raises an error"
do
expect
{
subject
.
execute
(
timeout:
0.0
)
}.
to
raise_error
end
end
context
"when the repository has an archive file path"
do
let
(
:file_path
)
{
"/archive.zip"
}
let
(
:pid_file_path
)
{
"/archive.zip.pid"
}
before
do
allow
(
project
.
repository
).
to
receive
(
:archive_file_path
).
and_return
(
file_path
)
allow
(
project
.
repository
).
to
receive
(
:archive_pid_file_path
).
and_return
(
pid_file_path
)
end
context
"when the archive file already exists"
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
file_path
).
and_return
(
true
)
end
it
"returns the file path"
do
expect
(
subject
.
execute
(
timeout:
0.0
)).
to
eq
(
file_path
)
end
end
context
"when the archive file doesn't exist yet"
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
file_path
).
and_return
(
false
)
allow
(
File
).
to
receive
(
:exist?
).
with
(
pid_file_path
).
and_return
(
true
)
end
context
"when the archive pid file doesn't exist yet"
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
pid_file_path
).
and_return
(
false
)
end
it
"queues the RepositoryArchiveWorker"
do
expect
(
RepositoryArchiveWorker
).
to
receive
(
:perform_async
)
subject
.
execute
(
timeout:
0.0
)
end
end
context
"when the archive pid file already exists"
do
it
"doesn't queue the RepositoryArchiveWorker"
do
expect
(
RepositoryArchiveWorker
).
not_to
receive
(
:perform_async
)
subject
.
execute
(
timeout:
0.0
)
end
end
context
"when the archive file exists after a little while"
do
before
do
Thread
.
new
do
sleep
0.1
allow
(
File
).
to
receive
(
:exist?
).
with
(
file_path
).
and_return
(
true
)
end
end
it
"returns the file path"
do
expect
(
subject
.
execute
(
timeout:
0.2
)).
to
eq
(
file_path
)
end
end
context
"when the archive file doesn't exist after the timeout"
do
it
"returns nil"
do
expect
(
subject
.
execute
(
timeout:
0.0
)).
to
eq
(
nil
)
end
end
end
end
end
end
spec/workers/repository_archive_worker_spec.rb
0 → 100644
浏览文件 @
91761b06
require
'spec_helper'
describe
RepositoryArchiveWorker
do
let
(
:project
)
{
create
(
:project
)
}
subject
{
RepositoryArchiveWorker
.
new
}
before
do
allow
(
Project
).
to
receive
(
:find
).
and_return
(
project
)
end
describe
"#perform"
do
it
"cleans old archives"
do
expect
(
project
.
repository
).
to
receive
(
:clean_old_archives
)
subject
.
perform
(
project
.
id
,
"master"
,
"zip"
)
end
context
"when the repository doesn't have an archive file path"
do
before
do
allow
(
project
.
repository
).
to
receive
(
:archive_file_path
).
and_return
(
nil
)
end
it
"doesn't archive the repo"
do
expect
(
project
.
repository
).
not_to
receive
(
:archive_repo
)
subject
.
perform
(
project
.
id
,
"master"
,
"zip"
)
end
end
context
"when the repository has an archive file path"
do
let
(
:file_path
)
{
"/archive.zip"
}
let
(
:pid_file_path
)
{
"/archive.zip.pid"
}
before
do
allow
(
project
.
repository
).
to
receive
(
:archive_file_path
).
and_return
(
file_path
)
allow
(
project
.
repository
).
to
receive
(
:archive_pid_file_path
).
and_return
(
pid_file_path
)
end
context
"when the archive file already exists"
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
file_path
).
and_return
(
true
)
end
it
"doesn't archive the repo"
do
expect
(
project
.
repository
).
not_to
receive
(
:archive_repo
)
subject
.
perform
(
project
.
id
,
"master"
,
"zip"
)
end
end
context
"when the archive file doesn't exist yet"
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
file_path
).
and_return
(
false
)
allow
(
File
).
to
receive
(
:exist?
).
with
(
pid_file_path
).
and_return
(
true
)
end
context
"when the archive pid file doesn't exist yet"
do
before
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
pid_file_path
).
and_return
(
false
)
end
it
"archives the repo"
do
expect
(
project
.
repository
).
to
receive
(
:archive_repo
)
subject
.
perform
(
project
.
id
,
"master"
,
"zip"
)
end
end
context
"when the archive pid file already exists"
do
it
"doesn't archive the repo"
do
expect
(
project
.
repository
).
not_to
receive
(
:archive_repo
)
subject
.
perform
(
project
.
id
,
"master"
,
"zip"
)
end
end
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录