Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
6fdbc229
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,发现更多精彩内容 >>
提交
6fdbc229
编写于
3月 01, 2017
作者:
G
Grzegorz Bizon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove deprecated legacy CI project status badge
上级
46252628
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
1 addition
and
153 deletion
+1
-153
app/controllers/ci/projects_controller.rb
app/controllers/ci/projects_controller.rb
+0
-47
app/services/ci/image_for_build_service.rb
app/services/ci/image_for_build_service.rb
+0
-25
config/routes/ci.rb
config/routes/ci.rb
+1
-7
spec/controllers/ci/projects_controller_spec.rb
spec/controllers/ci/projects_controller_spec.rb
+0
-74
未找到文件。
app/controllers/ci/projects_controller.rb
已删除
100644 → 0
浏览文件 @
46252628
module
Ci
class
ProjectsController
<
::
ApplicationController
before_action
:project
before_action
:no_cache
,
only:
[
:badge
]
before_action
:authorize_read_project!
,
except:
[
:badge
,
:index
]
skip_before_action
:authenticate_user!
,
only:
[
:badge
]
protect_from_forgery
def
index
redirect_to
root_path
end
def
show
# Temporary compatibility with CI badges pointing to CI project page
redirect_to
namespace_project_path
(
project
.
namespace
,
project
)
end
# Project status badge
# Image with build status for sha or ref
#
# This action in DEPRECATED, this is here only for backwards compatibility
# with projects migrated from GitLab CI.
#
def
badge
return
render_404
unless
@project
image
=
Ci
::
ImageForBuildService
.
new
.
execute
(
@project
,
params
)
send_file
image
.
path
,
filename:
image
.
name
,
disposition:
'inline'
,
type:
"image/svg+xml"
end
protected
def
project
@project
||=
Project
.
find_by
(
ci_id:
params
[
:id
].
to_i
)
end
def
no_cache
response
.
headers
[
"Cache-Control"
]
=
"no-cache, no-store, max-age=0, must-revalidate"
response
.
headers
[
"Pragma"
]
=
"no-cache"
response
.
headers
[
"Expires"
]
=
"Fri, 01 Jan 1990 00:00:00 GMT"
end
def
authorize_read_project!
return
access_denied!
unless
can?
(
current_user
,
:read_project
,
project
)
end
end
end
app/services/ci/image_for_build_service.rb
已删除
100644 → 0
浏览文件 @
46252628
module
Ci
class
ImageForBuildService
def
execute
(
project
,
opts
)
ref
=
opts
[
:ref
]
sha
=
opts
[
:sha
]
||
ref_sha
(
project
,
ref
)
pipelines
=
project
.
pipelines
.
where
(
sha:
sha
)
image_name
=
image_for_status
(
pipelines
.
latest_status
(
ref
))
image_path
=
Rails
.
root
.
join
(
'public/ci'
,
image_name
)
OpenStruct
.
new
(
path:
image_path
,
name:
image_name
)
end
private
def
ref_sha
(
project
,
ref
)
project
.
commit
(
ref
).
try
(
:sha
)
if
ref
end
def
image_for_status
(
status
)
status
||=
'unknown'
'build-'
+
status
+
".svg"
end
end
end
config/routes/ci.rb
浏览文件 @
6fdbc229
...
...
@@ -5,11 +5,5 @@ namespace :ci do
resource
:lint
,
only:
[
:show
,
:create
]
resources
:projects
,
only:
[
:index
,
:show
]
do
member
do
get
:status
,
to:
'projects#badge'
end
end
root
to:
'projects#index'
root
to:
redirect
(
'/'
)
end
spec/controllers/ci/projects_controller_spec.rb
已删除
100644 → 0
浏览文件 @
46252628
require
'spec_helper'
describe
Ci
::
ProjectsController
do
let
(
:visibility
)
{
:public
}
let!
(
:project
)
{
create
(
:empty_project
,
visibility
,
ci_id:
1
)
}
let
(
:ci_id
)
{
project
.
ci_id
}
describe
'#index'
do
context
'user signed in'
do
before
do
sign_in
(
create
(
:user
))
get
(
:index
)
end
it
'redirects to /'
do
expect
(
response
).
to
redirect_to
(
root_path
)
end
end
context
'user not signed in'
do
before
{
get
(
:index
)
}
it
'redirects to sign in page'
do
expect
(
response
).
to
redirect_to
(
new_user_session_path
)
end
end
end
##
# Specs for *deprecated* CI badge
#
describe
'#badge'
do
shared_examples
'badge provider'
do
it
'shows badge'
do
expect
(
response
.
status
).
to
eq
200
expect
(
response
.
headers
)
.
to
include
(
'Content-Type'
=>
'image/svg+xml'
)
end
end
context
'user not signed in'
do
before
{
get
(
:badge
,
id:
ci_id
)
}
context
'project has no ci_id reference'
do
let
(
:ci_id
)
{
123
}
it
'returns 404'
do
expect
(
response
.
status
).
to
eq
404
end
end
context
'project is public'
do
let
(
:visibility
)
{
:public
}
it_behaves_like
'badge provider'
end
context
'project is private'
do
let
(
:visibility
)
{
:private
}
it_behaves_like
'badge provider'
end
end
context
'user signed in'
do
let
(
:user
)
{
create
(
:user
)
}
before
{
sign_in
(
user
)
}
before
{
get
(
:badge
,
id:
ci_id
)
}
context
'private is internal'
do
let
(
:visibility
)
{
:internal
}
it_behaves_like
'badge provider'
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录