From e9dd398ebfa1e31888af3df679c191aaf7498f12 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 00:04:45 +0200 Subject: [PATCH 01/24] Add faraday-retry as dependency --- Gemfile.lock | 3 +++ errbit_github_plugin.gemspec | 1 + 2 files changed, 4 insertions(+) diff --git a/Gemfile.lock b/Gemfile.lock index 687435e..d2a8d72 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,6 +3,7 @@ PATH specs: errbit_github_plugin (0.4.0) errbit_plugin + faraday-retry octokit GEM @@ -39,6 +40,8 @@ GEM logger faraday-net_http (3.4.0) net-http (>= 0.5.0) + faraday-retry (2.3.1) + faraday (~> 2.0) i18n (1.14.7) concurrent-ruby (~> 1.0) json (2.10.2) diff --git a/errbit_github_plugin.gemspec b/errbit_github_plugin.gemspec index 4c39511..6ba860d 100644 --- a/errbit_github_plugin.gemspec +++ b/errbit_github_plugin.gemspec @@ -20,6 +20,7 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib"] spec.add_dependency "errbit_plugin" + spec.add_dependency "faraday-retry" spec.add_dependency "octokit" spec.add_development_dependency "rspec" From 516091eadee9f2b0c62ff42c6e57d952a443975c Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 00:08:39 +0200 Subject: [PATCH 02/24] Configure simplecov --- spec/spec_helper.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 05f63c8..cd28342 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,6 +6,8 @@ enable_coverage :branch primary_coverage :branch + + add_filter "spec/" end require "errbit_plugin" From c29ebd8784ccf40303c5dbb7d9b1a615c2c8fe24 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 00:45:39 +0200 Subject: [PATCH 03/24] Load only blank from active support --- spec/spec_helper.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index cd28342..b655912 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,7 +12,7 @@ require "errbit_plugin" require "errbit_github_plugin" -require "active_support/all" +require "active_support/core_ext/object/blank" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure From ebc28242497f1ee9bb034c6c15e2dd4910f5de06 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 00:45:50 +0200 Subject: [PATCH 04/24] Cleanup --- .../issue_tracker_spec.rb | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/spec/errbit_github_plugin/issue_tracker_spec.rb b/spec/errbit_github_plugin/issue_tracker_spec.rb index 921fb7d..dffc0c6 100644 --- a/spec/errbit_github_plugin/issue_tracker_spec.rb +++ b/spec/errbit_github_plugin/issue_tracker_spec.rb @@ -4,20 +4,25 @@ RSpec.describe ErrbitGithubPlugin::IssueTracker do describe ".label" do - it "return LABEL" do - expect(described_class.label).to eq described_class::LABEL - end + it { expect(described_class.label).to eq("github") } end describe ".note" do - it "return NOTE" do - expect(described_class.note).to eq described_class::NOTE - end + it { expect(described_class.note).to start_with("Please configure your GitHub") } end describe ".fields" do - it "return FIELDS" do - expect(described_class.fields).to eq described_class::FIELDS + it do + expect(described_class.fields).to eq( + { + username: { + placeholder: "Your username on GitHub" + }, + password: { + placeholder: "Password for your account" + } + } + ) end end @@ -55,7 +60,7 @@ end context "without errors" do let(:options) do - {username: "foo", password: "bar", github_repo: "user/repos"} + {username: "foo", password: "bar", github_repo: "user/repository"} end it "return true" do expect(tracker.configured?).to eq true @@ -105,14 +110,17 @@ describe "#create_issue" do subject { tracker.create_issue("title", "body", user: user) } + let(:options) do {username: "foo", password: "bar", github_repo: "user/repos"} end + let(:fake_github_client) do double("Fake GitHub Client").tap do |github_client| expect(github_client).to receive(:create_issue).and_return(fake_issue) end end + let(:fake_issue) do double("Fake Issue").tap do |issue| expect(issue).to receive(:html_url).and_return("http://github.com/user/repos/issues/878").twice @@ -126,20 +134,24 @@ "github_oauth_token" => "valid_token" } end + it "return issue url" do expect(Octokit::Client).to receive(:new).with( login: user["github_login"], access_token: user["github_oauth_token"] ).and_return(fake_github_client) + expect(subject).to eq fake_issue.html_url end end context "signed in with password" do let(:user) { {} } + it "return issue url" do expect(Octokit::Client).to receive(:new).with( login: options["username"], password: options["password"] ).and_return(fake_github_client) + expect(subject).to eq fake_issue.html_url end end @@ -148,10 +160,12 @@ let(:user) do {"github_login" => "alice", "github_oauth_token" => "invalid_token"} end + it "raise AuthenticationError" do expect(Octokit::Client).to receive(:new).with( login: user["github_login"], access_token: user["github_oauth_token"] ).and_raise(Octokit::Unauthorized) + expect { subject }.to raise_error(ErrbitGithubPlugin::AuthenticationError) end end From 6023842f0a52a48b9e33a6f3407b749e38599349 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 00:56:44 +0200 Subject: [PATCH 05/24] Fix dependencies --- Gemfile | 2 ++ Gemfile.lock | 2 +- errbit_github_plugin.gemspec | 5 +---- lib/errbit_github_plugin/issue_tracker.rb | 1 + spec/spec_helper.rb | 1 - 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index d910056..0782b7e 100644 --- a/Gemfile +++ b/Gemfile @@ -4,5 +4,7 @@ source "https://rubygems.org" gemspec +gem "rake" +gem "rspec" gem "simplecov", require: false gem "standard" diff --git a/Gemfile.lock b/Gemfile.lock index d2a8d72..bdc3fe0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,7 @@ PATH remote: . specs: errbit_github_plugin (0.4.0) + activesupport errbit_plugin faraday-retry octokit @@ -142,7 +143,6 @@ PLATFORMS x86_64-linux-musl DEPENDENCIES - activesupport errbit_github_plugin! rake rspec diff --git a/errbit_github_plugin.gemspec b/errbit_github_plugin.gemspec index 6ba860d..59ca9fe 100644 --- a/errbit_github_plugin.gemspec +++ b/errbit_github_plugin.gemspec @@ -22,8 +22,5 @@ Gem::Specification.new do |spec| spec.add_dependency "errbit_plugin" spec.add_dependency "faraday-retry" spec.add_dependency "octokit" - - spec.add_development_dependency "rspec" - spec.add_development_dependency "rake" - spec.add_development_dependency "activesupport" + spec.add_dependency "activesupport" end diff --git a/lib/errbit_github_plugin/issue_tracker.rb b/lib/errbit_github_plugin/issue_tracker.rb index fbfe57c..094be96 100644 --- a/lib/errbit_github_plugin/issue_tracker.rb +++ b/lib/errbit_github_plugin/issue_tracker.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require "active_support/core_ext/object/blank" require "octokit" module ErrbitGithubPlugin diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index b655912..e5b39a9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -12,7 +12,6 @@ require "errbit_plugin" require "errbit_github_plugin" -require "active_support/core_ext/object/blank" RSpec.configure do |config| # Enable flags like --only-failures and --next-failure From 15d95d7339ced332d38b409e3d8d2f9ac2cbb8a5 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 00:58:11 +0200 Subject: [PATCH 06/24] Cleanup --- lib/errbit_github_plugin/issue_tracker.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/errbit_github_plugin/issue_tracker.rb b/lib/errbit_github_plugin/issue_tracker.rb index 094be96..0f145e1 100644 --- a/lib/errbit_github_plugin/issue_tracker.rb +++ b/lib/errbit_github_plugin/issue_tracker.rb @@ -58,12 +58,15 @@ def url def errors errors = [] + if self.class.fields.detect { |f| options[f[0]].blank? } errors << [:base, "You must specify your GitHub username and password"] end + if repo.blank? errors << [:base, "You must specify your GitHub repository url."] end + errors end From 13ca976f085907b39983a5cf7571ee05c0e917db Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 01:29:22 +0200 Subject: [PATCH 07/24] Configure rubocop --- .rubocop.yml | 223 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 223 insertions(+) create mode 100644 .rubocop.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..6754e55 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,223 @@ +AllCops: + TargetRubyVersion: 3.1 + NewCops: enable + +# We use standard as a linter and formatter instead Rubocop. +# Also, we are explicitly disable all rubocop rules what +# already enabled in standard. And standard-performance. + +# Standard rules. Style: + +# Enforced by standard. Disable. +Style/StringLiterals: + Enabled: false + +# Enforced by standard. Disable. +Style/HashSyntax: + Enabled: false + +# Enforced by standard. Disable. +Style/NestedParenthesizedCalls: + Enabled: false + +# Enforced by standard. Disable. +Style/RedundantRegexpArgument: + Enabled: false + +# Enforced by standard. Disable. +Style/PercentLiteralDelimiters: + Enabled: false + +# Enforced by standard. Disable. +Style/RedundantBegin: + Enabled: false + +# Enforced by standard. Disable. +Style/SuperWithArgsParentheses: + Enabled: false + +# Enforced by standard. Disable. +Style/Encoding: + Enabled: false + +# Enforced by standard. Disable. +Style/NumericLiteralPrefix: + Enabled: false + +# Enforced by standard. Disable. +Style/RedundantParentheses: + Enabled: false + +# Enforced by standard. Disable. +Style/EmptyMethod: + Enabled: false + +# Enforced by standard. Disable. +Style/SingleLineMethods: + Enabled: false + +# Enforced by standard. Disable. +Style/SafeNavigation: + Enabled: false + +# Enforced by standard. Disable. +Style/RescueStandardError: + Enabled: false + +# Enforced by standard. Disable. +Style/RedundantSelf: + Enabled: false + +# Enforced by standard. Disable. +Style/TernaryParentheses: + Enabled: false + +# Enforced by standard. Disable. +Style/RedundantLineContinuation: + Enabled: false + +# Enforced by standard. Disable. +Style/SlicingWithRange: + Enabled: false + +# Enforced by standard. Disable. +Style/MultilineIfModifier: + Enabled: false + +# Enforced by standard. Disable. +Style/RedundantCondition: + Enabled: false + +# Enforced by standard. Disable. +Style/RedundantInterpolation: + Enabled: false + +# Enforced by standard. Disable. +Style/OrAssignment: + Enabled: false + +# Enforced by standard. Disable. +Style/ConditionalAssignment: + Enabled: false + +# Enforced by standard. Disable. +Style/ItAssignment: + Enabled: false + +# Enforced by standard. Disable. +Style/EachWithObject: + Enabled: false + +# Enforced by standard. Disable. +Style/GlobalStdStream: + Enabled: false + +# Enforced by standard. Disable. +Style/StringLiteralsInInterpolation: + Enabled: false + +# Disabled as in standard. +Style/HashAsLastArrayItem: + Enabled: false + +# Enforced by standard. Disable. +Style/Alias: + Enabled: false + +# Standard rules. Layout: + +# Enforced by standard. Disable. +Layout/HashAlignment: + Enabled: false + +# Enforced by standard. Disable. +Layout/FirstArrayElementIndentation: + Enabled: false + +# Enforced by standard. Disable. +Layout/SpaceInsideHashLiteralBraces: + Enabled: false + +# Enforced by standard. Disable. +Layout/SpaceInsideStringInterpolation: + Enabled: false + +# Enforced by standard. Disable. +Layout/DotPosition: + Enabled: false + +# Enforced by standard. Disable. +Layout/ExtraSpacing: + Enabled: false + +# Enforced by standard. Disable. +Layout/ArgumentAlignment: + Enabled: false + +# Enforced by standard. Disable. +Layout/MultilineMethodCallBraceLayout: + Enabled: false + +# Enforced by standard. Disable. +Layout/AccessModifierIndentation: + Enabled: false + +# Enforced by standard. Disable. +Layout/FirstHashElementIndentation: + Enabled: false + +# Enforced by standard. Disable. +Layout/IndentationWidth: + Enabled: false + +# Enforced by standard. Disable. +Layout/ElseAlignment: + Enabled: false + +# Enforced by standard. Disable. +Layout/EndAlignment: + Enabled: false + +# Enforced by standard. Disable. +Layout/MultilineHashBraceLayout: + Enabled: false + +# Enforced by standard. Disable. +Layout/EmptyLineBetweenDefs: + Enabled: false + +# Enforced by standard. Disable. +Layout/MultilineArrayBraceLayout: + Enabled: false + +# Enforced by standard. Disable. +Layout/EmptyLineAfterMagicComment: + Enabled: false + +# Enforced by standard. Disable. +Layout/SpaceAroundOperators: + Enabled: false + +# Enforced by standard. Disable. +Layout/ArrayAlignment: + Enabled: false + +# Enforced by standard. Disable. +Layout/AssignmentIndentation: + Enabled: false + +# Enforced by standard. Disable. +Layout/ClosingParenthesisIndentation: + Enabled: false + +# Enforced by standard. Disable. +Layout/LineLength: + Enabled: false + +# Enforced by standard. Disable. +Layout/MultilineMethodCallIndentation: + Enabled: false + +# Enforced by standard. Disable. +Layout/CaseIndentation: + Enabled: false From f49c9dd90b15ee657e5d9361df18900c13985da1 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 01:35:11 +0200 Subject: [PATCH 08/24] Update rubocop config --- .rubocop.yml | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 6754e55..d9c879b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +plugins: + - rubocop-performance + AllCops: TargetRubyVersion: 3.1 NewCops: enable @@ -221,3 +224,79 @@ Layout/MultilineMethodCallIndentation: # Enforced by standard. Disable. Layout/CaseIndentation: Enabled: false + +# Standard rules. Lint: + +# Enforced by standard. Disable. +Lint/ImplicitStringConcatenation: + Enabled: false + +# Enforced by standard. Disable. +Lint/TripleQuotes: + Enabled: false + +# Enforced by standard. Disable. +Lint/IneffectiveAccessModifier: + Enabled: false + +# Enforced by standard. Disable. +Lint/SymbolConversion: + Enabled: false + +# Enforced by rubocop and standard +Lint/CopDirectiveSyntax: + Enabled: true + +# Enforced by standard. Disable. +Lint/DuplicateMethods: + Enabled: false + +# Enforced by standard. Disable. +Lint/ConstantDefinitionInBlock: + Enabled: false + +# Enforced by standard. Disable. +Lint/UselessTimes: + Enabled: false + +# Standard-performance rules. + +# Enforced by standard-performance. Disable. +Performance/Detect: + Enabled: false + +# Enforced by standard-performance. Disable. +Performance/StringIdentifierArgument: + Enabled: false + +# Enforced by standard-performance. Disable. +Performance/RegexpMatch: + Enabled: false + +# Always enable rubocop Security: + +# Enforced by rubocop and standard +Security/JSONLoad: + Enabled: true + +# Our rubocop rules + +Bundler/OrderedGems: + Enabled: false + +Gemspec/OrderedDependencies: + Enabled: false + +# Don't allow %i[foo bar baz] +Style/SymbolArray: + Enabled: true + EnforcedStyle: brackets + +# Don't allow %w[foo bar baz] +Style/WordArray: + Enabled: true + EnforcedStyle: brackets + +# Disable warnings like "Missing top-level documentation comment for" +Style/Documentation: + Enabled: false From 77d7e54648add28338863b9ea542308851f5d264 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 01:35:49 +0200 Subject: [PATCH 09/24] Add rubocop --- Gemfile | 3 ++- Gemfile.lock | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 0782b7e..cd69a43 100644 --- a/Gemfile +++ b/Gemfile @@ -7,4 +7,5 @@ gemspec gem "rake" gem "rspec" gem "simplecov", require: false -gem "standard" +gem "standard", require: false +gem "rubocop", require: false diff --git a/Gemfile.lock b/Gemfile.lock index bdc3fe0..84d7621 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -146,6 +146,7 @@ DEPENDENCIES errbit_github_plugin! rake rspec + rubocop simplecov standard From 864ab476afb922c03f6a819d4d7b687eaf715aba Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 01:41:57 +0200 Subject: [PATCH 10/24] Configure rubocop --- .rubocop.yml | 38 ++++++++++++++++++++++++++++++++++++++ Gemfile | 2 ++ Gemfile.lock | 8 ++++++++ 3 files changed, 48 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index d9c879b..c583df6 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,7 @@ plugins: - rubocop-performance + - rubocop-rake + - rubocop-rspec AllCops: TargetRubyVersion: 3.1 @@ -281,12 +283,18 @@ Security/JSONLoad: # Our rubocop rules +# Bundler rules. + Bundler/OrderedGems: Enabled: false +# Gemspec rules + Gemspec/OrderedDependencies: Enabled: false +# Style rules + # Don't allow %i[foo bar baz] Style/SymbolArray: Enabled: true @@ -300,3 +308,33 @@ Style/WordArray: # Disable warnings like "Missing top-level documentation comment for" Style/Documentation: Enabled: false + +# Disable as in standard. +Style/ArgumentsForwarding: + Enabled: false + +# RSpec rules + +# Prefer eq over be. +RSpec/BeEq: + Enabled: false + +# Prefer eq over eql. +RSpec/BeEql: + Enabled: false + +# We prefer to use `expect` over `allow`. +RSpec/StubbedMock: + Enabled: false + +# We prefer multiple before blocks in tests. +RSpec/ScatteredSetup: + Enabled: false + +# We use `expect` in before hooks. +RSpec/ExpectInHook: + Enabled: false + +# We use item_1, item_2, etc. Disable. +RSpec/IndexedLet: + Enabled: false diff --git a/Gemfile b/Gemfile index cd69a43..e319375 100644 --- a/Gemfile +++ b/Gemfile @@ -9,3 +9,5 @@ gem "rspec" gem "simplecov", require: false gem "standard", require: false gem "rubocop", require: false +gem "rubocop-rake", require: false +gem "rubocop-rspec", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 84d7621..27a1ead 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -98,6 +98,12 @@ GEM lint_roller (~> 1.1) rubocop (>= 1.75.0, < 2.0) rubocop-ast (>= 1.38.0, < 2.0) + rubocop-rake (0.7.1) + lint_roller (~> 1.1) + rubocop (>= 1.72.1) + rubocop-rspec (3.5.0) + lint_roller (~> 1.1) + rubocop (~> 1.72, >= 1.72.1) ruby-progressbar (1.13.0) sawyer (0.9.2) addressable (>= 2.3.5) @@ -147,6 +153,8 @@ DEPENDENCIES rake rspec rubocop + rubocop-rake + rubocop-rspec simplecov standard From 65ab392726a4392d0c8d1f91cbff29ebf7ab57c7 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 12:41:51 +0200 Subject: [PATCH 11/24] Update rubocop config --- .rubocop.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index c583df6..4d67901 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -338,3 +338,23 @@ RSpec/ExpectInHook: # We use item_1, item_2, etc. Disable. RSpec/IndexedLet: Enabled: false + +# Naming rules: + +# Disable anonymous block forwarding. +Naming/BlockForwarding: + Enabled: true + EnforcedStyle: explicit + +# Enable and exclude specific files. +Naming/FileName: + Enabled: true + +# Disabled syntax: + +# Disable shorthand hash syntax like: ({ x:, y: }) +# Disable % style literals +Style/DisableSyntax: + DisableSyntax: + - shorthand_hash_syntax + - percent_literals From 5f3e4fa68cfad7843e1ad45d2dc7640706dc1510 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 12:43:02 +0200 Subject: [PATCH 12/24] Add rubocop-disable_syntax gem --- Gemfile | 1 + Gemfile.lock | 3 +++ 2 files changed, 4 insertions(+) diff --git a/Gemfile b/Gemfile index e319375..c636a17 100644 --- a/Gemfile +++ b/Gemfile @@ -11,3 +11,4 @@ gem "standard", require: false gem "rubocop", require: false gem "rubocop-rake", require: false gem "rubocop-rspec", require: false +gem "rubocop-disable_syntax", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 27a1ead..5712dcb 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -94,6 +94,8 @@ GEM rubocop-ast (1.44.0) parser (>= 3.3.7.2) prism (~> 1.4) + rubocop-disable_syntax (0.1.1) + rubocop (>= 1.50) rubocop-performance (1.25.0) lint_roller (~> 1.1) rubocop (>= 1.75.0, < 2.0) @@ -153,6 +155,7 @@ DEPENDENCIES rake rspec rubocop + rubocop-disable_syntax rubocop-rake rubocop-rspec simplecov From ede186ddfca9855cdac794edc91da7d869d18a12 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 12:43:42 +0200 Subject: [PATCH 13/24] Update rubocop config --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 4d67901..c130200 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,6 @@ +require: + - rubocop-disable_syntax + plugins: - rubocop-performance - rubocop-rake From 60b668bbb68617946cccf3c12cf66704188d62eb Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 12:46:14 +0200 Subject: [PATCH 14/24] Add rubocop-performance gem --- Gemfile | 3 ++- Gemfile.lock | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index c636a17..e96b574 100644 --- a/Gemfile +++ b/Gemfile @@ -9,6 +9,7 @@ gem "rspec" gem "simplecov", require: false gem "standard", require: false gem "rubocop", require: false +gem "rubocop-disable_syntax", require: false +gem "rubocop-performance", require: false gem "rubocop-rake", require: false gem "rubocop-rspec", require: false -gem "rubocop-disable_syntax", require: false diff --git a/Gemfile.lock b/Gemfile.lock index 5712dcb..3a4247c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -156,6 +156,7 @@ DEPENDENCIES rspec rubocop rubocop-disable_syntax + rubocop-performance rubocop-rake rubocop-rspec simplecov From 522f1315091f46202a7e5c91116ac69c237ab728 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 13:30:24 +0200 Subject: [PATCH 15/24] Rename --- lib/errbit_github_plugin.rb | 2 +- lib/errbit_github_plugin/{error.rb => authentication_error.rb} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/errbit_github_plugin/{error.rb => authentication_error.rb} (100%) diff --git a/lib/errbit_github_plugin.rb b/lib/errbit_github_plugin.rb index 0a17647..57afb5a 100644 --- a/lib/errbit_github_plugin.rb +++ b/lib/errbit_github_plugin.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require "errbit_github_plugin/version" -require "errbit_github_plugin/error" +require "errbit_github_plugin/authentication_error" require "errbit_github_plugin/issue_tracker" module ErrbitGithubPlugin diff --git a/lib/errbit_github_plugin/error.rb b/lib/errbit_github_plugin/authentication_error.rb similarity index 100% rename from lib/errbit_github_plugin/error.rb rename to lib/errbit_github_plugin/authentication_error.rb From 97a8c1cf730fb95783aa306275d594c3ef979ed1 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 13:33:33 +0200 Subject: [PATCH 16/24] Cleanup --- .../issue_tracker_spec.rb | 53 +++++++++++++------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/spec/errbit_github_plugin/issue_tracker_spec.rb b/spec/errbit_github_plugin/issue_tracker_spec.rb index dffc0c6..4b7f820 100644 --- a/spec/errbit_github_plugin/issue_tracker_spec.rb +++ b/spec/errbit_github_plugin/issue_tracker_spec.rb @@ -28,24 +28,24 @@ describe ".icons" do it "puts create icon onto the icons" do - expect(described_class.icons[:create][0]).to eq "image/png" - expect( - described_class.icons[:create][1] - ).to eq ErrbitGithubPlugin.read_static_file("github_create.png") + expect(described_class.icons[:create][0]).to eq("image/png") + + expect(described_class.icons[:create][1]) + .to eq(ErrbitGithubPlugin.read_static_file("github_create.png")) end it "puts goto icon onto the icons" do - expect(described_class.icons[:goto][0]).to eq "image/png" - expect( - described_class.icons[:goto][1] - ).to eq ErrbitGithubPlugin.read_static_file("github_goto.png") + expect(described_class.icons[:goto][0]).to eq("image/png") + + expect(described_class.icons[:goto][1]) + .to eq(ErrbitGithubPlugin.read_static_file("github_goto.png")) end it "puts inactive icon onto the icons" do - expect(described_class.icons[:inactive][0]).to eq "image/png" - expect( - described_class.icons[:inactive][1] - ).to eq ErrbitGithubPlugin.read_static_file("github_inactive.png") + expect(described_class.icons[:inactive][0]).to eq("image/png") + + expect(described_class.icons[:inactive][1]) + .to eq(ErrbitGithubPlugin.read_static_file("github_inactive.png")) end end @@ -54,24 +54,28 @@ describe "#configured?" do context "with errors" do let(:options) { {invalid_key: ""} } + it "return false" do - expect(tracker.configured?).to eq false + expect(tracker.configured?).to eq(false) end end + context "without errors" do let(:options) do {username: "foo", password: "bar", github_repo: "user/repository"} end + it "return true" do - expect(tracker.configured?).to eq true + expect(tracker.configured?).to eq(true) end end end describe "#url" do - let(:options) { {github_repo: "repo"} } + let(:options) { {github_repo: "user/repo"} } + it "returns issues url" do - expect(tracker.url).to eq "https://github.com/repo/issues" + expect(tracker.url).to eq("https://github.com/user/repo/issues") end end @@ -87,12 +91,15 @@ end it { is_expected.not_to be_empty } end + context "without github_repo" do let(:options) do {username: "foo", password: "bar", github_repo: ""} end + it { is_expected.not_to be_empty } end + context "with completed options" do let(:options) do {username: "foo", password: "bar", github_repo: "repo"} @@ -170,4 +177,18 @@ end end end + + describe "#close_issue" do + context "signed in with token" do + let(:user) do + { + "github_login" => "bob", + "github_oauth_token" => "valid_token" + } + end + + + + end + end end From 7feb45d90424d227cbc2ce3472179edf4c93795f Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 13:45:23 +0200 Subject: [PATCH 17/24] Update rubocop config --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index c130200..18c633d 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -342,6 +342,10 @@ RSpec/ExpectInHook: RSpec/IndexedLet: Enabled: false +# We don't use named subject's +RSpec/NamedSubject: + Enabled: false + # Naming rules: # Disable anonymous block forwarding. From 1f65f28b35f061b30ee3c03fb4e78fd2d2760397 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 13:47:02 +0200 Subject: [PATCH 18/24] Cleanup tests --- spec/errbit_github_plugin/issue_tracker_spec.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/spec/errbit_github_plugin/issue_tracker_spec.rb b/spec/errbit_github_plugin/issue_tracker_spec.rb index 4b7f820..1b9280d 100644 --- a/spec/errbit_github_plugin/issue_tracker_spec.rb +++ b/spec/errbit_github_plugin/issue_tracker_spec.rb @@ -81,14 +81,18 @@ describe "#errors" do subject { tracker.errors } + context "without username" do let(:options) { {username: "", password: "bar", github_repo: "repo"} } + it { is_expected.not_to be_empty } end + context "without password" do let(:options) do {username: "", password: "bar", github_repo: "repo"} end + it { is_expected.not_to be_empty } end @@ -104,14 +108,16 @@ let(:options) do {username: "foo", password: "bar", github_repo: "repo"} end + it { is_expected.to be_empty } end end describe "#repo" do let(:options) { {github_repo: "baz"} } + it "returns github repo" do - expect(tracker.repo).to eq "baz" + expect(tracker.repo).to eq("baz") end end @@ -147,7 +153,7 @@ login: user["github_login"], access_token: user["github_oauth_token"] ).and_return(fake_github_client) - expect(subject).to eq fake_issue.html_url + expect(subject).to eq(fake_issue.html_url) end end @@ -159,7 +165,7 @@ login: options["username"], password: options["password"] ).and_return(fake_github_client) - expect(subject).to eq fake_issue.html_url + expect(subject).to eq(fake_issue.html_url) end end From 2281879e8765d7820b61b8628bef5d451194eee5 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 13:58:30 +0200 Subject: [PATCH 19/24] Cleanup --- errbit_github_plugin.gemspec | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/errbit_github_plugin.gemspec b/errbit_github_plugin.gemspec index 59ca9fe..5725109 100644 --- a/errbit_github_plugin.gemspec +++ b/errbit_github_plugin.gemspec @@ -1,8 +1,6 @@ # frozen_string_literal: true -lib = File.expand_path("../lib", __FILE__) -$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) -require "errbit_github_plugin/version" +require_relative "lib/errbit_github_plugin/version" Gem::Specification.new do |spec| spec.name = "errbit_github_plugin" @@ -10,10 +8,14 @@ Gem::Specification.new do |spec| spec.authors = ["Stephen Crosby"] spec.email = ["stevecrozz@gmail.com"] - spec.description = "GitHub integration for Errbit" spec.summary = "GitHub integration for Errbit" + spec.description = "GitHub integration for Errbit" spec.homepage = "https://github.com/errbit/errbit_github_plugin" spec.license = "MIT" + spec.required_ruby_version = ">= 3.1.0" + + spec.metadata["homepage_uri"] = spec.homepage + spec.metadata["source_code_uri"] = spec.homepage spec.files = `git ls-files`.split($/) spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } From c9526681ac2203c6fe9059cfebd177b5ea64b9c1 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 14:00:33 +0200 Subject: [PATCH 20/24] Cleanup --- errbit_github_plugin.gemspec | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/errbit_github_plugin.gemspec b/errbit_github_plugin.gemspec index 5725109..fef2843 100644 --- a/errbit_github_plugin.gemspec +++ b/errbit_github_plugin.gemspec @@ -17,8 +17,15 @@ Gem::Specification.new do |spec| spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = spec.homepage - spec.files = `git ls-files`.split($/) - spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } + # Specify which files should be added to the gem when it is released. + # The `git ls-files -z` loads the files in the RubyGem that have been added into git. + gemspec = File.basename(__FILE__) + spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls| + ls.readlines("\x0", chomp: true).reject do |f| + (f == gemspec) || + f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) + end + end spec.require_paths = ["lib"] spec.add_dependency "errbit_plugin" From 1e1926ec267081f44bd6e07fabeff27ee9f70d44 Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 14:10:12 +0200 Subject: [PATCH 21/24] Cleanup --- errbit_github_plugin.gemspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/errbit_github_plugin.gemspec b/errbit_github_plugin.gemspec index fef2843..e73b0a8 100644 --- a/errbit_github_plugin.gemspec +++ b/errbit_github_plugin.gemspec @@ -20,10 +20,10 @@ Gem::Specification.new do |spec| # Specify which files should be added to the gem when it is released. # The `git ls-files -z` loads the files in the RubyGem that have been added into git. gemspec = File.basename(__FILE__) - spec.files = IO.popen(%w[git ls-files -z], chdir: __dir__, err: IO::NULL) do |ls| + spec.files = IO.popen(["git", "ls-files", "-z"], chdir: __dir__, err: IO::NULL) do |ls| ls.readlines("\x0", chomp: true).reject do |f| (f == gemspec) || - f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile]) + f.start_with?(*['bin/', 'test/', 'spec/', 'features/', '.git', '.github', 'appveyor', 'Gemfile']) end end spec.require_paths = ["lib"] From 711d3162157c92e78947640effa5803284c147db Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 14:14:48 +0200 Subject: [PATCH 22/24] Cleanup --- errbit_github_plugin.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/errbit_github_plugin.gemspec b/errbit_github_plugin.gemspec index e73b0a8..9b74f2d 100644 --- a/errbit_github_plugin.gemspec +++ b/errbit_github_plugin.gemspec @@ -23,7 +23,7 @@ Gem::Specification.new do |spec| spec.files = IO.popen(["git", "ls-files", "-z"], chdir: __dir__, err: IO::NULL) do |ls| ls.readlines("\x0", chomp: true).reject do |f| (f == gemspec) || - f.start_with?(*['bin/', 'test/', 'spec/', 'features/', '.git', '.github', 'appveyor', 'Gemfile']) + f.start_with?("bin/", "test/", "spec/", "features/", ".git", ".github", "appveyor", "Gemfile") end end spec.require_paths = ["lib"] From 8106e189b96921d9dee4a6c270b9d5f55a9acc2a Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 14:41:53 +0200 Subject: [PATCH 23/24] Tests --- .../issue_tracker_spec.rb | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/spec/errbit_github_plugin/issue_tracker_spec.rb b/spec/errbit_github_plugin/issue_tracker_spec.rb index 1b9280d..a6a9a88 100644 --- a/spec/errbit_github_plugin/issue_tracker_spec.rb +++ b/spec/errbit_github_plugin/issue_tracker_spec.rb @@ -185,6 +185,24 @@ end describe "#close_issue" do + subject { tracker.close_issue("url", user: user) } + + let(:options) do + {username: "foo", password: "bar", github_repo: "user/repository"} + end + + let(:fake_github_client) do + double("Fake GitHub Client").tap do |github_client| + expect(github_client).to receive(:close_issue).and_return(fake_issue) + end + end + + let(:fake_issue) do + double("Fake Issue").tap do |issue| + expect(issue).to receive(:html_url).and_return("http://github.com/user/repos/issues/878").twice + end + end + context "signed in with token" do let(:user) do { @@ -193,8 +211,39 @@ } end + it "return issue url" do + expect(Octokit::Client).to receive(:new).with( + login: user["github_login"], access_token: user["github_oauth_token"] + ).and_return(fake_github_client) + expect(subject).to eq(fake_issue.html_url) + end + end + context "signed in with password" do + let(:user) { {} } + + it "return issue url" do + expect(Octokit::Client).to receive(:new).with( + login: options["username"], password: options["password"] + ).and_return(fake_github_client) + + expect(subject).to eq(fake_issue.html_url) + end + end + + context "when unauthentication error" do + let(:user) do + {"github_login" => "alice", "github_oauth_token" => "invalid_token"} + end + # + it "raise AuthenticationError" do + expect(Octokit::Client).to receive(:new).with( + login: user["github_login"], access_token: user["github_oauth_token"] + ).and_raise(Octokit::Unauthorized) + + expect { subject }.to raise_error(ErrbitGithubPlugin::AuthenticationError) + end end end end From 587a5571a244c0d0a9885fd5811864d5b98506fc Mon Sep 17 00:00:00 2001 From: Igor Zubkov Date: Fri, 11 Apr 2025 14:42:01 +0200 Subject: [PATCH 24/24] Params --- lib/errbit_github_plugin/issue_tracker.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/errbit_github_plugin/issue_tracker.rb b/lib/errbit_github_plugin/issue_tracker.rb index 0f145e1..106e1ad 100644 --- a/lib/errbit_github_plugin/issue_tracker.rb +++ b/lib/errbit_github_plugin/issue_tracker.rb @@ -90,6 +90,9 @@ def create_issue(title, body, user: {}) raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password." end + # @param url [String] + # @param user [Hash] + # @return [String] The URL of the closed issue def close_issue(url, user: {}) github_client = if user["github_login"] && user["github_oauth_token"] Octokit::Client.new(