Move badges to separate modules and add base class
This commit is contained in:
parent
6f0b5800a9
commit
9f0b46c05a
11 changed files with 82 additions and 55 deletions
|
@ -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 }
|
||||
|
|
|
@ -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
|
||||
|
|
21
lib/gitlab/badge/base.rb
Normal file
21
lib/gitlab/badge/base.rb
Normal file
|
@ -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
|
|
@ -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
|
|
@ -1,6 +1,6 @@
|
|||
module Gitlab
|
||||
module Badge
|
||||
class Build
|
||||
module Build
|
||||
##
|
||||
# Class that describes build badge metadata
|
||||
#
|
||||
|
|
32
lib/gitlab/badge/build/status.rb
Normal file
32
lib/gitlab/badge/build/status.rb
Normal file
|
@ -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
|
|
@ -1,6 +1,6 @@
|
|||
module Gitlab
|
||||
module Badge
|
||||
class Build
|
||||
module Build
|
||||
##
|
||||
# Class that represents a build badge template.
|
||||
#
|
||||
|
|
|
@ -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
|
19
lib/gitlab/badge/coverage/report.rb
Normal file
19
lib/gitlab/badge/coverage/report.rb
Normal file
|
@ -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
|
|
@ -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' }
|
|
@ -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
|
Loading…
Reference in a new issue