From ff8ddd9bd1109184f1b7bb04172d73e037489d40 Mon Sep 17 00:00:00 2001 From: Andrew Mason Date: Mon, 28 Oct 2019 20:43:08 -0400 Subject: [PATCH] add rspec and rubocop binstubs, and lint the project (#21) --- .github/workflows/rubocop.yml | 26 +++++++++++ .github/workflows/test.yml | 26 +++++++++++ .rubocop.yml | 11 +++++ Gemfile | 14 ++++++ Gemfile.lock | 62 +++++++++++++++++++++++++++ bin/rspec | 29 +++++++++++++ bin/rubocop | 29 +++++++++++++ lib/github_check_run_service.rb | 1 - lib/report_adapter.rb | 4 +- spec/github_check_run_service_spec.rb | 2 + spec/report_adapter_spec.rb | 10 +++-- spec/spec_helper.rb | 2 + 12 files changed, 209 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/rubocop.yml create mode 100644 .github/workflows/test.yml create mode 100644 .rubocop.yml create mode 100644 Gemfile create mode 100644 Gemfile.lock create mode 100755 bin/rspec create mode 100755 bin/rubocop diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml new file mode 100644 index 0000000..1bfa996 --- /dev/null +++ b/.github/workflows/rubocop.yml @@ -0,0 +1,26 @@ +name: Rubocop + +on: + pull_request: + branches: + - '*' + push: + branches: + - master + +jobs: + rubocop: + name: Ruocop Action + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Set up Ruby 2.6 + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.6.x + - name: Bundle + run: | + gem install bundler + bundle install --jobs 4 --retry 3 + - name: Run Rubocop + run: bin/rubocop diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..7fd73c9 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: Test + +on: + pull_request: + branches: + - '*' + push: + branches: + - master + +jobs: + test: + name: Rspec Test Action + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: Set up Ruby 2.6 + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.6.x + - name: Bundle + run: | + gem install bundler + bundle install --jobs 4 --retry 3 + - name: Run Rspec + run: bin/rspec diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..6ee570d --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,11 @@ +Layout/IndentFirstHashElement: + EnforcedStyle: consistent + +Metrics/MethodLength: + Max: 16 + +Style/Documentation: + Enabled: false + +Metrics/LineLength: + Max: 120 diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..0e6ca2e --- /dev/null +++ b/Gemfile @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +group :development do + gem 'rubocop', '~> 0.76.0' +end + +group :test do + gem 'json', '~> 2.2' + gem 'pry', '~> 0.12.2' + gem 'rspec', '~> 3.9.0' + gem 'webmock', '~> 3.7', '>= 3.7.6' +end diff --git a/Gemfile.lock b/Gemfile.lock new file mode 100644 index 0000000..63b65b0 --- /dev/null +++ b/Gemfile.lock @@ -0,0 +1,62 @@ +GEM + remote: https://rubygems.org/ + specs: + addressable (2.7.0) + public_suffix (>= 2.0.2, < 5.0) + ast (2.4.0) + coderay (1.1.2) + crack (0.4.3) + safe_yaml (~> 1.0.0) + diff-lcs (1.3) + hashdiff (1.0.0) + jaro_winkler (1.5.3) + json (2.2.0) + method_source (0.9.2) + parallel (1.18.0) + parser (2.6.5.0) + ast (~> 2.4.0) + pry (0.12.2) + coderay (~> 1.1.0) + method_source (~> 0.9.0) + public_suffix (4.0.1) + rainbow (3.0.0) + rspec (3.9.0) + rspec-core (~> 3.9.0) + rspec-expectations (~> 3.9.0) + rspec-mocks (~> 3.9.0) + rspec-core (3.9.0) + rspec-support (~> 3.9.0) + rspec-expectations (3.9.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-mocks (3.9.0) + diff-lcs (>= 1.2.0, < 2.0) + rspec-support (~> 3.9.0) + rspec-support (3.9.0) + rubocop (0.76.0) + jaro_winkler (~> 1.5.1) + parallel (~> 1.10) + parser (>= 2.6) + rainbow (>= 2.2.2, < 4.0) + ruby-progressbar (~> 1.7) + unicode-display_width (>= 1.4.0, < 1.7) + ruby-progressbar (1.10.1) + safe_yaml (1.0.5) + unicode-display_width (1.6.0) + webmock (3.7.6) + addressable (>= 2.3.6) + crack (>= 0.3.2) + hashdiff (>= 0.4.0, < 2.0.0) + +PLATFORMS + ruby + +DEPENDENCIES + json (~> 2.2) + pry (~> 0.12.2) + rspec (~> 3.9.0) + rubocop (~> 0.76.0) + webmock (~> 3.7, >= 3.7.6) + +BUNDLED WITH + 2.0.2 diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..58d85dd --- /dev/null +++ b/bin/rspec @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path('bundle', __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rspec-core', 'rspec') diff --git a/bin/rubocop b/bin/rubocop new file mode 100755 index 0000000..66a026a --- /dev/null +++ b/bin/rubocop @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'rubocop' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require 'pathname' +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', + Pathname.new(__FILE__).realpath) + +bundle_binstub = File.expand_path('bundle', __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/ + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rubocop', 'rubocop') diff --git a/lib/github_check_run_service.rb b/lib/github_check_run_service.rb index 151302c..c2e1cd5 100644 --- a/lib/github_check_run_service.rb +++ b/lib/github_check_run_service.rb @@ -54,5 +54,4 @@ class GithubCheckRunService } } end - end diff --git a/lib/report_adapter.rb b/lib/report_adapter.rb index 0a72684..a1ba99a 100644 --- a/lib/report_adapter.rb +++ b/lib/report_adapter.rb @@ -30,13 +30,13 @@ class ReportAdapter return annotation_list if count == 48 location = offense['location'] - annotation_list.push({ + annotation_list.push( 'path' => file['path'], 'start_line' => location['start_line'], 'end_line' => location['last_line'], 'annotation_level' => annotation_level(offense['severity']), 'message' => offense['message'] - }) + ) end end end diff --git a/spec/github_check_run_service_spec.rb b/spec/github_check_run_service_spec.rb index a942421..99833d0 100644 --- a/spec/github_check_run_service_spec.rb +++ b/spec/github_check_run_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require './spec/spec_helper' describe GithubCheckRunService do diff --git a/spec/report_adapter_spec.rb b/spec/report_adapter_spec.rb index 1924e47..856a4e9 100644 --- a/spec/report_adapter_spec.rb +++ b/spec/report_adapter_spec.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require './spec/spec_helper' describe ReportAdapter do - let(:rubocop_report) { + let(:rubocop_report) do JSON(File.read('./spec/fixtures/report.json')) - } + end let(:adapter) { ReportAdapter } @@ -19,12 +21,12 @@ describe ReportAdapter do it '.annotations' do result = adapter.annotations(rubocop_report) - expect(result.first).to eq({ + expect(result.first).to eq( 'path' => 'Gemfile', 'start_line' => 1, 'end_line' => 1, 'annotation_level' => 'failure', 'message' => 'Missing magic comment `# frozen_string_literal: true`.' - }) + ) end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 79d7889..d37a172 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'webmock/rspec' require 'json' require 'pry'