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
Boxiang Sun
gitlab-ce
Commits
0c4fa861
Commit
0c4fa861
authored
Jul 28, 2016
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Calculate build status only in build badge class
parent
9ae1ecf8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
17 deletions
+26
-17
lib/gitlab/badge/build.rb
lib/gitlab/badge/build.rb
+13
-7
spec/lib/gitlab/badge/build_spec.rb
spec/lib/gitlab/badge/build_spec.rb
+13
-10
No files found.
lib/gitlab/badge/build.rb
View file @
0c4fa861
...
@@ -5,8 +5,16 @@ module Gitlab
...
@@ -5,8 +5,16 @@ module Gitlab
#
#
class
Build
class
Build
def
initialize
(
project
,
ref
)
def
initialize
(
project
,
ref
)
@project
,
@ref
=
project
,
ref
@project
=
project
@image
=
::
Ci
::
ImageForBuildService
.
new
.
execute
(
project
,
ref:
ref
)
@ref
=
ref
end
def
status
sha
=
@project
.
commit
(
@ref
).
try
(
:sha
)
@project
.
pipelines
.
where
(
sha:
sha
,
ref:
@ref
)
.
status
||
'unknown'
end
end
def
metadata
def
metadata
...
@@ -18,11 +26,9 @@ module Gitlab
...
@@ -18,11 +26,9 @@ module Gitlab
end
end
def
data
def
data
File
.
read
(
@image
[
:path
])
File
.
read
(
end
Rails
.
root
.
join
(
'public/ci'
,
'build-'
+
status
+
'.svg'
)
)
def
to_s
@image
[
:name
].
sub
(
/\.svg$/
,
''
)
end
end
end
end
end
end
...
...
spec/lib/gitlab/badge/build_spec.rb
View file @
0c4fa861
...
@@ -24,9 +24,10 @@ describe Gitlab::Badge::Build do
...
@@ -24,9 +24,10 @@ describe Gitlab::Badge::Build do
context
'build success'
do
context
'build success'
do
before
{
build
.
success!
}
before
{
build
.
success!
}
describe
'#to_s'
do
describe
'#status'
do
subject
{
badge
.
to_s
}
it
'is successful'
do
it
{
is_expected
.
to
eq
'build-success'
}
expect
(
badge
.
status
).
to
eq
'success'
end
end
end
describe
'#data'
do
describe
'#data'
do
...
@@ -41,9 +42,10 @@ describe Gitlab::Badge::Build do
...
@@ -41,9 +42,10 @@ describe Gitlab::Badge::Build do
context
'build failed'
do
context
'build failed'
do
before
{
build
.
drop!
}
before
{
build
.
drop!
}
describe
'#to_s'
do
describe
'#status'
do
subject
{
badge
.
to_s
}
it
'failed'
do
it
{
is_expected
.
to
eq
'build-failed'
}
expect
(
badge
.
status
).
to
eq
'failed'
end
end
end
describe
'#data'
do
describe
'#data'
do
...
@@ -57,9 +59,10 @@ describe Gitlab::Badge::Build do
...
@@ -57,9 +59,10 @@ describe Gitlab::Badge::Build do
end
end
context
'build does not exist'
do
context
'build does not exist'
do
describe
'#to_s'
do
describe
'#status'
do
subject
{
badge
.
to_s
}
it
'is unknown'
do
it
{
is_expected
.
to
eq
'build-unknown'
}
expect
(
badge
.
status
).
to
eq
'unknown'
end
end
end
describe
'#data'
do
describe
'#data'
do
...
@@ -81,7 +84,7 @@ describe Gitlab::Badge::Build do
...
@@ -81,7 +84,7 @@ describe Gitlab::Badge::Build do
end
end
it
'does not take outdated pipeline into account'
do
it
'does not take outdated pipeline into account'
do
expect
(
badge
.
to_s
).
to
eq
'build-
success'
expect
(
badge
.
status
).
to
eq
'
success'
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