diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-10 14:12:31 +0200 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-08-15 14:39:46 +0200 |
commit | 9f0b46c05aef9d0352bfaa5e42e34143227de8ff (patch) | |
tree | 546d740aa3c1b21e234a6b5a1b260a31b44ec049 | |
parent | 6f0b5800a92e5a0a9b94a36e013baa6361d638d5 (diff) | |
download | gitlab-ce-9f0b46c05aef9d0352bfaa5e42e34143227de8ff.tar.gz |
Move badges to separate modules and add base class
-rw-r--r-- | app/controllers/projects/badges_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/projects/pipelines_settings_controller.rb | 2 | ||||
-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 | ||||
-rw-r--r-- | spec/lib/gitlab/badge/build/status_spec.rb (renamed from spec/lib/gitlab/badge/build_spec.rb) | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/badge/coverage/report_spec.rb (renamed from spec/lib/gitlab/badge/coverage_spec.rb) | 8 |
11 files changed, 82 insertions, 55 deletions
diff --git a/app/controllers/projects/badges_controller.rb b/app/controllers/projects/badges_controller.rb index d0f5071d2cc..e026ceaf757 100644 --- a/app/controllers/projects/badges_controller.rb +++ b/app/controllers/projects/badges_controller.rb @@ -4,7 +4,7 @@ class Projects::BadgesController < Projects::ApplicationController before_action :no_cache_headers, except: [:index] def build - badge = Gitlab::Badge::Build.new(project, params[:ref]) + badge = Gitlab::Badge::Build::Status.new(project, params[:ref]) respond_to do |format| format.html { render_404 } diff --git a/app/controllers/projects/pipelines_settings_controller.rb b/app/controllers/projects/pipelines_settings_controller.rb index 75dd3648e45..fe7cb748f43 100644 --- a/app/controllers/projects/pipelines_settings_controller.rb +++ b/app/controllers/projects/pipelines_settings_controller.rb @@ -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).metadata + @build_badge = Gitlab::Badge::Build::Status.new(@project, @ref).metadata end def update 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 diff --git a/spec/lib/gitlab/badge/build_spec.rb b/spec/lib/gitlab/badge/build/status_spec.rb index bb8144d5122..fa5bc068918 100644 --- a/spec/lib/gitlab/badge/build_spec.rb +++ b/spec/lib/gitlab/badge/build/status_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Badge::Build do +describe Gitlab::Badge::Build::Status do let(:project) { create(:project) } let(:sha) { project.commit.sha } let(:branch) { 'master' } diff --git a/spec/lib/gitlab/badge/coverage_spec.rb b/spec/lib/gitlab/badge/coverage/report_spec.rb index 343ca3c0f85..57b89dd8cda 100644 --- a/spec/lib/gitlab/badge/coverage_spec.rb +++ b/spec/lib/gitlab/badge/coverage/report_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Gitlab::Badge::Coverage do +describe Gitlab::Badge::Coverage::Report do let(:project) { create(:project) } let(:pipeline) do @@ -9,11 +9,13 @@ describe Gitlab::Badge::Coverage do ref: 'master') end - let(:badge) { described_class.new(project, 'master') } + let(:badge) do + described_class.new(project, 'master') + end context 'builds exist' do end - context 'build does not exist' do + context 'builds do not exist' do end end |