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
Tatuya Kamada
gitlab-ce
Commits
4cd1b9f4
Commit
4cd1b9f4
authored
Mar 23, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor builds badge, encapsulate inside a class
parent
63c8a05b
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
60 additions
and
2 deletions
+60
-2
app/controllers/projects/badges_controller.rb
app/controllers/projects/badges_controller.rb
+3
-2
lib/gitlab/badge/build.rb
lib/gitlab/badge/build.rb
+24
-0
spec/lib/gitlab/badge/build_spec.rb
spec/lib/gitlab/badge/build_spec.rb
+33
-0
No files found.
app/controllers/projects/badges_controller.rb
View file @
4cd1b9f4
...
...
@@ -2,11 +2,12 @@ class Projects::BadgesController < Projects::ApplicationController
before_action
:no_cache_headers
def
build
badge
=
Gitlab
::
Badge
::
Build
.
new
(
project
,
params
[
:ref
])
respond_to
do
|
format
|
format
.
html
{
render_404
}
format
.
svg
do
image
=
Ci
::
ImageForBuildService
.
new
.
execute
(
project
,
ref:
params
[
:ref
])
send_file
(
image
.
path
,
filename:
image
.
name
,
disposition:
'inline'
,
type:
'image/svg+xml'
)
send_data
(
badge
.
data
,
type:
badge
.
type
,
disposition:
'inline'
)
end
end
end
...
...
lib/gitlab/badge/build.rb
0 → 100644
View file @
4cd1b9f4
module
Gitlab
module
Badge
##
# Build badge
#
class
Build
def
initialize
(
project
,
ref
)
@image
=
::
Ci
::
ImageForBuildService
.
new
.
execute
(
project
,
ref:
ref
)
end
def
to_s
@image
[
:name
].
sub
(
/\.svg$/
,
''
)
end
def
type
'image/svg+xml'
end
def
data
File
.
read
(
@image
[
:path
])
end
end
end
end
spec/lib/gitlab/badge/build_spec.rb
0 → 100644
View file @
4cd1b9f4
require
'spec_helper'
describe
Gitlab
::
Badge
::
Build
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:sha
)
{
project
.
commit
.
sha
}
let
(
:ci_commit
)
{
create
(
:ci_commit
,
project:
project
,
sha:
sha
)
}
let
(
:badge
)
{
described_class
.
new
(
project
,
'master'
)
}
let!
(
:build
)
{
create
(
:ci_build
,
commit:
ci_commit
)
}
describe
'#type'
do
subject
{
badge
.
type
}
it
{
is_expected
.
to
eq
'image/svg+xml'
}
end
context
'build success'
do
before
{
build
.
success!
}
describe
'#to_s'
do
subject
{
badge
.
to_s
}
it
{
is_expected
.
to
eq
'build-success'
}
end
describe
'#data'
do
let
(
:data
)
{
badge
.
data
}
let
(
:xml
)
{
Nokogiri
::
XML
.
parse
(
data
)
}
it
'contains infromation about success'
do
expect
(
xml
.
at
(
%Q{text:contains("success")}
)).
to
be_truthy
end
end
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