From a589c8f5b99dbfac3354e93f85c56230d388f002 Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Mon, 22 Sep 2025 09:14:42 -0400 Subject: [PATCH 1/2] Avoid running bundle install twice. --- .github/workflows/danger.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index 6fffc33..65d16f8 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -4,6 +4,8 @@ on: [pull_request] jobs: danger: runs-on: ubuntu-latest + env: + BUNDLE_GEMFILE: Gemfile.danger steps: - uses: actions/checkout@v2 with: @@ -11,13 +13,10 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.6 + ruby-version: 2.7 bundler-cache: true - name: Run Danger - env: - BUNDLE_GEMFILE: Gemfile.danger run: | - bundle install # the personal token is public, this is ok, base64 encode to avoid tripping Github TOKEN=$(echo -n Z2hwX0xNQ3VmanBFeTBvYkZVTWh6NVNqVFFBOEUxU25abzBqRUVuaAo= | base64 --decode) DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose From ab40f190afab5066f0d13c656a179f1aab51f16c Mon Sep 17 00:00:00 2001 From: "Daniel (dB.) Doubrovkine" Date: Mon, 22 Sep 2025 09:20:08 -0400 Subject: [PATCH 2/2] Upgraded RuboCop to 1.80.2. --- .github/workflows/rubocop.yml | 2 +- .github/workflows/test-mongodb.yml | 9 ++- .github/workflows/test-postgresql.yml | 9 ++- .rubocop.yml | 7 +++ .rubocop_todo.yml | 60 ++++++++++++++++++- CHANGELOG.md | 5 +- Gemfile | 13 ++-- LICENSE | 2 +- README.md | 2 +- Rakefile | 2 +- lib/slack-ruby-bot-server-events/config.rb | 2 +- .../requests/request.rb | 2 +- lib/slack-ruby-bot-server-events/version.rb | 2 +- lib/slack-ruby-bot-server/api/endpoints.rb | 16 +++-- slack-ruby-bot-server-events.gemspec | 1 + .../activerecord/activerecord.rb | 4 +- spec/database_adapters/mongoid/mongoid.rb | 2 +- .../config_spec.rb | 6 +- .../version_spec.rb | 2 +- spec/spec_helper.rb | 2 + 20 files changed, 113 insertions(+), 37 deletions(-) diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml index c027bc7..34b133f 100644 --- a/.github/workflows/rubocop.yml +++ b/.github/workflows/rubocop.yml @@ -10,7 +10,7 @@ jobs: - name: Set up Ruby uses: ruby/setup-ruby@v1 with: - ruby-version: 2.7 + ruby-version: 3.4 bundler-cache: true - name: Run RuboCop run: bundle exec rubocop diff --git a/.github/workflows/test-mongodb.yml b/.github/workflows/test-mongodb.yml index c92b6bf..ddbc2f5 100644 --- a/.github/workflows/test-mongodb.yml +++ b/.github/workflows/test-mongodb.yml @@ -7,9 +7,12 @@ jobs: strategy: matrix: entry: - - { ruby: 2.6.2, mongoid: 6.4.8, mongodb: 4.4 } - - { ruby: 2.6.2, mongoid: 7.3.0, mongodb: 5.0 } - - { ruby: 3.1.1, mongoid: 7.3.0, mongodb: 5.0 } + - { ruby: 3.1, mongoid: 6.4.8, mongodb: 4.4 } + - { ruby: 3.1, mongoid: 7.3.0, mongodb: 5.0 } + - { ruby: 3.1, mongoid: 7.3.0, mongodb: 5.0 } + - { ruby: 3.2, mongoid: 8.1.11, mongodb: 6.0 } + - { ruby: 3.4, mongoid: 8.1.11, mongodb: 7.0 } + - { ruby: 3.4, mongoid: 9.0.8, mongodb: 8.0 } name: test (ruby=${{ matrix.entry.ruby }}, mongoid=${{ matrix.entry.mongoid }}, mongodb=${{ matrix.entry.mongodb }}) steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/test-postgresql.yml b/.github/workflows/test-postgresql.yml index 9a80bb8..99762a5 100644 --- a/.github/workflows/test-postgresql.yml +++ b/.github/workflows/test-postgresql.yml @@ -7,9 +7,12 @@ jobs: strategy: matrix: entry: - - { ruby: 2.6.2, postgresql: 11 } - - { ruby: 2.6.2, postgresql: 14 } - - { ruby: 3.1.1, postgresql: 14 } + - { ruby: 3.1, postgresql: 11 } + - { ruby: 3.1, postgresql: 14 } + - { ruby: 3.1, postgresql: 14 } + - { ruby: 3.2, postgresql: 15 } + - { ruby: 3.3, postgresql: 16 } + - { ruby: 3.4, postgresql: 17 } name: test (ruby=${{ matrix.entry.ruby }}, postgresql=${{ matrix.entry.postgresql }}) services: postgres: diff --git a/.rubocop.yml b/.rubocop.yml index 26ff349..06b4c83 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +AllCops: + NewCops: enable + Metrics: Enabled: false @@ -11,5 +14,9 @@ Style/Documentation: Style/ModuleFunction: EnforcedStyle: extend_self +plugins: + - rubocop-rake + - rubocop-rspec + inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9978767..f2eec74 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,20 +1,74 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-07-19 23:46:20 -0400 using RuboCop version 0.81.0. +# on 2025-09-22 13:18:33 UTC using RuboCop version 1.80.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 1 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# Configuration parameters: Severity. +Gemspec/RequiredRubyVersion: + Exclude: + - 'slack-ruby-bot-server-events.gemspec' + +# Offense count: 1 +# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# CheckDefinitionPathHierarchyRoots: lib, spec, test, src # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS Naming/FileName: Exclude: + - 'Rakefile.rb' - 'lib/slack-ruby-bot-server-events.rb' +# Offense count: 7 +RSpec/AnyInstance: + Exclude: + - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/actions_endpoint_spec.rb' + - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/commands_endpoint_spec.rb' + - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/events_endpoint_spec.rb' + +# Offense count: 2 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: + Exclude: + - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/actions_endpoint_spec.rb' + +# Offense count: 3 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 9 + +# Offense count: 22 +RSpec/MultipleExpectations: + Max: 2 + +# Offense count: 5 +# Configuration parameters: AllowedGroups. +RSpec/NestedGroups: + Max: 5 + +# Offense count: 5 +# Configuration parameters: CustomTransform, IgnoreMethods, IgnoreMetadata. +RSpec/SpecFilePathFormat: + Exclude: + - '**/spec/routing/**/*' + - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/actions_endpoint_spec.rb' + - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/commands_endpoint_spec.rb' + - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/events_endpoint_spec.rb' + - 'spec/slack-ruby-bot-server-events/config_spec.rb' + - 'spec/slack-ruby-bot-server-events/version_spec.rb' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/GlobalStdStream: + Exclude: + - 'spec/database_adapters/activerecord/activerecord.rb' + # Offense count: 1 -# Configuration parameters: MinBodyLength. +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: MinBodyLength, AllowConsecutiveConditionals. Style/GuardClause: Exclude: - 'spec/slack-ruby-bot-server-events/api/endpoints/slack/events_endpoint_spec.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ab6a1b..ba1a6d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ ### Changelog -#### 0.3.3 (Next) +#### 0.4.0 (Next) -* Your contribution here. * [#18](https://github.com/slack-ruby/slack-ruby-bot-server-events/pull/18): Use pagy_cursor in place of cursor_pagination - [@duffn](https://github.com/duffn). +* [#26](https://github.com/slack-ruby/slack-ruby-bot-server-events/pull/26): Upgraded RuboCop to 1.80.2 - [@dblock](https://github.com/dblock). +* Your contribution here. #### 0.3.2 (2022/06/09) diff --git a/Gemfile b/Gemfile index b92e38f..85e75de 100644 --- a/Gemfile +++ b/Gemfile @@ -2,12 +2,13 @@ source 'https://rubygems.org' -case ENV['DATABASE_ADAPTER'] -when 'mongoid' then +case ENV.fetch('DATABASE_ADAPTER', nil) +when 'mongoid' gem 'kaminari-mongoid' gem 'mongoid', ENV['MONGOID_VERSION'] || '~> 7.3.0' gem 'mongoid-scroll' -when 'activerecord' then + gem 'mutex_m' +when 'activerecord' gem 'activerecord' gem 'otr-activerecord' gem 'pagy_cursor' @@ -16,7 +17,7 @@ when 'activerecord' then when nil warn "Missing ENV['DATABASE_ADAPTER']." else - warn "Invalid ENV['DATABASE_ADAPTER']: #{ENV['DATABASE_ADAPTER']}." + warn "Invalid ENV['DATABASE_ADAPTER']: #{ENV.fetch('DATABASE_ADAPTER', nil)}." end gemspec @@ -30,7 +31,9 @@ group :development, :test do gem 'rack-test' gem 'rake' gem 'rspec' - gem 'rubocop', '0.81.0' + gem 'rubocop', '1.80.2' + gem 'rubocop-rake' + gem 'rubocop-rspec' gem 'vcr' gem 'webmock' end diff --git a/LICENSE b/LICENSE index 7042ec7..abdf9a8 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2020 Daniel Doubrovkine & Contributors +Copyright (c) 2020-2025 Daniel Doubrovkine & Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index a55a689..3e3a786 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,6 @@ end ### Copyright & License -Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2020 +Copyright [Daniel Doubrovkine](http://code.dblock.org) and Contributors, 2020-2025 [MIT License](LICENSE) diff --git a/Rakefile b/Rakefile index 88b4e3a..c64d80e 100644 --- a/Rakefile +++ b/Rakefile @@ -7,7 +7,7 @@ require 'rspec/core' require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) do |spec| - spec.pattern = FileList['spec/**/*_spec.rb'].exclude(%r{ext\/(?!#{ENV['DATABASE_ADAPTER']})}) + spec.pattern = FileList['spec/**/*_spec.rb'].exclude(%r{ext/(?!#{ENV.fetch('DATABASE_ADAPTER', nil)})}) end require 'rubocop/rake_task' diff --git a/lib/slack-ruby-bot-server-events/config.rb b/lib/slack-ruby-bot-server-events/config.rb index e5d8a1f..25c6d7c 100644 --- a/lib/slack-ruby-bot-server-events/config.rb +++ b/lib/slack-ruby-bot-server-events/config.rb @@ -15,7 +15,7 @@ module Config def reset! self.callbacks = Hash.new { |h, k| h[k] = [] } - self.signing_secret = ENV['SLACK_SIGNING_SECRET'] + self.signing_secret = ENV.fetch('SLACK_SIGNING_SECRET', nil) self.signature_expires_in = 5 * 60 on :event, 'url_verification' do |event| diff --git a/lib/slack-ruby-bot-server-events/requests/request.rb b/lib/slack-ruby-bot-server-events/requests/request.rb index 8b6695e..6ee8532 100644 --- a/lib/slack-ruby-bot-server-events/requests/request.rb +++ b/lib/slack-ruby-bot-server-events/requests/request.rb @@ -8,7 +8,7 @@ class Request < ActiveSupport::HashWithIndifferentAccess def initialize(params, request) @request = request - super params + super(params) end def logger diff --git a/lib/slack-ruby-bot-server-events/version.rb b/lib/slack-ruby-bot-server-events/version.rb index 1254048..f742d98 100644 --- a/lib/slack-ruby-bot-server-events/version.rb +++ b/lib/slack-ruby-bot-server-events/version.rb @@ -2,6 +2,6 @@ module SlackRubyBotServer module Events - VERSION = '0.3.3' + VERSION = '0.4.0' end end diff --git a/lib/slack-ruby-bot-server/api/endpoints.rb b/lib/slack-ruby-bot-server/api/endpoints.rb index d4ea51c..2c15cd0 100644 --- a/lib/slack-ruby-bot-server/api/endpoints.rb +++ b/lib/slack-ruby-bot-server/api/endpoints.rb @@ -8,15 +8,13 @@ class RootEndpoint format :json before do - begin - ::Slack::Events::Request.new( - request, - signing_secret: SlackRubyBotServer::Events.config.signing_secret, - signature_expires_in: SlackRubyBotServer::Events.config.signature_expires_in - ).verify! - rescue ::Slack::Events::Request::TimestampExpired - error!('Invalid Signature', 403) - end + ::Slack::Events::Request.new( + request, + signing_secret: SlackRubyBotServer::Events.config.signing_secret, + signature_expires_in: SlackRubyBotServer::Events.config.signature_expires_in + ).verify! + rescue ::Slack::Events::Request::TimestampExpired + error!('Invalid Signature', 403) end mount SlackRubyBotServer::Events::Api::Endpoints::Slack::CommandsEndpoint diff --git a/slack-ruby-bot-server-events.gemspec b/slack-ruby-bot-server-events.gemspec index e87065c..a3968ff 100644 --- a/slack-ruby-bot-server-events.gemspec +++ b/slack-ruby-bot-server-events.gemspec @@ -17,4 +17,5 @@ Gem::Specification.new do |spec| spec.require_paths = ['lib'] spec.add_dependency 'slack-ruby-bot-server', '>= 0.12.0' + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/spec/database_adapters/activerecord/activerecord.rb b/spec/database_adapters/activerecord/activerecord.rb index 4b08490..38f9202 100644 --- a/spec/database_adapters/activerecord/activerecord.rb +++ b/spec/database_adapters/activerecord/activerecord.rb @@ -2,9 +2,9 @@ yml = ERB.new(File.read(File.expand_path('postgresql.yml', __dir__))).result db_config = if Gem::Version.new(Psych::VERSION) >= Gem::Version.new('3.1.0.pre1') - ::YAML.safe_load(yml, aliases: true)[ENV['RACK_ENV']] + YAML.safe_load(yml, aliases: true)[ENV.fetch('RACK_ENV', nil)] else - ::YAML.safe_load(yml, [], [], true)[ENV['RACK_ENV']] + YAML.safe_load(yml, [], [], true)[ENV.fetch('RACK_ENV', nil)] end ActiveRecord::Tasks::DatabaseTasks.create(db_config) ActiveRecord::Base.establish_connection(db_config) diff --git a/spec/database_adapters/mongoid/mongoid.rb b/spec/database_adapters/mongoid/mongoid.rb index 8c373d4..bd07a77 100644 --- a/spec/database_adapters/mongoid/mongoid.rb +++ b/spec/database_adapters/mongoid/mongoid.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true Mongo::Logger.logger.level = Logger::INFO -Mongoid.load!(File.expand_path('mongoid.yml', __dir__), ENV['RACK_ENV']) +Mongoid.load!(File.expand_path('mongoid.yml', __dir__), ENV.fetch('RACK_ENV', nil)) diff --git a/spec/slack-ruby-bot-server-events/config_spec.rb b/spec/slack-ruby-bot-server-events/config_spec.rb index 29f2897..13d48ef 100644 --- a/spec/slack-ruby-bot-server-events/config_spec.rb +++ b/spec/slack-ruby-bot-server-events/config_spec.rb @@ -6,15 +6,18 @@ it 'defaults signature_expires_in' do expect(SlackRubyBotServer::Events.config.signature_expires_in).to eq 300 end + context 'with ENV[SLACK_SIGNING_SECRET] set' do before do - allow(ENV).to receive(:[]) { |k| "#{k} was set" } + allow(ENV).to receive(:fetch) { |k| "#{k} was set" } SlackRubyBotServer::Events.config.reset! end + it 'sets signing_secret' do expect(SlackRubyBotServer::Events.config.signing_secret).to eq 'SLACK_SIGNING_SECRET was set' end end + %i[ signing_secret signature_expires_in @@ -25,6 +28,7 @@ config.send("#{k}=", 'set') end end + it "sets and returns #{k}" do expect(SlackRubyBotServer::Events.config.send(k)).to eq 'set' end diff --git a/spec/slack-ruby-bot-server-events/version_spec.rb b/spec/slack-ruby-bot-server-events/version_spec.rb index 121a911..69c17a0 100644 --- a/spec/slack-ruby-bot-server-events/version_spec.rb +++ b/spec/slack-ruby-bot-server-events/version_spec.rb @@ -4,6 +4,6 @@ describe SlackRubyBotServer::Events do it 'has a version' do - expect(SlackRubyBotServer::Events::VERSION).to_not be nil + expect(SlackRubyBotServer::Events::VERSION).not_to be_nil end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ffa6230..467e472 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,6 +3,8 @@ ENV['RACK_ENV'] = 'test' ENV['DATABASE_ADAPTER'] ||= 'mongoid' +require 'logger' + Bundler.require require 'rack/test'