diff --git a/.github/workflows/standardrb-linter.yml b/.github/workflows/standardrb-linter.yml new file mode 100644 index 0000000..794668e --- /dev/null +++ b/.github/workflows/standardrb-linter.yml @@ -0,0 +1,14 @@ +name: StandardRB + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: StandardRB Linter + uses: andrewmcodes/standardrb-action@v0.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RUBY_VERSION: 2.7 diff --git a/Gemfile b/Gemfile index 39b6e67..a64699f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,10 +1,11 @@ -source 'https://rubygems.org' +source "https://rubygems.org" git_source(:github) { |repo| "https://github.com/#{repo}.git" } -gem 'octokit', '~> 4.20' -gem 'activesupport', '~> 6.1.1' +gem "octokit", "~> 4.20" +gem "activesupport", "~> 6.1.1" group :test, :development do - gem 'rspec' - gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] + gem "byebug", platforms: [:mri, :mingw, :x64_mingw] + gem "rspec" + gem "standard" end diff --git a/Gemfile.lock b/Gemfile.lock index 0d18a0d..9a717a2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -9,6 +9,7 @@ GEM zeitwerk (~> 2.3) addressable (2.8.0) public_suffix (>= 2.0.2, < 5.0) + ast (2.4.2) byebug (11.1.3) concurrent-ruby (1.1.7) diff-lcs (1.4.4) @@ -24,7 +25,13 @@ GEM octokit (4.20.0) faraday (>= 0.9) sawyer (~> 0.8.0, >= 0.5.3) + parallel (1.20.1) + parser (3.0.2.0) + ast (~> 2.4.1) public_suffix (4.0.6) + rainbow (3.0.0) + regexp_parser (2.1.1) + rexml (3.2.5) rspec (3.10.0) rspec-core (~> 3.10.0) rspec-expectations (~> 3.10.0) @@ -38,12 +45,31 @@ GEM diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.10.0) rspec-support (3.10.1) + rubocop (1.18.4) + parallel (~> 1.10) + parser (>= 3.0.0.0) + rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml + rubocop-ast (>= 1.8.0, < 2.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 3.0) + rubocop-ast (1.10.0) + parser (>= 3.0.1.1) + rubocop-performance (1.11.4) + rubocop (>= 1.7.0, < 2.0) + rubocop-ast (>= 0.4.0) + ruby-progressbar (1.11.0) ruby2_keywords (0.0.2) sawyer (0.8.2) addressable (>= 2.3.5) faraday (> 0.8, < 2.0) + standard (1.1.7) + rubocop (= 1.18.4) + rubocop-performance (= 1.11.4) tzinfo (2.0.4) concurrent-ruby (~> 1.0) + unicode-display_width (2.0.0) zeitwerk (2.4.2) PLATFORMS @@ -55,6 +81,7 @@ DEPENDENCIES byebug octokit (~> 4.20) rspec + standard BUNDLED WITH 2.2.3 diff --git a/app/.standard.yml b/app/.standard.yml new file mode 100644 index 0000000..9317f11 --- /dev/null +++ b/app/.standard.yml @@ -0,0 +1,5 @@ +fix: true # default: false +parallel: true # default: false +format: progress # default: Standard::Formatter +ruby_version: 2.7.2 # default: RUBY_VERSION +default_ignores: false # default: true diff --git a/app/errors/check_conclusion_not_allowed_error.rb b/app/errors/check_conclusion_not_allowed_error.rb index aa07ded..b471cdf 100644 --- a/app/errors/check_conclusion_not_allowed_error.rb +++ b/app/errors/check_conclusion_not_allowed_error.rb @@ -3,7 +3,7 @@ class CheckConclusionNotAllowedError < StandardError def initialize(allowed_conclusions) msg = "The conclusion of one or more checks were not allowed. Allowed conclusions are: "\ - "#{allowed_conclusions.join(', ')}. This can be configured with the 'allowed-conclusions' param." + "#{allowed_conclusions.join(", ")}. This can be configured with the 'allowed-conclusions' param." super(msg) end end diff --git a/app/spec/entrypoint_spec.rb b/app/spec/entrypoint_spec.rb index 478f3a9..6184e37 100644 --- a/app/spec/entrypoint_spec.rb +++ b/app/spec/entrypoint_spec.rb @@ -1,12 +1,11 @@ require "spec_helper" - describe "entrypoint" do it "calls the GithubChecksVerifier service" do allow(GithubChecksVerifier).to receive(:call) allow(GithubChecksVerifier).to receive(:configure) - require_relative "../../entrypoint.rb" + require_relative "../../entrypoint" expect(GithubChecksVerifier).to have_received(:call) end diff --git a/app/spec/services/github_checks_verifier_spec.rb b/app/spec/services/github_checks_verifier_spec.rb index 0fb5df3..7b81618 100644 --- a/app/spec/services/github_checks_verifier_spec.rb +++ b/app/spec/services/github_checks_verifier_spec.rb @@ -30,7 +30,7 @@ mock_api_response(all_successful_checks) service.workflow_name = "invoking_check" service.wait = 0 - output = with_captured_stdout{ service.call } + output = with_captured_stdout { service.call } expect(output).to include("The requested check isn't complete yet, will check back in #{service.wait} seconds...") end @@ -79,14 +79,14 @@ describe "#fail_if_requested_check_never_run" do it "raises an exception if check_name is not empty and all_checks is" do - service.config.check_name = 'test' + service.config.check_name = "test" all_checks = [] allow(service).to receive(:query_check_status).and_return all_checks expected_msg = "The requested check was never run against this ref, exiting..." - expect do + expect { service.call - end.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout + }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout end end @@ -100,10 +100,9 @@ expected_msg = "The conclusion of one or more checks were not allowed. Allowed conclusions are: "\ "success, skipped. This can be configured with the 'allowed-conclusions' param." - expect do + expect { service.call - end.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout - + }.to raise_error(SystemExit).and output(/#{expected_msg}/).to_stdout end it "does not raise an exception if all checks conlusions are allowed" do @@ -113,9 +112,9 @@ ] allow(service).to receive(:query_check_status).and_return all_checks - expect do + expect { service.call - end.not_to raise_error + }.not_to raise_error end end @@ -123,7 +122,7 @@ it "prints successful message to standard output" do checks = [OpenStruct.new(name: "check_completed", status: "completed", conclusion: "success")] allow(service).to receive(:query_check_status).and_return checks - output = with_captured_stdout{ service.call } + output = with_captured_stdout { service.call } expect(output).to include("check_completed: completed (success)") end @@ -138,7 +137,7 @@ service.config.check_name = "check_name" service.send(:apply_filters, checks) - expect(checks.map(&:name)).to all( eq "check_name" ) + expect(checks.map(&:name)).to all(eq "check_name") end it "does not filter by check_name if it's empty" do @@ -186,7 +185,7 @@ OpenStruct.new(name: "other_check", status: "queued") ] - service.check_regexp = '.?_check' + service.check_regexp = ".?_check" service.send(:apply_regexp_filter, checks) expect(checks.map(&:name)).to include("other_check") diff --git a/app/spec/spec_helper.rb b/app/spec/spec_helper.rb index 293653d..d861ff8 100644 --- a/app/spec/spec_helper.rb +++ b/app/spec/spec_helper.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true -require 'byebug' +require "byebug" -services = Dir['./services/**/*.rb'] +services = Dir["./services/**/*.rb"] services.sort.each { |f| require f } -test_helpers = Dir['./spec/support/**/*.rb'] +test_helpers = Dir["./spec/support/**/*.rb"] test_helpers.sort.each { |f| require f } RSpec.configure do |config| diff --git a/app/spec/support/helpers.rb b/app/spec/support/helpers.rb index 8c6b248..92c940b 100644 --- a/app/spec/support/helpers.rb +++ b/app/spec/support/helpers.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true + require "ostruct" require "json" module Helpers @@ -18,12 +19,12 @@ def mock_api_response(checks) end def with_captured_stdout - original_stdout = $stdout # capture previous value of $stdout - $stdout = StringIO.new # assign a string buffer to $stdout - yield # perform the body of the user code - $stdout.string # return the contents of the string buffer + original_stdout = $stdout # capture previous value of $stdout + $stdout = StringIO.new # assign a string buffer to $stdout + yield # perform the body of the user code + $stdout.string # return the contents of the string buffer ensure - $stdout = original_stdout # restore $stdout to its previous value + $stdout = original_stdout # restore $stdout to its previous value end end diff --git a/entrypoint.rb b/entrypoint.rb index 60b1cf5..080a5e8 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -1,11 +1,11 @@ #!/usr/bin/env ruby -require_relative "./app/services/github_checks_verifier.rb" +require_relative "./app/services/github_checks_verifier" require "octokit" -allowed_conclusions, check_name, check_regexp, ref, token, verbose, wait, workflow_name = ARGV +allowed_conclusions, check_name, check_regexp, ref, token, verbose, wait, workflow_name = ARGV GithubChecksVerifier.configure do |config| - config.allowed_conclusions = allowed_conclusions.split(',').map(&:strip) + config.allowed_conclusions = allowed_conclusions.split(",").map(&:strip) config.check_name = check_name config.check_regexp = check_regexp config.client = Octokit::Client.new(access_token: token)