Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-08-11 12:16:14 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2016-08-15 15:39:46 +0300
commitf3de46e6b0d4cc61e00c884753a8c9eec66f66c4 (patch)
treec94491b355df3a161a7a805f2d7794ece07384e6 /lib/gitlab/badge
parent9f0b46c05aef9d0352bfaa5e42e34143227de8ff (diff)
Refactor badge template and metadata classes
Diffstat (limited to 'lib/gitlab/badge')
-rw-r--r--lib/gitlab/badge/base.rb4
-rw-r--r--lib/gitlab/badge/build/metadata.rb6
-rw-r--r--lib/gitlab/badge/build/status.rb11
-rw-r--r--lib/gitlab/badge/build/template.rb12
4 files changed, 19 insertions, 14 deletions
diff --git a/lib/gitlab/badge/base.rb b/lib/gitlab/badge/base.rb
index 229e7b5aa57..909fa24fa90 100644
--- a/lib/gitlab/badge/base.rb
+++ b/lib/gitlab/badge/base.rb
@@ -1,11 +1,11 @@
module Gitlab
module Badge
class Base
- def key_text
+ def entity
raise NotImplementedError
end
- def value_text
+ def status
raise NotImplementedError
end
diff --git a/lib/gitlab/badge/build/metadata.rb b/lib/gitlab/badge/build/metadata.rb
index fbe10b948c4..52a10b19298 100644
--- a/lib/gitlab/badge/build/metadata.rb
+++ b/lib/gitlab/badge/build/metadata.rb
@@ -9,9 +9,9 @@ module Gitlab
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::UrlHelper
- def initialize(project, ref)
- @project = project
- @ref = ref
+ def initialize(badge)
+ @project = badge.project
+ @ref = badge.ref
end
def to_html
diff --git a/lib/gitlab/badge/build/status.rb b/lib/gitlab/badge/build/status.rb
index a72e284d513..50aa45e5406 100644
--- a/lib/gitlab/badge/build/status.rb
+++ b/lib/gitlab/badge/build/status.rb
@@ -5,14 +5,19 @@ module Gitlab
# Build status badge
#
class Status < Badge::Base
- delegate :key_text, :value_text, to: :template
+ attr_reader :project, :ref
def initialize(project, ref)
@project = project
@ref = ref
+
@sha = @project.commit(@ref).try(:sha)
end
+ def entity
+ 'build'
+ end
+
def status
@project.pipelines
.where(sha: @sha, ref: @ref)
@@ -20,11 +25,11 @@ module Gitlab
end
def metadata
- @metadata ||= Build::Metadata.new(@project, @ref)
+ @metadata ||= Build::Metadata.new(self)
end
def template
- @template ||= Build::Template.new(status)
+ @template ||= Build::Template.new(self)
end
end
end
diff --git a/lib/gitlab/badge/build/template.rb b/lib/gitlab/badge/build/template.rb
index 779569d0cd7..f52589ff736 100644
--- a/lib/gitlab/badge/build/template.rb
+++ b/lib/gitlab/badge/build/template.rb
@@ -17,16 +17,17 @@ module Gitlab
unknown: '#9f9f9f'
}
- def initialize(status)
- @status = status
+ def initialize(badge)
+ @entity = badge.entity
+ @status = badge.status
end
def key_text
- 'build'
+ @entity.to_s
end
def value_text
- @status
+ @status.to_s
end
def key_width
@@ -42,8 +43,7 @@ module Gitlab
end
def value_color
- STATUS_COLOR[@status.to_sym] ||
- STATUS_COLOR[:unknown]
+ STATUS_COLOR[@status.to_sym] || STATUS_COLOR[:unknown]
end
def key_text_anchor