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
9ae1ecf8
Commit
9ae1ecf8
authored
Jul 28, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract build status badge metadata to separate class
parent
42c035ee
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
82 additions
and
49 deletions
+82
-49
app/controllers/projects/pipelines_settings_controller.rb
app/controllers/projects/pipelines_settings_controller.rb
+1
-1
lib/gitlab/badge/build.rb
lib/gitlab/badge/build.rb
+4
-21
lib/gitlab/badge/build/metadata.rb
lib/gitlab/badge/build/metadata.rb
+36
-0
spec/lib/gitlab/badge/build/metadata_spec.rb
spec/lib/gitlab/badge/build/metadata_spec.rb
+37
-0
spec/lib/gitlab/badge/build_spec.rb
spec/lib/gitlab/badge/build_spec.rb
+4
-27
No files found.
app/controllers/projects/pipelines_settings_controller.rb
View file @
9ae1ecf8
...
...
@@ -3,7 +3,7 @@ class Projects::PipelinesSettingsController < Projects::ApplicationController
def
show
@ref
=
params
[
:ref
]
||
@project
.
default_branch
||
'master'
@build_badge
=
Gitlab
::
Badge
::
Build
.
new
(
@project
,
@ref
)
@build_badge
=
Gitlab
::
Badge
::
Build
.
new
(
@project
,
@ref
)
.
metadata
end
def
update
...
...
lib/gitlab/badge/build.rb
View file @
9ae1ecf8
...
...
@@ -4,15 +4,15 @@ module Gitlab
# Build badge
#
class
Build
include
Gitlab
::
Application
.
routes
.
url_helpers
include
ActionView
::
Helpers
::
AssetTagHelper
include
ActionView
::
Helpers
::
UrlHelper
def
initialize
(
project
,
ref
)
@project
,
@ref
=
project
,
ref
@image
=
::
Ci
::
ImageForBuildService
.
new
.
execute
(
project
,
ref:
ref
)
end
def
metadata
Build
::
Metadata
.
new
(
@project
,
@ref
)
end
def
type
'image/svg+xml'
end
...
...
@@ -24,23 +24,6 @@ module Gitlab
def
to_s
@image
[
:name
].
sub
(
/\.svg$/
,
''
)
end
def
to_html
link_to
(
image_tag
(
image_url
,
alt:
'build status'
),
link_url
)
end
def
to_markdown
"[![build status](
#{
image_url
}
)](
#{
link_url
}
)"
end
def
image_url
build_namespace_project_badges_url
(
@project
.
namespace
,
@project
,
@ref
,
format: :svg
)
end
def
link_url
namespace_project_commits_url
(
@project
.
namespace
,
@project
,
id:
@ref
)
end
end
end
end
lib/gitlab/badge/build/metadata.rb
0 → 100644
View file @
9ae1ecf8
module
Gitlab
module
Badge
class
Build
##
# Class that describes build badge metadata
#
class
Metadata
include
Gitlab
::
Application
.
routes
.
url_helpers
include
ActionView
::
Helpers
::
AssetTagHelper
include
ActionView
::
Helpers
::
UrlHelper
def
initialize
(
project
,
ref
)
@project
=
project
@ref
=
ref
end
def
to_html
link_to
(
image_tag
(
image_url
,
alt:
'build status'
),
link_url
)
end
def
to_markdown
"[![build status](
#{
image_url
}
)](
#{
link_url
}
)"
end
def
image_url
build_namespace_project_badges_url
(
@project
.
namespace
,
@project
,
@ref
,
format: :svg
)
end
def
link_url
namespace_project_commits_url
(
@project
.
namespace
,
@project
,
id:
@ref
)
end
end
end
end
end
spec/lib/gitlab/badge/build/metadata_spec.rb
0 → 100644
View file @
9ae1ecf8
require
'spec_helper'
describe
Gitlab
::
Badge
::
Build
::
Metadata
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:branch
)
{
'master'
}
let
(
:badge
)
{
described_class
.
new
(
project
,
branch
)
}
describe
'#to_html'
do
let
(
:html
)
{
Nokogiri
::
HTML
.
parse
(
badge
.
to_html
)
}
let
(
:a_href
)
{
html
.
at
(
'a'
)
}
it
'points to link'
do
expect
(
a_href
[
:href
]).
to
eq
badge
.
link_url
end
it
'contains clickable image'
do
expect
(
a_href
.
children
.
first
.
name
).
to
eq
'img'
end
end
describe
'#to_markdown'
do
subject
{
badge
.
to_markdown
}
it
{
is_expected
.
to
include
badge
.
image_url
}
it
{
is_expected
.
to
include
badge
.
link_url
}
end
describe
'#image_url'
do
subject
{
badge
.
image_url
}
it
{
is_expected
.
to
include
"badges/
#{
branch
}
/build.svg"
}
end
describe
'#link_url'
do
subject
{
badge
.
link_url
}
it
{
is_expected
.
to
include
"commits/
#{
branch
}
"
}
end
end
spec/lib/gitlab/badge/build_spec.rb
View file @
9ae1ecf8
...
...
@@ -11,36 +11,13 @@ describe Gitlab::Badge::Build do
it
{
is_expected
.
to
eq
'image/svg+xml'
}
end
describe
'#to_html'
do
let
(
:html
)
{
Nokogiri
::
HTML
.
parse
(
badge
.
to_html
)
}
let
(
:a_href
)
{
html
.
at
(
'a'
)
}
it
'points to link'
do
expect
(
a_href
[
:href
]).
to
eq
badge
.
link_url
end
it
'contains clickable image'
do
expect
(
a_href
.
children
.
first
.
name
).
to
eq
'img'
describe
'#metadata'
do
it
'returns badge metadata'
do
expect
(
badge
.
metadata
.
image_url
)
.
to
include
'badges/master/build.svg'
end
end
describe
'#to_markdown'
do
subject
{
badge
.
to_markdown
}
it
{
is_expected
.
to
include
badge
.
image_url
}
it
{
is_expected
.
to
include
badge
.
link_url
}
end
describe
'#image_url'
do
subject
{
badge
.
image_url
}
it
{
is_expected
.
to
include
"badges/
#{
branch
}
/build.svg"
}
end
describe
'#link_url'
do
subject
{
badge
.
link_url
}
it
{
is_expected
.
to
include
"commits/
#{
branch
}
"
}
end
context
'build exists'
do
let!
(
:build
)
{
create_build
(
project
,
sha
,
branch
)
}
...
...
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