From b4117d7c348b63b0af2efa86bbb3b79d582ec1ad Mon Sep 17 00:00:00 2001 From: f Date: Sat, 17 Feb 2024 14:11:17 -0300 Subject: [PATCH] chore: rubocop --- .../api/v1/concerns/webhook_concern.rb | 13 ++++++------ app/models/deploy.rb | 8 ++++---- app/models/deploy_social_distributed_press.rb | 20 +++++++++++-------- app/models/site/social_distributed_press.rb | 3 ++- app/models/social_inbox.rb | 5 +---- 5 files changed, 26 insertions(+), 23 deletions(-) diff --git a/app/controllers/api/v1/concerns/webhook_concern.rb b/app/controllers/api/v1/concerns/webhook_concern.rb index 59d48b28..9960e550 100644 --- a/app/controllers/api/v1/concerns/webhook_concern.rb +++ b/app/controllers/api/v1/concerns/webhook_concern.rb @@ -18,13 +18,14 @@ module Api def token @token ||= begin - _headers = request.headers - _token ||= _headers['X-Gitlab-Token'].presence - _token ||= token_from_signature(_headers['X-Gitea-Signature'].presence) - _token ||= token_from_signature(_headers['X-Hub-Signature-256'].presence, 'sha256=') - _token + header = request.headers + token = header['X-Social-Inbox'].presence + token ||= header['X-Gitlab-Token'].presence + token ||= token_from_signature(header['X-Gitea-Signature'].presence) + token ||= token_from_signature(header['X-Hub-Signature-256'].presence, 'sha256=') + token ensure - raise ActiveRecord::RecordNotFound, 'Proveedor no soportado' if _token.blank? + raise ActiveRecord::RecordNotFound, 'Proveedor no soportado' if token.blank? end end diff --git a/app/models/deploy.rb b/app/models/deploy.rb index 8f28f214..77646034 100644 --- a/app/models/deploy.rb +++ b/app/models/deploy.rb @@ -14,8 +14,8 @@ class Deploy < ApplicationRecord has_many :build_stats, dependent: :destroy - DEPENDENCIES = [] - SOFT_DEPENDENCIES = [] + DEPENDENCIES = [].freeze + SOFT_DEPENDENCIES = [].freeze def deploy(**) raise NotImplementedError @@ -74,7 +74,7 @@ class Deploy < ApplicationRecord 'HOME' => home_dir, 'PATH' => paths.join(':'), 'JEKYLL_ENV' => Rails.env, - 'LANG' => ENV['LANG'], + 'LANG' => ENV.fetch('LANG', nil) }) end @@ -139,7 +139,7 @@ class Deploy < ApplicationRecord # provisto con el archivo como parĂ¡metro # # @param :content [String] - def with_tempfile(content, &block) + def with_tempfile(content) Tempfile.create(SecureRandom.hex) do |file| file.write content.to_s file.rewind diff --git a/app/models/deploy_social_distributed_press.rb b/app/models/deploy_social_distributed_press.rb index f5c38a22..fc0e01d5 100644 --- a/app/models/deploy_social_distributed_press.rb +++ b/app/models/deploy_social_distributed_press.rb @@ -5,7 +5,7 @@ require 'distributed_press/v1/social/client' # Publicar novedades al Fediverso class DeploySocialDistributedPress < Deploy # Solo luego de publicar remotamente - DEPENDENCIES = %i[deploy_distributed_press deploy_rsync deploy_full_rsync] + DEPENDENCIES = %i[deploy_distributed_press deploy_rsync deploy_full_rsync].freeze after_save :create_hooks! @@ -70,17 +70,21 @@ class DeploySocialDistributedPress < Deploy # @return [nil] def create_hooks! hook_client = site.social_inbox.hook + webhook_class = DistributedPress::V1::Social::Schemas::Webhook hook_client.class::EVENTS.each do |event| event_url = :"v1_site_webhooks_social_inbox_#{event}_url" - webhook = DistributedPress::V1::Social::Schemas::Webhook.new.call({ - method: 'POST', - url: Rails.application.routes.url_helpers.public_send(event_url, site_id: site.name, host: api_hostname), - headers: { - 'X-Social-Inbox': rol.token - } - }) + webhook = + webhook_class.new.call({ + method: 'POST', + url: Rails.application.routes.url_helpers.public_send( + event_url, site_id: site.name, host: api_hostname + ), + headers: { + 'X-Social-Inbox': rol.token + } + }) raise ArgumentError, webhook.errors.messages if webhook.failure? diff --git a/app/models/site/social_distributed_press.rb b/app/models/site/social_distributed_press.rb index 1193ca76..d3ebf579 100644 --- a/app/models/site/social_distributed_press.rb +++ b/app/models/site/social_distributed_press.rb @@ -25,7 +25,8 @@ class Site def generate_private_key_pem! self.private_key_pem ||= DistributedPress::V1::Social::Client.new( public_key_url: nil, - key_size: 2048).private_key.export + key_size: 2048 + ).private_key.export end end end diff --git a/app/models/social_inbox.rb b/app/models/social_inbox.rb index 8aa5b504..24f749be 100644 --- a/app/models/social_inbox.rb +++ b/app/models/social_inbox.rb @@ -50,9 +50,6 @@ class SocialInbox def hostname @hostname ||= - begin - host = site.config.dig('activity_pub', 'hostname') - host ||= site.hostname - end + site.config.dig('activity_pub', 'hostname') || site.hostname end end