Commit 44d7b158 authored by Alexis Reigel's avatar Alexis Reigel

use custom favicon for ci build status favicons

parent a6f3f6b8
......@@ -7,16 +7,7 @@ class StatusEntity < Grape::Entity
expose :details_path
expose :favicon do |status|
dir =
if Gitlab::Utils.to_boolean(ENV['CANARY'])
File.join('ci_favicons', 'canary')
elsif Rails.env.development?
File.join('ci_favicons', 'dev')
else
'ci_favicons'
end
ActionController::Base.helpers.image_path(File.join(dir, "#{status.favicon}.ico"))
ActionController::Base.helpers.image_path(status.favicon)
end
expose :action, if: -> (status, _) { status.has_action? } do
......
......@@ -15,7 +15,7 @@ module Gitlab
end
def favicon
'favicon_status_canceled'
Gitlab::Favicon.status('canceled')
end
end
end
......
......@@ -15,7 +15,7 @@ module Gitlab
end
def favicon
'favicon_status_created'
Gitlab::Favicon.status('created')
end
end
end
......
......@@ -15,7 +15,7 @@ module Gitlab
end
def favicon
'favicon_status_failed'
Gitlab::Favicon.status('failed')
end
end
end
......
......@@ -15,7 +15,7 @@ module Gitlab
end
def favicon
'favicon_status_manual'
Gitlab::Favicon.status('manual')
end
end
end
......
......@@ -15,7 +15,7 @@ module Gitlab
end
def favicon
'favicon_status_pending'
Gitlab::Favicon.status('pending')
end
end
end
......
......@@ -15,7 +15,7 @@ module Gitlab
end
def favicon
'favicon_status_running'
Gitlab::Favicon.status('running')
end
end
end
......
......@@ -15,7 +15,7 @@ module Gitlab
end
def favicon
'favicon_status_skipped'
Gitlab::Favicon.status('skipped')
end
end
end
......
......@@ -15,7 +15,7 @@ module Gitlab
end
def favicon
'favicon_status_success'
Gitlab::Favicon.status('success')
end
end
end
......
......@@ -2,21 +2,33 @@ module Gitlab
class Favicon
class << self
def default
return appearance_favicon.default.url if appearance_favicon
return appearance_favicon.default.url if appearance_favicon.exists?
return 'favicon-yellow.ico' if Gitlab::Utils.to_boolean(ENV['CANARY'])
return 'favicon-blue.ico' if Rails.env.development?
'favicon.ico'
end
def status(status_name)
if appearance_favicon.exists?
appearance_favicon.public_send("status_#{status_name}").url
else
dir = 'ci_favicons'
dir = File.join(dir, 'dev') if Rails.env.development?
dir = File.join(dir, 'canary') if Gitlab::Utils.to_boolean(ENV['CANARY'])
File.join(dir, "favicon_status_#{status_name}.ico")
end
end
private
def appearance
@appearance ||= Appearance.current
Appearance.current || Appearance.new
end
def appearance_favicon
appearance&.favicon
appearance.favicon
end
end
end
......
......@@ -22,4 +22,17 @@ RSpec.describe Gitlab::Favicon do
expect(described_class.default).to match %r{/uploads/-/system/appearance/favicon/\d+/default_dk.ico}
end
end
describe '.status' do
subject { described_class.status('created') }
it 'defaults to the stock icon' do
expect(subject).to eq 'ci_favicons/favicon_status_created.ico'
end
it 'uses the custom favicon if a favicon appearance is present' do
create :appearance, favicon: fixture_file_upload(Rails.root.join('spec/fixtures/dk.png'))
expect(subject).to match(%r{/uploads/-/system/appearance/favicon/\d+/status_created_dk.ico})
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