Skip to content

Commit

Permalink
Merge pull request #43 from lewagon/feature/add_standardrb_linter_wor…
Browse files Browse the repository at this point in the history
…kflow

Add workflow to execute Standardrb linter on push events
  • Loading branch information
matiasalbarello authored Aug 23, 2021
2 parents a0f99ce + 00c6b7c commit 0179dfc
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 31 deletions.
14 changes: 14 additions & 0 deletions .github/workflows/standardrb-linter.yml
Original file line number Diff line number Diff line change
@@ -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
11 changes: 6 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -55,6 +81,7 @@ DEPENDENCIES
byebug
octokit (~> 4.20)
rspec
standard

BUNDLED WITH
2.2.3
5 changes: 5 additions & 0 deletions app/.standard.yml
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion app/errors/check_conclusion_not_allowed_error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 1 addition & 2 deletions app/spec/entrypoint_spec.rb
Original file line number Diff line number Diff line change
@@ -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
Expand Down
23 changes: 11 additions & 12 deletions app/spec/services/github_checks_verifier_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -113,17 +112,17 @@
]
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

describe "#show_checks_conclusion_message" do
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
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions app/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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|
Expand Down
11 changes: 6 additions & 5 deletions app/spec/support/helpers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require "ostruct"
require "json"
module Helpers
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions entrypoint.rb
Original file line number Diff line number Diff line change
@@ -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)
Expand Down

0 comments on commit 0179dfc

Please sign in to comment.