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 ...@@ -7,16 +7,7 @@ class StatusEntity < Grape::Entity
expose :details_path expose :details_path
expose :favicon do |status| expose :favicon do |status|
dir = ActionController::Base.helpers.image_path(status.favicon)
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"))
end end
expose :action, if: -> (status, _) { status.has_action? } do expose :action, if: -> (status, _) { status.has_action? } do
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def favicon def favicon
'favicon_status_canceled' Gitlab::Favicon.status('canceled')
end end
end end
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def favicon def favicon
'favicon_status_created' Gitlab::Favicon.status('created')
end end
end end
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def favicon def favicon
'favicon_status_failed' Gitlab::Favicon.status('failed')
end end
end end
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def favicon def favicon
'favicon_status_manual' Gitlab::Favicon.status('manual')
end end
end end
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def favicon def favicon
'favicon_status_pending' Gitlab::Favicon.status('pending')
end end
end end
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def favicon def favicon
'favicon_status_running' Gitlab::Favicon.status('running')
end end
end end
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def favicon def favicon
'favicon_status_skipped' Gitlab::Favicon.status('skipped')
end end
end end
end end
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def favicon def favicon
'favicon_status_success' Gitlab::Favicon.status('success')
end end
end end
end end
......
...@@ -2,21 +2,33 @@ module Gitlab ...@@ -2,21 +2,33 @@ module Gitlab
class Favicon class Favicon
class << self class << self
def default 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-yellow.ico' if Gitlab::Utils.to_boolean(ENV['CANARY'])
return 'favicon-blue.ico' if Rails.env.development? return 'favicon-blue.ico' if Rails.env.development?
'favicon.ico' 'favicon.ico'
end 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 private
def appearance def appearance
@appearance ||= Appearance.current Appearance.current || Appearance.new
end end
def appearance_favicon def appearance_favicon
appearance&.favicon appearance.favicon
end end
end end
end end
......
...@@ -22,4 +22,17 @@ RSpec.describe Gitlab::Favicon do ...@@ -22,4 +22,17 @@ RSpec.describe Gitlab::Favicon do
expect(described_class.default).to match %r{/uploads/-/system/appearance/favicon/\d+/default_dk.ico} expect(described_class.default).to match %r{/uploads/-/system/appearance/favicon/\d+/default_dk.ico}
end end
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 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