Commit 7b840c84 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add coverage report badge metadata class

parent cdb0caaf
...@@ -869,7 +869,10 @@ Rails.application.routes.draw do ...@@ -869,7 +869,10 @@ Rails.application.routes.draw do
resources :badges, only: [:index] do resources :badges, only: [:index] do
collection do collection do
scope '*ref', constraints: { ref: Gitlab::Regex.git_reference_regex } do scope '*ref', constraints: { ref: Gitlab::Regex.git_reference_regex } do
get :build, constraints: { format: /svg/ } constraints format: /svg/ do
get :build
get :coverage
end
end end
end end
end end
......
module Gitlab
module Badge
module Coverage
##
# Class that describes coverage badge metadata
#
class Metadata
include Gitlab::Application.routes.url_helpers
include ActionView::Helpers::AssetTagHelper
include ActionView::Helpers::UrlHelper
def initialize(badge)
@project = badge.project
@ref = badge.ref
@job = badge.job
end
def to_html
link_to(image_tag(image_url, alt: 'coverage report'), link_url)
end
def to_markdown
"[![coverage report](#{image_url})](#{link_url})"
end
def image_url
coverage_namespace_project_badges_url(@project.namespace,
@project, @ref,
format: :svg)
end
def link_url
namespace_project_commits_url(@project.namespace, @project, id: @ref)
end
end
end
end
end
require 'spec_helper'
require 'lib/gitlab/badge/shared/metadata'
describe Gitlab::Badge::Coverage::Metadata do
let(:badge) do
double(project: create(:project), ref: 'feature', job: 'test')
end
let(:metadata) { described_class.new(badge) }
it_behaves_like 'badge metadata'
describe '#image_url' do
it 'returns valid url' do
expect(metadata.image_url).to include 'badges/feature/coverage.svg'
end
end
describe '#link_url' do
it 'returns valid link' do
expect(metadata.link_url).to include 'commits/feature'
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