From 30227fd55f0f98974ba4e446ef37b16a94f59566 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Sun, 22 Aug 2021 22:26:08 +0200 Subject: [PATCH 01/18] Add workflow to execute Standardrb linter on push events --- .github/workflows/standardrb-linter.yml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/standardrb-linter.yml diff --git a/.github/workflows/standardrb-linter.yml b/.github/workflows/standardrb-linter.yml new file mode 100644 index 0000000..0c228d6 --- /dev/null +++ b/.github/workflows/standardrb-linter.yml @@ -0,0 +1,13 @@ +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 }} \ No newline at end of file From 34815e3706f335fc48337236f56715fa25db35fc Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Sun, 22 Aug 2021 22:40:35 +0200 Subject: [PATCH 02/18] Add standardrb gem to detect & fix errors locally --- Gemfile | 3 ++- Gemfile.lock | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 39b6e67..9cce56c 100644 --- a/Gemfile +++ b/Gemfile @@ -5,6 +5,7 @@ gem 'octokit', '~> 4.20' gem 'activesupport', '~> 6.1.1' group :test, :development do - gem 'rspec' 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 From a3c62af03a021e539949686850daffe37bc4c517 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Sun, 22 Aug 2021 22:40:57 +0200 Subject: [PATCH 03/18] Automatic standardrb fixes --- .../check_conclusion_not_allowed_error.rb | 2 +- app/services/application_service.rb | 4 ++-- app/spec/entrypoint_spec.rb | 3 +-- .../services/github_checks_verifier_spec.rb | 23 +++++++++---------- app/spec/spec_helper.rb | 6 ++--- app/spec/support/helpers.rb | 11 +++++---- 6 files changed, 24 insertions(+), 25 deletions(-) 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/services/application_service.rb b/app/services/application_service.rb index 44262b0..48c328e 100644 --- a/app/services/application_service.rb +++ b/app/services/application_service.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ApplicationService - def self.call(*args, &block) - new(*args, &block).call + def self.call(...) + new(...).call 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 From 99f2e9168de4407a98f329bf1d83a225455d2816 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Sun, 22 Aug 2021 22:43:01 +0200 Subject: [PATCH 04/18] Update Gemfile --- Gemfile | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Gemfile b/Gemfile index 9cce56c..a64699f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,11 +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 'byebug', platforms: [:mri, :mingw, :x64_mingw] - gem 'rspec' + gem "byebug", platforms: [:mri, :mingw, :x64_mingw] + gem "rspec" gem "standard" end From cf5c14a7fdaa573c128493050f5fb41d938b49b1 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Sun, 22 Aug 2021 22:47:08 +0200 Subject: [PATCH 05/18] Create .standard.yml --- app/.standard.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 app/.standard.yml 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 From 7e5d3a1600a3dd3835c69582101422455fbac2bb Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Sun, 22 Aug 2021 22:58:41 +0200 Subject: [PATCH 06/18] try setting ruby version in workflow --- .github/workflows/standardrb-linter.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/standardrb-linter.yml b/.github/workflows/standardrb-linter.yml index 0c228d6..794668e 100644 --- a/.github/workflows/standardrb-linter.yml +++ b/.github/workflows/standardrb-linter.yml @@ -10,4 +10,5 @@ jobs: - name: StandardRB Linter uses: andrewmcodes/standardrb-action@v0.0.2 env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RUBY_VERSION: 2.7 From cf611e28adac4bc6ec57d17c309313ed5e595fe8 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:26:52 +0200 Subject: [PATCH 07/18] Remove redundant '.rb' --- entrypoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.rb b/entrypoint.rb index 7b57ea3..9050f4d 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -1,5 +1,5 @@ #!/usr/bin/env ruby -require_relative "./app/services/github_checks_verifier.rb" +require_relative "./app/services/github_checks_verifier" require "octokit" ref, check_name, check_regexp, token, wait, workflow_name, allowed_conclusions = ARGV From d4c1bb6214c4b6ce65291d1b0fda0578cc9ca120 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:31:33 +0200 Subject: [PATCH 08/18] "Prefer double-quoted strings" fix --- entrypoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.rb b/entrypoint.rb index 9050f4d..f518f3d 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -12,7 +12,7 @@ config.repo = ENV["GITHUB_REPOSITORY"] config.wait = wait.to_i config.workflow_name = workflow_name - config.allowed_conclusions = allowed_conclusions.split(',').map(&:strip) + config.allowed_conclusions = allowed_conclusions.split(",").map(&:strip) end GithubChecksVerifier.call From d13125b512418f1afd8fe58feb7d9be8f2e95a0d Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:33:06 +0200 Subject: [PATCH 09/18] Try another standardrb GH action --- .github/workflows/standardrb-linter.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/standardrb-linter.yml b/.github/workflows/standardrb-linter.yml index 794668e..a4fb217 100644 --- a/.github/workflows/standardrb-linter.yml +++ b/.github/workflows/standardrb-linter.yml @@ -6,9 +6,7 @@ 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 + - name: standardrb + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + uses: amoeba/standardrb-action@v2 From ab41de3134be70da675a63ca8db7f16a48083ecf Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:35:44 +0200 Subject: [PATCH 10/18] Add error to test standardrb --- entrypoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.rb b/entrypoint.rb index f518f3d..9050f4d 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -12,7 +12,7 @@ config.repo = ENV["GITHUB_REPOSITORY"] config.wait = wait.to_i config.workflow_name = workflow_name - config.allowed_conclusions = allowed_conclusions.split(",").map(&:strip) + config.allowed_conclusions = allowed_conclusions.split(',').map(&:strip) end GithubChecksVerifier.call From 0b89c8cfae9a81abff437bd843c06fa8f2026d50 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:37:54 +0200 Subject: [PATCH 11/18] update version of action --- .github/workflows/standardrb-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/standardrb-linter.yml b/.github/workflows/standardrb-linter.yml index a4fb217..fafc206 100644 --- a/.github/workflows/standardrb-linter.yml +++ b/.github/workflows/standardrb-linter.yml @@ -9,4 +9,4 @@ jobs: - name: standardrb env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: amoeba/standardrb-action@v2 + uses: amoeba/standardrb-action@v3 From 6297582e6480fdd5c13c33efad15468067147963 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:41:20 +0200 Subject: [PATCH 12/18] Revert "update version of action" This reverts commit 0b89c8cfae9a81abff437bd843c06fa8f2026d50. --- .github/workflows/standardrb-linter.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/standardrb-linter.yml b/.github/workflows/standardrb-linter.yml index fafc206..a4fb217 100644 --- a/.github/workflows/standardrb-linter.yml +++ b/.github/workflows/standardrb-linter.yml @@ -9,4 +9,4 @@ jobs: - name: standardrb env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: amoeba/standardrb-action@v3 + uses: amoeba/standardrb-action@v2 From 507d4b0a0d34cceecdd841b15cc8a38f245ceaeb Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:41:29 +0200 Subject: [PATCH 13/18] Revert "Try another standardrb GH action" This reverts commit d13125b512418f1afd8fe58feb7d9be8f2e95a0d. --- .github/workflows/standardrb-linter.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/standardrb-linter.yml b/.github/workflows/standardrb-linter.yml index a4fb217..794668e 100644 --- a/.github/workflows/standardrb-linter.yml +++ b/.github/workflows/standardrb-linter.yml @@ -6,7 +6,9 @@ jobs: build: runs-on: ubuntu-latest steps: - - name: standardrb - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - uses: amoeba/standardrb-action@v2 + - uses: actions/checkout@v1 + - name: StandardRB Linter + uses: andrewmcodes/standardrb-action@v0.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + RUBY_VERSION: 2.7 From 4481142cbb6f318ad06abad1c573518edfc52881 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:41:50 +0200 Subject: [PATCH 14/18] Update application_service.rb --- app/services/application_service.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/services/application_service.rb b/app/services/application_service.rb index 48c328e..44262b0 100644 --- a/app/services/application_service.rb +++ b/app/services/application_service.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true class ApplicationService - def self.call(...) - new(...).call + def self.call(*args, &block) + new(*args, &block).call end end From 44788bc1d108300ad57d58308c7cb22151e8381c Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:43:04 +0200 Subject: [PATCH 15/18] Revert "Add error to test standardrb" This reverts commit ab41de3134be70da675a63ca8db7f16a48083ecf. --- entrypoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.rb b/entrypoint.rb index 9050f4d..f518f3d 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -12,7 +12,7 @@ config.repo = ENV["GITHUB_REPOSITORY"] config.wait = wait.to_i config.workflow_name = workflow_name - config.allowed_conclusions = allowed_conclusions.split(',').map(&:strip) + config.allowed_conclusions = allowed_conclusions.split(",").map(&:strip) end GithubChecksVerifier.call From a6a1d8fe1652858163642b720d3caf7a3e9bf7ee Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:44:38 +0200 Subject: [PATCH 16/18] Undo change to avoid conflict with master --- entrypoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.rb b/entrypoint.rb index f518f3d..9050f4d 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -12,7 +12,7 @@ config.repo = ENV["GITHUB_REPOSITORY"] config.wait = wait.to_i config.workflow_name = workflow_name - config.allowed_conclusions = allowed_conclusions.split(",").map(&:strip) + config.allowed_conclusions = allowed_conclusions.split(',').map(&:strip) end GithubChecksVerifier.call From a4e52c2fb6b39922d5b3f25629fa58978b06b457 Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:46:57 +0200 Subject: [PATCH 17/18] Update entrypoint.rb --- entrypoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.rb b/entrypoint.rb index 71788c7..96d9b33 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -5,7 +5,7 @@ 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) From 00c6b7c373f507668144d97c47bee6184b9d65ba Mon Sep 17 00:00:00 2001 From: Matias Albarello Date: Mon, 23 Aug 2021 17:47:18 +0200 Subject: [PATCH 18/18] Update entrypoint.rb --- entrypoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/entrypoint.rb b/entrypoint.rb index 96d9b33..080a5e8 100755 --- a/entrypoint.rb +++ b/entrypoint.rb @@ -2,7 +2,7 @@ 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)