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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Jérome Perrin
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
...
@@ -57,9 +57,8 @@ class Projects::CommitController < Projects::ApplicationController
render
layout:
false
render
layout:
false
end
end
def
status
def
badge
status_sha
=
ci_commit
.
sha
if
ci_commit
image
=
Ci
::
ImageForBuildService
.
new
.
execute
(
@project
,
ref:
params
[
:id
])
image
=
Ci
::
ImageForBuildService
.
new
.
execute
(
@project
,
sha:
status_sha
)
send_file
(
image
.
path
,
filename:
image
.
name
,
disposition:
'inline'
,
type:
'image/svg+xml'
)
send_file
(
image
.
path
,
filename:
image
.
name
,
disposition:
'inline'
,
type:
'image/svg+xml'
)
end
end
...
...
app/services/ci/image_for_build_service.rb
View file @
28c4c949
module
Ci
module
Ci
class
ImageForBuildService
class
ImageForBuildService
def
execute
(
project
,
params
)
def
execute
(
project
,
opts
)
sha
=
params
[
:sha
]
sha
=
opts
[
:sha
]
||
ref_sha
(
project
,
opts
[
:ref
])
sha
||=
if
params
[
:ref
]
project
.
commit
(
params
[
:ref
]).
try
(
:sha
)
end
commit
=
project
.
ci_commits
.
ordered
.
find_by
(
sha:
sha
)
commit
=
project
.
ci_commits
.
ordered
.
find_by
(
sha:
sha
)
image_name
=
image_for_commit
(
commit
)
image_name
=
image_for_commit
(
commit
)
image_path
=
Rails
.
root
.
join
(
'public/ci'
,
image_name
)
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
end
private
private
def
ref_sha
(
project
,
ref
)
project
.
commit
(
ref
).
try
(
:sha
)
if
ref
end
def
image_for_commit
(
commit
)
def
image_for_commit
(
commit
)
return
'build-unknown.svg'
unless
commit
return
'build-unknown.svg'
unless
commit
'build-'
+
commit
.
status
+
".svg"
'build-'
+
commit
.
status
+
".svg"
end
end
end
end
...
...
config/routes.rb
View file @
28c4c949
...
@@ -496,9 +496,9 @@ Rails.application.routes.draw do
...
@@ -496,9 +496,9 @@ Rails.application.routes.draw do
get
(
get
(
'/status/*id/badge'
,
'/status/*id/badge'
,
to:
'commit#
status
'
,
to:
'commit#
badge
'
,
constraints:
{
format:
/png/
},
constraints:
{
format:
/png/
},
as: :commit_
status
as: :commit_
badge
)
)
end
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