Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gitlab-ce
Commits
28c4c949
Commit
28c4c949
authored
Feb 05, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve CI status badge implementation
parent
14f928b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
17 deletions
+11
-17
app/controllers/projects/commit_controller.rb
app/controllers/projects/commit_controller.rb
+2
-3
app/services/ci/image_for_build_service.rb
app/services/ci/image_for_build_service.rb
+7
-12
config/routes.rb
config/routes.rb
+2
-2
No files found.
app/controllers/projects/commit_controller.rb
View file @
28c4c949
...
...
@@ -57,9 +57,8 @@ class Projects::CommitController < Projects::ApplicationController
render
layout:
false
end
def
status
status_sha
=
ci_commit
.
sha
if
ci_commit
image
=
Ci
::
ImageForBuildService
.
new
.
execute
(
@project
,
sha:
status_sha
)
def
badge
image
=
Ci
::
ImageForBuildService
.
new
.
execute
(
@project
,
ref:
params
[
:id
])
send_file
(
image
.
path
,
filename:
image
.
name
,
disposition:
'inline'
,
type:
'image/svg+xml'
)
end
...
...
app/services/ci/image_for_build_service.rb
View file @
28c4c949
module
Ci
class
ImageForBuildService
def
execute
(
project
,
params
)
sha
=
params
[
:sha
]
sha
||=
if
params
[
:ref
]
project
.
commit
(
params
[
:ref
]).
try
(
:sha
)
end
def
execute
(
project
,
opts
)
sha
=
opts
[
:sha
]
||
ref_sha
(
project
,
opts
[
:ref
])
commit
=
project
.
ci_commits
.
ordered
.
find_by
(
sha:
sha
)
image_name
=
image_for_commit
(
commit
)
image_path
=
Rails
.
root
.
join
(
'public/ci'
,
image_name
)
OpenStruct
.
new
(
path:
image_path
,
name:
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_commit
(
commit
)
return
'build-unknown.svg'
unless
commit
'build-'
+
commit
.
status
+
".svg"
end
end
...
...
config/routes.rb
View file @
28c4c949
...
...
@@ -496,9 +496,9 @@ Rails.application.routes.draw do
get
(
'/status/*id/badge'
,
to:
'commit#
status
'
,
to:
'commit#
badge
'
,
constraints:
{
format:
/png/
},
as: :commit_
status
as: :commit_
badge
)
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment