Commit 67fe0a17 authored by Alexis Reigel's avatar Alexis Reigel

call Gitlab::Favicon.status in serializer

this ways we can keep the `lib/gitlab/ci/status/*` classes to return the
bare favicon name as it was before.

also the favicon uploader versions are now have the same names as the
stock favicons (+ `favicon_` prefix), which makes working with the
status names easier.
parent 40ffa840
...@@ -39,7 +39,7 @@ module PageLayoutHelper ...@@ -39,7 +39,7 @@ module PageLayoutHelper
end end
def favicon def favicon
Gitlab::Favicon.default Gitlab::Favicon.main
end end
def page_image def page_image
......
...@@ -7,7 +7,7 @@ class StatusEntity < Grape::Entity ...@@ -7,7 +7,7 @@ class StatusEntity < Grape::Entity
expose :details_path expose :details_path
expose :favicon do |status| expose :favicon do |status|
ActionController::Base.helpers.image_path(status.favicon) Gitlab::Favicon.status(status.favicon)
end end
expose :action, if: -> (status, _) { status.has_action? } do expose :action, if: -> (status, _) { status.has_action? } do
......
...@@ -2,19 +2,19 @@ class FaviconUploader < AttachmentUploader ...@@ -2,19 +2,19 @@ class FaviconUploader < AttachmentUploader
include CarrierWave::MiniMagick include CarrierWave::MiniMagick
STATUS_ICON_NAMES = [ STATUS_ICON_NAMES = [
:status_canceled, :favicon_status_canceled,
:status_created, :favicon_status_created,
:status_failed, :favicon_status_failed,
:status_manual, :favicon_status_manual,
:status_not_found, :favicon_status_not_found,
:status_pending, :favicon_status_pending,
:status_running, :favicon_status_running,
:status_skipped, :favicon_status_skipped,
:status_success, :favicon_status_success,
:status_warning :favicon_status_warning
].freeze ].freeze
version :default do version :favicon_main do
process resize_to_fill: [32, 32] process resize_to_fill: [32, 32]
process convert: 'ico' process convert: 'ico'
...@@ -24,7 +24,7 @@ class FaviconUploader < AttachmentUploader ...@@ -24,7 +24,7 @@ class FaviconUploader < AttachmentUploader
end end
STATUS_ICON_NAMES.each do |status_name| STATUS_ICON_NAMES.each do |status_name|
version status_name, from_version: :default do version status_name, from_version: :favicon_main do
process status_favicon: status_name process status_favicon: status_name
def full_filename(filename) def full_filename(filename)
...@@ -41,7 +41,7 @@ class FaviconUploader < AttachmentUploader ...@@ -41,7 +41,7 @@ class FaviconUploader < AttachmentUploader
def status_favicon(status_name) def status_favicon(status_name)
manipulate! do |img| manipulate! do |img|
overlay_path = Rails.root.join("app/assets/images/ci_favicons/overlays/favicon_#{status_name}.png") overlay_path = Rails.root.join("app/assets/images/ci_favicons/overlays/#{status_name}.png")
overlay = MiniMagick::Image.open(overlay_path) overlay = MiniMagick::Image.open(overlay_path)
img.composite(overlay) do |c| img.composite(overlay) do |c|
c.compose 'over' c.compose 'over'
......
...@@ -62,7 +62,7 @@ ...@@ -62,7 +62,7 @@
= f.label :favicon, 'Favicon', class: 'control-label' = f.label :favicon, 'Favicon', class: 'control-label'
.col-sm-10 .col-sm-10
- if @appearance.favicon? - if @appearance.favicon?
= image_tag @appearance.favicon.default.url, class: 'appearance-light-logo-preview' = image_tag @appearance.favicon.favicon_main.url, class: 'appearance-light-logo-preview'
- if @appearance.favicon? - if @appearance.favicon?
= f.label :favicon, 'Generated status icons', class: 'control-label' = f.label :favicon, 'Generated status icons', class: 'control-label'
.col-sm-10 .col-sm-10
......
...@@ -15,7 +15,7 @@ module Gitlab ...@@ -15,7 +15,7 @@ module Gitlab
end end
def favicon def favicon
Gitlab::Favicon.status('canceled') '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
Gitlab::Favicon.status('created') '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
Gitlab::Favicon.status('failed') '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
Gitlab::Favicon.status('manual') '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
Gitlab::Favicon.status('pending') '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
Gitlab::Favicon.status('running') '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
Gitlab::Favicon.status('skipped') '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
Gitlab::Favicon.status('success') 'favicon_status_success'
end end
end end
end end
......
module Gitlab module Gitlab
class Favicon class Favicon
class << self class << self
def default def main
return custom_favicon_url(appearance_favicon.default.url) if appearance_favicon.exists? return custom_favicon_url(appearance_favicon.favicon_main.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?
...@@ -11,13 +11,16 @@ module Gitlab ...@@ -11,13 +11,16 @@ module Gitlab
def status(status_name) def status(status_name)
if appearance_favicon.exists? if appearance_favicon.exists?
custom_favicon_url(appearance_favicon.public_send("status_#{status_name}").url) # rubocop:disable GitlabSecurity/PublicSend custom_favicon_url(appearance_favicon.public_send("#{status_name}").url) # rubocop:disable GitlabSecurity/PublicSend
else else
dir = 'ci_favicons' path = File.join(
dir = File.join(dir, 'dev') if Rails.env.development? 'ci_favicons',
dir = File.join(dir, 'canary') if Gitlab::Utils.to_boolean(ENV['CANARY']) Rails.env.development? ? 'dev' : '',
Gitlab::Utils.to_boolean(ENV['CANARY']) ? 'canary' : '',
"#{status_name}.ico"
)
File.join(dir, "favicon_status_#{status_name}.ico") ActionController::Base.helpers.image_path(path)
end end
end end
......
require 'rails_helper' require 'rails_helper'
RSpec.describe Gitlab::Favicon, :request_store do RSpec.describe Gitlab::Favicon, :request_store do
describe '.default' do describe '.main' do
it 'defaults to favicon.ico' do it 'defaults to favicon.ico' do
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('production')) allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('production'))
expect(described_class.default).to eq 'favicon.ico' expect(described_class.main).to eq 'favicon.ico'
end end
it 'has blue favicon for development' do it 'has blue favicon for development' do
allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('development')) allow(Rails).to receive(:env).and_return(ActiveSupport::StringInquirer.new('development'))
expect(described_class.default).to eq 'favicon-blue.ico' expect(described_class.main).to eq 'favicon-blue.ico'
end end
it 'has yellow favicon for canary' do it 'has yellow favicon for canary' do
stub_env('CANARY', 'true') stub_env('CANARY', 'true')
expect(described_class.favicon).to eq 'favicon-yellow.ico' expect(described_class.main).to eq 'favicon-yellow.ico'
end end
it 'uses the custom favicon if a favicon appearance is present' do 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')) create :appearance, favicon: fixture_file_upload(Rails.root.join('spec/fixtures/dk.png'))
expect(described_class.default).to match %r{/uploads/-/system/appearance/favicon/\d+/default_dk.ico\?} expect(described_class.main).to match %r{/uploads/-/system/appearance/favicon/\d+/favicon_main_dk.ico}
end end
end end
describe '.status' do describe '.status' do
subject { described_class.status('created') } subject { described_class.status('favicon_status_created') }
it 'defaults to the stock icon' do it 'defaults to the stock icon' do
expect(subject).to eq 'ci_favicons/favicon_status_created.ico' expect(subject).to eq '/assets/ci_favicons/favicon_status_created.ico'
end end
it 'uses the custom favicon if a favicon appearance is present' do 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')) 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\?}) expect(subject).to match(%r{/uploads/-/system/appearance/favicon/\d+/favicon_status_created_dk.ico})
end end
end end
end end
...@@ -19,11 +19,11 @@ RSpec.describe FaviconUploader do ...@@ -19,11 +19,11 @@ RSpec.describe FaviconUploader do
end end
it 'has the correct format' do it 'has the correct format' do
expect(uploader.default).to be_format('ico') expect(uploader.favicon_main).to be_format('ico')
end end
it 'has the correct dimensions' do it 'has the correct dimensions' do
expect(uploader.default).to have_dimensions(32, 32) expect(uploader.favicon_main).to have_dimensions(32, 32)
end end
it 'generates all the status icons' do it 'generates all the status icons' do
...@@ -31,7 +31,7 @@ RSpec.describe FaviconUploader do ...@@ -31,7 +31,7 @@ RSpec.describe FaviconUploader do
expect(FaviconUploader::STATUS_ICON_NAMES.count).to eq 10 expect(FaviconUploader::STATUS_ICON_NAMES.count).to eq 10
FaviconUploader::STATUS_ICON_NAMES.each do |status_name| FaviconUploader::STATUS_ICON_NAMES.each do |status_name|
expect(File.exist?(uploader.status_not_found.file.file)).to be true expect(File.exist?(uploader.favicon_status_not_found.file.file)).to be true
end end
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