Skip to content
Snippets Groups Projects
Unverified Commit 67fe0a17 authored by Alexis Reigel's avatar Alexis Reigel
Browse files

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
No related branches found
No related tags found
No related merge requests found
Showing with 45 additions and 42 deletions
Loading
Loading
@@ -39,7 +39,7 @@ module PageLayoutHelper
end
 
def favicon
Gitlab::Favicon.default
Gitlab::Favicon.main
end
 
def page_image
Loading
Loading
Loading
Loading
@@ -7,7 +7,7 @@ class StatusEntity < Grape::Entity
expose :details_path
 
expose :favicon do |status|
ActionController::Base.helpers.image_path(status.favicon)
Gitlab::Favicon.status(status.favicon)
end
 
expose :action, if: -> (status, _) { status.has_action? } do
Loading
Loading
Loading
Loading
@@ -2,19 +2,19 @@ class FaviconUploader < AttachmentUploader
include CarrierWave::MiniMagick
 
STATUS_ICON_NAMES = [
:status_canceled,
:status_created,
:status_failed,
:status_manual,
:status_not_found,
:status_pending,
:status_running,
:status_skipped,
:status_success,
:status_warning
:favicon_status_canceled,
:favicon_status_created,
:favicon_status_failed,
:favicon_status_manual,
:favicon_status_not_found,
:favicon_status_pending,
:favicon_status_running,
:favicon_status_skipped,
:favicon_status_success,
:favicon_status_warning
].freeze
 
version :default do
version :favicon_main do
process resize_to_fill: [32, 32]
process convert: 'ico'
 
Loading
Loading
@@ -24,7 +24,7 @@ class FaviconUploader < AttachmentUploader
end
 
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
 
def full_filename(filename)
Loading
Loading
@@ -41,7 +41,7 @@ class FaviconUploader < AttachmentUploader
 
def status_favicon(status_name)
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)
img.composite(overlay) do |c|
c.compose 'over'
Loading
Loading
Loading
Loading
@@ -62,7 +62,7 @@
= f.label :favicon, 'Favicon', class: 'control-label'
.col-sm-10
- 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?
= f.label :favicon, 'Generated status icons', class: 'control-label'
.col-sm-10
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ module Gitlab
end
 
def favicon
Gitlab::Favicon.status('canceled')
'favicon_status_canceled'
end
end
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ module Gitlab
end
 
def favicon
Gitlab::Favicon.status('created')
'favicon_status_created'
end
end
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ module Gitlab
end
 
def favicon
Gitlab::Favicon.status('failed')
'favicon_status_failed'
end
end
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ module Gitlab
end
 
def favicon
Gitlab::Favicon.status('manual')
'favicon_status_manual'
end
end
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ module Gitlab
end
 
def favicon
Gitlab::Favicon.status('pending')
'favicon_status_pending'
end
end
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ module Gitlab
end
 
def favicon
Gitlab::Favicon.status('running')
'favicon_status_running'
end
end
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ module Gitlab
end
 
def favicon
Gitlab::Favicon.status('skipped')
'favicon_status_skipped'
end
end
end
Loading
Loading
Loading
Loading
@@ -15,7 +15,7 @@ module Gitlab
end
 
def favicon
Gitlab::Favicon.status('success')
'favicon_status_success'
end
end
end
Loading
Loading
module Gitlab
class Favicon
class << self
def default
return custom_favicon_url(appearance_favicon.default.url) if appearance_favicon.exists?
def main
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-blue.ico' if Rails.env.development?
 
Loading
Loading
@@ -11,13 +11,16 @@ module Gitlab
 
def status(status_name)
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
dir = 'ci_favicons'
dir = File.join(dir, 'dev') if Rails.env.development?
dir = File.join(dir, 'canary') if Gitlab::Utils.to_boolean(ENV['CANARY'])
path = File.join(
'ci_favicons',
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
 
Loading
Loading
require 'rails_helper'
 
RSpec.describe Gitlab::Favicon, :request_store do
describe '.default' do
describe '.main' do
it 'defaults to favicon.ico' do
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
 
it 'has blue favicon for development' do
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
 
it 'has yellow favicon for canary' do
stub_env('CANARY', 'true')
expect(described_class.favicon).to eq 'favicon-yellow.ico'
expect(described_class.main).to eq 'favicon-yellow.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(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
 
describe '.status' do
subject { described_class.status('created') }
subject { described_class.status('favicon_status_created') }
 
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
 
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\?})
expect(subject).to match(%r{/uploads/-/system/appearance/favicon/\d+/favicon_status_created_dk.ico})
end
end
end
Loading
Loading
@@ -19,11 +19,11 @@ RSpec.describe FaviconUploader do
end
 
it 'has the correct format' do
expect(uploader.default).to be_format('ico')
expect(uploader.favicon_main).to be_format('ico')
end
 
it 'has the correct dimensions' do
expect(uploader.default).to have_dimensions(32, 32)
expect(uploader.favicon_main).to have_dimensions(32, 32)
end
 
it 'generates all the status icons' do
Loading
Loading
@@ -31,7 +31,7 @@ RSpec.describe FaviconUploader do
expect(FaviconUploader::STATUS_ICON_NAMES.count).to eq 10
 
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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment