Commit 9f0b46c0 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Move badges to separate modules and add base class

parent 6f0b5800
...@@ -4,7 +4,7 @@ class Projects::BadgesController < Projects::ApplicationController ...@@ -4,7 +4,7 @@ class Projects::BadgesController < Projects::ApplicationController
before_action :no_cache_headers, except: [:index] before_action :no_cache_headers, except: [:index]
def build def build
badge = Gitlab::Badge::Build.new(project, params[:ref]) badge = Gitlab::Badge::Build::Status.new(project, params[:ref])
respond_to do |format| respond_to do |format|
format.html { render_404 } format.html { render_404 }
......
...@@ -3,7 +3,7 @@ class Projects::PipelinesSettingsController < Projects::ApplicationController ...@@ -3,7 +3,7 @@ class Projects::PipelinesSettingsController < Projects::ApplicationController
def show def show
@ref = params[:ref] || @project.default_branch || 'master' @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 end
def update def update
......
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
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
module Gitlab module Gitlab
module Badge module Badge
class Build module Build
## ##
# Class that describes build badge metadata # Class that describes build badge metadata
# #
......
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
module Gitlab module Gitlab
module Badge module Badge
class Build module Build
## ##
# Class that represents a build badge template. # Class that represents a build badge template.
# #
......
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
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
require 'spec_helper' require 'spec_helper'
describe Gitlab::Badge::Build do describe Gitlab::Badge::Build::Status do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:sha) { project.commit.sha } let(:sha) { project.commit.sha }
let(:branch) { 'master' } let(:branch) { 'master' }
......
require 'spec_helper' require 'spec_helper'
describe Gitlab::Badge::Coverage do describe Gitlab::Badge::Coverage::Report do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:pipeline) do let(:pipeline) do
...@@ -9,11 +9,13 @@ describe Gitlab::Badge::Coverage do ...@@ -9,11 +9,13 @@ describe Gitlab::Badge::Coverage do
ref: 'master') ref: 'master')
end end
let(:badge) { described_class.new(project, 'master') } let(:badge) do
described_class.new(project, 'master')
end
context 'builds exist' do context 'builds exist' do
end end
context 'build does not exist' do context 'builds do not exist' do
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment