diff --git a/.github/workflows/danger-comment.yml b/.github/workflows/danger-comment.yml new file mode 100644 index 0000000..8e15cb6 --- /dev/null +++ b/.github/workflows/danger-comment.yml @@ -0,0 +1,11 @@ +name: Danger Comment + +on: + workflow_run: + workflows: [Danger] + types: [completed] + +jobs: + comment: + uses: numbata/danger-pr-comment/.github/workflows/danger-comment.yml@v0.1.0 + secrets: inherit diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml index 6288c0a..dfb8ea7 100644 --- a/.github/workflows/danger.yml +++ b/.github/workflows/danger.yml @@ -1,17 +1,13 @@ -name: PR Linter -on: [pull_request] +name: Danger + +on: + pull_request: + types: [opened, reopened, edited, synchronize] + jobs: danger: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: 2.7 - bundler-cache: true - - run: | - # Personal access token for dangerpr-bot - public, but base64 encoded to avoid tripping up GitHub - TOKEN=$(echo -n Z2hwX0xNQ3VmanBFeTBvYkZVTWh6NVNqVFFBOEUxU25abzBqRUVuaAo= | base64 --decode) - DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose \ No newline at end of file + uses: numbata/danger-pr-comment/.github/workflows/danger-run.yml@v0.1.0 + secrets: inherit + with: + ruby-version: '2.7' + bundler-cache: true \ No newline at end of file diff --git a/.rubocop.yml b/.rubocop.yml index 04b2216..ca95924 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,10 @@ AllCops: + NewCops: enable Exclude: - vendor/**/* inherit_from: .rubocop_todo.yml + +require: + - rubocop-rake + - rubocop-rspec \ No newline at end of file diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 82d0159..d40536e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,39 +1,63 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-09-13 14:18:39 -0400 using RuboCop version 0.33.0. +# on 2026-01-02 19:41:49 UTC using RuboCop version 1.36.0. # 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: 20 -# Configuration parameters: AllowURI, URISchemes. -Metrics/LineLength: - Max: 118 - +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec Gemspec/RequiredRubyVersion: Exclude: - 'mongoid-compatibility.gemspec' -Metrics/BlockLength: +# 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: - - 'spec/**/*' - - 'test/**/*' + - 'lib/mongoid-compatibility.rb' -# Offense count: 4 -Style/Documentation: +# Offense count: 1 +# Configuration parameters: Prefixes, AllowedPatterns. +# Prefixes: when, with, without +RSpec/ContextWording: Exclude: - - 'lib/mongoid/compatibility/object_id.rb' - - 'lib/mongoid/compatibility/self.rb' - - 'lib/mongoid/compatibility/version.rb' + - 'spec/mongoid/compatibility/version_spec.rb' + +# Offense count: 18 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: SkipBlocks, EnforcedStyle. +# SupportedStyles: described_class, explicit +RSpec/DescribedClass: + Exclude: + - 'spec/mongoid/compatibility/object_id_spec.rb' + - 'spec/mongoid/compatibility/version_spec.rb' + +# Offense count: 1 +# Configuration parameters: CountAsOne. +RSpec/ExampleLength: + Max: 13 # Offense count: 1 -Style/DoubleNegation: +# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly. +# Include: **/*_spec*rb*, **/spec/**/* +RSpec/FilePath: Exclude: - - 'lib/mongoid/compatibility/version.rb' + - 'spec/mongoid/compatibility/self_spec.rb' # Offense count: 1 -# Configuration parameters: Exclude. -Style/FileName: +RSpec/MultipleExpectations: + Max: 5 + +# Offense count: 3 +# Configuration parameters: AllowedConstants. +Style/Documentation: Exclude: - - 'lib/mongoid-compatibility.rb' + - 'spec/**/*' + - 'test/**/*' + - 'lib/mongoid/compatibility/object_id.rb' + - 'lib/mongoid/compatibility/version.rb' diff --git a/CHANGELOG.md b/CHANGELOG.md index f2b33a1..b08e696 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ### 1.1.0 (Next) * Your contribution here. +* [#21](https://github.com/mongoid/mongoid-compatibility/pull/21): Migrate Danger to use danger-pr-comment workflow - [@dblock](https://github.com/dblock). * [#20](https://github.com/mongoid/mongoid-compatibility/pull/20): Add gem caching to CI - [@saisrinivasan](https://github.com/SairamSrinivasan). ### 1.0.0 (2024/06/19) diff --git a/Dangerfile b/Dangerfile index de2a4a0..f769387 100644 --- a/Dangerfile +++ b/Dangerfile @@ -1,3 +1,5 @@ # frozen_string_literal: true -danger.import_dangerfile(gem: 'mongoid-danger') +danger.import_dangerfile(gem: 'danger-pr-comment') + +changelog.check! diff --git a/Gemfile b/Gemfile index f7200f1..b6fbf3d 100644 --- a/Gemfile +++ b/Gemfile @@ -3,3 +3,9 @@ source 'http://rubygems.org' gemspec + +group :test do + gem 'danger', require: false + gem 'danger-changelog', require: false + gem 'danger-pr-comment', require: false +end diff --git a/mongoid-compatibility.gemspec b/mongoid-compatibility.gemspec index d1a4e0e..4392493 100644 --- a/mongoid-compatibility.gemspec +++ b/mongoid-compatibility.gemspec @@ -19,8 +19,11 @@ Gem::Specification.new do |s| s.add_dependency 'mongoid', '>= 2.0' s.add_development_dependency 'appraisal', '~> 2.0' - s.add_development_dependency 'mongoid-danger', '~> 0.2' - s.add_development_dependency 'rake', '< 12' + s.add_development_dependency 'ostruct' + s.add_development_dependency 'rake' s.add_development_dependency 'rspec' s.add_development_dependency 'rubocop', '~> 1.36.0' + s.add_development_dependency 'rubocop-rake' + s.add_development_dependency 'rubocop-rspec' + s.metadata['rubygems_mfa_required'] = 'true' end diff --git a/spec/mongoid/compatibility/object_id_spec.rb b/spec/mongoid/compatibility/object_id_spec.rb index 1fdfd88..c05ac62 100644 --- a/spec/mongoid/compatibility/object_id_spec.rb +++ b/spec/mongoid/compatibility/object_id_spec.rb @@ -6,6 +6,7 @@ it 'valid' do expect(Mongoid::Compatibility::ObjectId.legal?('4e4d66343b39b68407000001')).to be true end + it 'invalid' do expect(Mongoid::Compatibility::ObjectId.legal?('asadsf')).to be false end diff --git a/spec/mongoid/compatibility/version_spec.rb b/spec/mongoid/compatibility/version_spec.rb index 7307e34..035b1a1 100644 --- a/spec/mongoid/compatibility/version_spec.rb +++ b/spec/mongoid/compatibility/version_spec.rb @@ -9,11 +9,14 @@ Mongoid::Compatibility::Version.send("mongoid#{v}?") end).to be true end + context "current version #{Mongoid::VERSION}" do let(:version) { Mongoid::VERSION.split('.').first.to_i } + it 'mongoidX?' do expect(Mongoid::Compatibility::Version.send("mongoid#{version}?")).to be true end + it 'mongoidX?_or_newer?' do expect(Mongoid::Compatibility::Version.send("mongoid#{version}_or_newer?")).to be true if Mongoid::Compatibility::Version.respond_to?("mongoid#{version - 1}_or_newer?") @@ -29,25 +32,31 @@ expect(Mongoid::Compatibility::Version.send("mongoid#{version + 1}_or_newer?")).to be false end end + it 'mongoidX?_or_older?' do expect(Mongoid::Compatibility::Version.send("mongoid#{version}_or_older?")).to be true end end + (2..9).each do |v| context "mongoid #{v}" do before do stub_const('::Mongoid::VERSION', v.to_s) stub_const("::Mongoid::Compatibility::Version::ClassMethods::V#{v}", 1) end + it "responds to mongoid#{v}?" do expect(Mongoid::Compatibility::Version).to respond_to("mongoid#{v}?") end + it "mongoid#{v}?" do expect(Mongoid::Compatibility::Version.send("mongoid#{v}?")).to be true end + it "mongoid#{v}_or_newer?" do expect(Mongoid::Compatibility::Version.send("mongoid#{v}_or_newer?")).to be true end + it "mongoid#{v}_or_older?" do expect(Mongoid::Compatibility::Version.send("mongoid#{v}_or_older?")).to be true end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 94790a9..9b82ed6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -4,6 +4,7 @@ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) +require 'logger' require 'rubygems' require 'rspec'