diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-10 15:12:31 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-15 15:39:46 +0300 |
commit | 9f0b46c05aef9d0352bfaa5e42e34143227de8ff (patch) | |
tree | 546d740aa3c1b21e234a6b5a1b260a31b44ec049 /lib | |
parent | 6f0b5800a92e5a0a9b94a36e013baa6361d638d5 (diff) |
Move badges to separate modules and add base class
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/badge/base.rb | 21 | ||||
-rw-r--r-- | lib/gitlab/badge/build.rb | 30 | ||||
-rw-r--r-- | lib/gitlab/badge/build/metadata.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/badge/build/status.rb | 32 | ||||
-rw-r--r-- | lib/gitlab/badge/build/template.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/badge/coverage.rb | 17 | ||||
-rw-r--r-- | lib/gitlab/badge/coverage/report.rb | 19 |
7 files changed, 74 insertions, 49 deletions
diff --git a/lib/gitlab/badge/base.rb b/lib/gitlab/badge/base.rb new file mode 100644 index 00000000000..229e7b5aa57 --- /dev/null +++ b/lib/gitlab/badge/base.rb @@ -0,0 +1,21 @@ +module Gitlab + module Badge + class Base + def key_text + raise NotImplementedError + end + + def value_text + raise NotImplementedError + end + + def metadata + raise NotImplementedError + end + + def template + raise NotImplementedError + end + end + end +end diff --git a/lib/gitlab/badge/build.rb b/lib/gitlab/badge/build.rb deleted file mode 100644 index 1de721a2269..00000000000 --- a/lib/gitlab/badge/build.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Gitlab - module Badge - ## - # Build badge - # - class Build - delegate :key_text, :value_text, to: :template - - def initialize(project, ref) - @project = project - @ref = ref - @sha = @project.commit(@ref).try(:sha) - end - - def status - @project.pipelines - .where(sha: @sha, ref: @ref) - .status || 'unknown' - end - - def metadata - @metadata ||= Build::Metadata.new(@project, @ref) - end - - def template - @template ||= Build::Template.new(status) - end - end - end -end diff --git a/lib/gitlab/badge/build/metadata.rb b/lib/gitlab/badge/build/metadata.rb index 553ef8d7b16..fbe10b948c4 100644 --- a/lib/gitlab/badge/build/metadata.rb +++ b/lib/gitlab/badge/build/metadata.rb @@ -1,6 +1,6 @@ module Gitlab module Badge - class Build + module Build ## # Class that describes build badge metadata # diff --git a/lib/gitlab/badge/build/status.rb b/lib/gitlab/badge/build/status.rb new file mode 100644 index 00000000000..a72e284d513 --- /dev/null +++ b/lib/gitlab/badge/build/status.rb @@ -0,0 +1,32 @@ +module Gitlab + module Badge + module Build + ## + # Build status badge + # + class Status < Badge::Base + delegate :key_text, :value_text, to: :template + + def initialize(project, ref) + @project = project + @ref = ref + @sha = @project.commit(@ref).try(:sha) + end + + def status + @project.pipelines + .where(sha: @sha, ref: @ref) + .status || 'unknown' + end + + def metadata + @metadata ||= Build::Metadata.new(@project, @ref) + end + + def template + @template ||= Build::Template.new(status) + end + end + end + end +end diff --git a/lib/gitlab/badge/build/template.rb b/lib/gitlab/badge/build/template.rb index deba3b669b3..779569d0cd7 100644 --- a/lib/gitlab/badge/build/template.rb +++ b/lib/gitlab/badge/build/template.rb @@ -1,6 +1,6 @@ module Gitlab module Badge - class Build + module Build ## # Class that represents a build badge template. # diff --git a/lib/gitlab/badge/coverage.rb b/lib/gitlab/badge/coverage.rb deleted file mode 100644 index 94af3a7ec34..00000000000 --- a/lib/gitlab/badge/coverage.rb +++ /dev/null @@ -1,17 +0,0 @@ -module Gitlab - module Badge - ## - # Test coverage badge - # - class Coverage - def initialize(project, ref, job = nil) - @project = project - @ref = ref - @job = job - end - - def coverage - end - end - end -end diff --git a/lib/gitlab/badge/coverage/report.rb b/lib/gitlab/badge/coverage/report.rb new file mode 100644 index 00000000000..e6de15e085f --- /dev/null +++ b/lib/gitlab/badge/coverage/report.rb @@ -0,0 +1,19 @@ +module Gitlab + module Badge + module Coverage + ## + # Test coverage report badge + # + class Report < Badge::Base + def initialize(project, ref, job = nil) + @project = project + @ref = ref + @job = job + end + + def coverage + end + end + end + end +end |