From 22e0fc5520d5f047593b46fa5b70920bf9922534 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Thu, 24 Jun 2021 07:05:39 +0000 Subject: [PATCH] Maintenance: Updated to Ruby 2.7.3. --- .github/workflows/ci.yaml | 2 +- .gitlab-ci.yml | 6 +++--- .gitlab/ci/browser-core/api_client_ruby.yml | 1 + .gitlab/ci/pre.yml | 11 ++++++++++ .ruby-version | 2 +- Gemfile | 4 ++-- Gemfile.lock | 16 +++++++------- .../knowledge_base/answers_controller.rb | 2 +- app/controllers/links_controller.rb | 3 +-- app/jobs/checks_kb_client_notification_job.rb | 6 ++---- app/models/channel/email_parser.rb | 4 ++-- .../concerns/checks_client_notification.rb | 3 +-- app/models/cti/log.rb | 2 +- app/models/knowledge_base/search.rb | 2 +- app/models/link.rb | 3 +-- app/models/tag/object.rb | 6 +++--- lib/core_ext/kernel.rb | 21 ------------------- lib/knowledge_base/menu_item_update_action.rb | 2 +- lib/ldap/group.rb | 4 ++-- lib/search_index_backend.rb | 3 +-- .../unit/exchange/folders/id_path_map.rb | 4 ++-- .../common/model/associations/extract.rb | 4 ++-- .../unit/import/zendesk/user/groups.rb | 3 +-- 23 files changed, 49 insertions(+), 65 deletions(-) delete mode 100644 lib/core_ext/kernel.rb diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0356df80d..f3c97a4d6 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -36,7 +36,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.6.6 + ruby-version: 2.7.3 - name: Increase MySQL max_allowed_packet to 1GB (workaround for unknown/missing service option) run: | sudo apt-get install -y mysql-client diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index d183a7b4f..d2b83ad20 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,5 +1,5 @@ default: - image: registry.znuny.com/docker/zammad-ci:stable + image: registry.znuny.com/docker/zammad-ci:test-ruby-3.7 include: - local: '/.gitlab/ci/base.yml' @@ -43,9 +43,9 @@ variables: # Cache gems in between jobs and pipelines # ATTENTION: We use a combination of the Ruby major and minor version number # as a key for the cache to avoid cache growth and incompatibilities between -# the gems. Search hook: 2.6.6 (change it when updating the Ruby version too) +# the gems. Search hook: 2.7.2 (change it when updating the Ruby version too) cache: - key: "centos7ruby266rails6" + key: "centos7ruby273" paths: - vendor/ruby # ATTENTION: This should be a dedicated cache only used in the job "TODO". diff --git a/.gitlab/ci/browser-core/api_client_ruby.yml b/.gitlab/ci/browser-core/api_client_ruby.yml index b26bfc387..caf7c4499 100644 --- a/.gitlab/ci/browser-core/api_client_ruby.yml +++ b/.gitlab/ci/browser-core/api_client_ruby.yml @@ -7,6 +7,7 @@ api_client_ruby: - bundle exec rake zammad:ci:test:start - git clone https://github.com/zammad/zammad-api-client-ruby.git - cd zammad-api-client-ruby + - bundle update --bundler - bundle install -j $(nproc) - bundle exec rspec diff --git a/.gitlab/ci/pre.yml b/.gitlab/ci/pre.yml index 211cd4531..a8f535ad8 100644 --- a/.gitlab/ci/pre.yml +++ b/.gitlab/ci/pre.yml @@ -32,6 +32,17 @@ zeitwerk_check: - bundle exec rake zammad:db:init - bundle exec rails zeitwerk:check +zeitwerk_check: + <<: *template_pre + extends: + - .tags_docker + - .services_postgresql + script: + - bundle install -j $(nproc) --path vendor + - bundle exec ruby script/build/database_config.rb + - bundle exec rake zammad:db:init + - bundle exec rails zeitwerk:check + coffeelint: <<: *template_pre script: diff --git a/.ruby-version b/.ruby-version index 338a5b5d8..2c9b4ef42 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6.6 +2.7.3 diff --git a/Gemfile b/Gemfile index 26af002ce..230ea5810 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' # core - base -ruby '2.6.6' +ruby '2.7.3' gem 'rails', '6.0.4' # core - rails additions @@ -19,7 +19,7 @@ gem 'unicorn', group: :unicorn # core - supported ORMs gem 'activerecord-nulldb-adapter', group: :nulldb -gem 'mysql2', '0.4.10', group: :mysql +gem 'mysql2', group: :mysql gem 'pg', '0.21.0', group: :postgres # core - asynchrous task execution diff --git a/Gemfile.lock b/Gemfile.lock index 167ea955b..1ed5c8687 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -129,7 +129,7 @@ GEM biz (1.8.2) clavius (~> 1.0) tzinfo - bootsnap (1.3.2) + bootsnap (1.5.1) msgpack (~> 1.0) browser (2.5.3) buftok (0.2.0) @@ -296,19 +296,19 @@ GEM memoizable (0.4.2) thread_safe (~> 0.3, >= 0.3.1) method_source (0.9.2) - mime-types (3.2.2) + mime-types (3.3.1) mime-types-data (~> 3.2015) - mime-types-data (3.2019.0331) + mime-types-data (3.2020.1104) mini_mime (1.1.0) mini_portile2 (2.5.3) mini_racer (0.2.9) libv8 (>= 6.9.411) minitest (5.14.4) - msgpack (1.2.4) + msgpack (1.3.3) multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) - mysql2 (0.4.10) + mysql2 (0.5.3) naught (1.1.0) nenv (0.3.0) nestful (1.1.3) @@ -638,7 +638,7 @@ DEPENDENCIES mail! mime-types mini_racer - mysql2 (= 0.4.10) + mysql2 net-ldap oauth2 omniauth-facebook @@ -699,7 +699,7 @@ DEPENDENCIES zendesk_api RUBY VERSION - ruby 2.6.6p146 + ruby 2.7.3p183 BUNDLED WITH - 1.17.3 + 2.2.20 diff --git a/app/controllers/knowledge_base/answers_controller.rb b/app/controllers/knowledge_base/answers_controller.rb index 79720644c..ef4c5ccc7 100644 --- a/app/controllers/knowledge_base/answers_controller.rb +++ b/app/controllers/knowledge_base/answers_controller.rb @@ -75,7 +75,7 @@ class KnowledgeBase::AnswersController < KnowledgeBase::BaseController assets = object.assets({}) - contents = object.translations.map(&:content).compact + contents = object.translations.filter_map(&:content) assets = ApplicationModel::CanAssets.reduce contents, assets render json: { id: object.id, assets: assets }, status: :created diff --git a/app/controllers/links_controller.rb b/app/controllers/links_controller.rb index 1bc6e9851..8140aed8b 100644 --- a/app/controllers/links_controller.rb +++ b/app/controllers/links_controller.rb @@ -12,8 +12,7 @@ class LinksController < ApplicationController ) linked_objects = links - .map { |elem| elem['link_object']&.safe_constantize&.lookup(id: elem['link_object_value']) } - .compact + .filter_map { |elem| elem['link_object']&.safe_constantize&.lookup(id: elem['link_object_value']) } # return result render json: { diff --git a/app/jobs/checks_kb_client_notification_job.rb b/app/jobs/checks_kb_client_notification_job.rb index 3d92c7be5..9e7e58a21 100644 --- a/app/jobs/checks_kb_client_notification_job.rb +++ b/app/jobs/checks_kb_client_notification_job.rb @@ -53,10 +53,8 @@ class ChecksKbClientNotificationJob < ApplicationJob def users_for(permission_suffix) Sessions .sessions - .map { |client_id| Sessions.get(client_id)&.dig(:user, 'id') } - .compact - .map { |user_id| User.find_by(id: user_id) } - .compact + .filter_map { |client_id| Sessions.get(client_id)&.dig(:user, 'id') } + .filter_map { |user_id| User.find_by(id: user_id) } .select { |user| user.permissions? "knowledge_base.#{permission_suffix}" } end diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index 3fedf6ac7..ae388eb76 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -377,7 +377,7 @@ returns def self.sender_attributes(from) if from.is_a?(HashWithIndifferentAccess) - from = SENDER_FIELDS.map { |f| from[f] }.compact + from = SENDER_FIELDS.filter_map { |f| from[f] } .map(&:to_utf8).reject(&:blank?) .partition { |address| address.match?(EMAIL_REGEX) } .flatten.first @@ -743,7 +743,7 @@ process unprocessable_mails (tmp/unprocessable_mail/*.eml) again end # for some broken sm mail clients (X-MimeOLE: Produced By Microsoft Exchange V6.5) - filename ||= file.header[:content_location].to_s.force_encoding('utf-8') + filename ||= file.header[:content_location].to_s.dup.force_encoding('utf-8') file_body = String.new(file.body.to_s) diff --git a/app/models/concerns/checks_client_notification.rb b/app/models/concerns/checks_client_notification.rb index a67556ef3..1eb61dd73 100644 --- a/app/models/concerns/checks_client_notification.rb +++ b/app/models/concerns/checks_client_notification.rb @@ -11,8 +11,7 @@ module ChecksClientNotification end def notify_clients_data(event) - class_name = self.class.name - class_name.gsub!(%r{::}, '') + class_name = self.class.name.gsub(%r{::}, '') { message: { diff --git a/app/models/cti/log.rb b/app/models/cti/log.rb index 8097b9985..0ced08b9d 100644 --- a/app/models/cti/log.rb +++ b/app/models/cti/log.rb @@ -309,7 +309,7 @@ returns .map { |p| p.slice(:from, :to) } .map(&:values).flatten .pluck(:user_id).compact - .map { |user_id| User.lookup(id: user_id) }.compact + .filter_map { |user_id| User.lookup(id: user_id) } .each.with_object({}) { |user, a| user.assets(a) } { diff --git a/app/models/knowledge_base/search.rb b/app/models/knowledge_base/search.rb index 153a3833a..1d9a201b3 100644 --- a/app/models/knowledge_base/search.rb +++ b/app/models/knowledge_base/search.rb @@ -37,7 +37,7 @@ class KnowledgeBase es_response = SearchIndexBackend.search(query, name, options) es_response = search_es_filter(es_response, query, kb_locales, options) if defined? :search_es_filter - es_response.map { |item| lookup(id: item[:id]) }.compact + es_response.filter_map { |item| lookup(id: item[:id]) } end def search_sql(query, kb_locales, options) diff --git a/app/models/link.rb b/app/models/link.rb index c52362215..46bd3c0f2 100644 --- a/app/models/link.rb +++ b/app/models/link.rb @@ -230,8 +230,7 @@ class Link < ApplicationModel def self.reduce_assets(assets, link_references) link_items = link_references - .map { |elem| lookup_linked_object(elem) } - .compact + .filter_map { |elem| lookup_linked_object(elem) } ApplicationModel::CanAssets.reduce(link_items, assets) end diff --git a/app/models/tag/object.rb b/app/models/tag/object.rb index 1f0a8b193..f96992e99 100644 --- a/app/models/tag/object.rb +++ b/app/models/tag/object.rb @@ -12,11 +12,11 @@ lookup by name and create tag item =end def self.lookup_by_name_and_create(name) - name.strip! + lookup = name.strip - tag_object = Tag::Object.lookup(name: name) + tag_object = Tag::Object.lookup(name: lookup) return tag_object if tag_object - Tag::Object.create(name: name) + Tag::Object.create(name: lookup) end end diff --git a/lib/core_ext/kernel.rb b/lib/core_ext/kernel.rb deleted file mode 100644 index 5d6e62f50..000000000 --- a/lib/core_ext/kernel.rb +++ /dev/null @@ -1,21 +0,0 @@ -# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/ - -if Kernel.respond_to?(:open_uri_original_open) - module Kernel - - module_function - - # see: https://github.com/ruby/ruby/pull/1675 - def open(name, *rest, &block) - if name.respond_to?(:open) && name.method(:open).parameters.present? - name.open(*rest, &block) - elsif name.respond_to?(:to_str) && - %r{\A[A-Za-z][A-Za-z0-9+\-.]*://} =~ name && - (uri = URI.parse(name)).respond_to?(:open) - uri.open(*rest, &block) - else - open_uri_original_open(name, *rest, &block) - end - end - end -end diff --git a/lib/knowledge_base/menu_item_update_action.rb b/lib/knowledge_base/menu_item_update_action.rb index 1229006c0..70336d724 100644 --- a/lib/knowledge_base/menu_item_update_action.rb +++ b/lib/knowledge_base/menu_item_update_action.rb @@ -83,7 +83,7 @@ class KnowledgeBase def all_ids_present? old_ids = scope.pluck(:id) - new_ids = @menu_items_data.map { |elem| elem[:id]&.to_i }.compact + new_ids = @menu_items_data.filter_map { |elem| elem[:id]&.to_i } old_ids.sort == new_ids.sort end diff --git a/lib/ldap/group.rb b/lib/ldap/group.rb index 2b0ecd424..dce710e89 100644 --- a/lib/ldap/group.rb +++ b/lib/ldap/group.rb @@ -136,13 +136,13 @@ class Ldap end def group_user_dns_memberuid(entry) - entry[:memberuid].collect do |uid| + entry[:memberuid].filter_map do |uid| dn = nil @ldap.search("(&(uid=#{uid})#{Import::Ldap.config[:user_filter]})", attributes: %w[dn]) do |user| dn = user.dn end dn - end.compact + end end end end diff --git a/lib/search_index_backend.rb b/lib/search_index_backend.rb index 585e40cc6..ba75436f0 100644 --- a/lib/search_index_backend.rb +++ b/lib/search_index_backend.rb @@ -261,8 +261,7 @@ remove whole data from index end index - .map { |local_index| search_by_index(query, local_index, options) } - .compact + .filter_map { |local_index| search_by_index(query, local_index, options) } .flatten(1) end diff --git a/lib/sequencer/unit/exchange/folders/id_path_map.rb b/lib/sequencer/unit/exchange/folders/id_path_map.rb index 33b303a58..fc66a9a73 100644 --- a/lib/sequencer/unit/exchange/folders/id_path_map.rb +++ b/lib/sequencer/unit/exchange/folders/id_path_map.rb @@ -16,13 +16,13 @@ class Sequencer ids = ews_folder_ids ids ||= [] - ews_folder.id_folder_map.collect do |id, folder| + ews_folder.id_folder_map.filter_map do |id, folder| next if ids.present? && ids.exclude?(id) next if folder.total_count.blank? next if folder.total_count.zero? [id, ews_folder.display_path(folder)] - end.compact.to_h + end.to_h end end end diff --git a/lib/sequencer/unit/import/common/model/associations/extract.rb b/lib/sequencer/unit/import/common/model/associations/extract.rb index c900f132b..567671953 100644 --- a/lib/sequencer/unit/import/common/model/associations/extract.rb +++ b/lib/sequencer/unit/import/common/model/associations/extract.rb @@ -16,7 +16,7 @@ class Sequencer def process state.provide(:associations) do - associations.collect do |association| + associations.filter_map do |association| logger.debug { "Checking association '#{association}'" } next if !mapped.key?(association) @@ -30,7 +30,7 @@ class Sequencer logger.debug { "Using value of association '#{association}'" } [association, value] - end.compact.to_h + end.to_h end end diff --git a/lib/sequencer/unit/import/zendesk/user/groups.rb b/lib/sequencer/unit/import/zendesk/user/groups.rb index 697adc766..f2c027bb6 100644 --- a/lib/sequencer/unit/import/zendesk/user/groups.rb +++ b/lib/sequencer/unit/import/zendesk/user/groups.rb @@ -12,8 +12,7 @@ class Sequencer private def groups - remote_ids.map { |remote_id| group_map[remote_id] } - .compact + remote_ids.filter_map { |remote_id| group_map[remote_id] } .map { |local_id| ::Group.find(local_id) } end