Skip to content

Commit

Permalink
Update govuk-lint and auto-correct linting offences
Browse files Browse the repository at this point in the history
  • Loading branch information
Bevan Loon committed Oct 10, 2019
1 parent 9dad4ed commit 5774909
Show file tree
Hide file tree
Showing 50 changed files with 968 additions and 964 deletions.
32 changes: 16 additions & 16 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
source 'https://rubygems.org'
source "https://rubygems.org"

ruby File.read('.ruby-version').chomp
ruby File.read(".ruby-version").chomp

gem 'bundler-audit', git: 'https://github.com/rubysec/bundler-audit', branch: 'master'
gem 'octokit', '~> 4.3'
gem 'rake', '~> 12.3.0'
gem 'sinatra'
gem 'slack-poster', '~> 2.2'
gem "bundler-audit", git: "https://github.com/rubysec/bundler-audit", branch: "master"
gem "octokit", "~> 4.3"
gem "rake", "~> 12.3.0"
gem "sinatra"
gem "slack-poster", "~> 2.2"

group :production, :staging do
gem 'unicorn'
gem "unicorn"
end

group :development, :test do
gem 'govuk-lint'
gem "govuk-lint"
end

group :test do
gem 'climate_control', '~> 0.2'
gem 'pry', '~> 0.11.3'
gem 'rack-test', '~> 0.8.0'
gem 'rspec', '~> 3.7.0'
gem 'timecop', '~> 0.9.1'
gem 'vcr'
gem 'webmock'
gem "climate_control", "~> 0.2"
gem "pry", "~> 0.11.3"
gem "rack-test", "~> 0.8.0"
gem "rspec", "~> 3.7.0"
gem "timecop", "~> 0.9.1"
gem "vcr"
gem "webmock"
end
32 changes: 18 additions & 14 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,22 @@ GEM
diff-lcs (1.3)
faraday (0.15.3)
multipart-post (>= 1.2, < 3)
ffi (1.10.0)
govuk-lint (3.11.1)
rubocop (~> 0.64)
ffi (1.11.1)
govuk-lint (4.0.1)
rubocop (~> 0.72)
rubocop-rails (~> 2)
rubocop-rspec (~> 1.28)
scss_lint
hashdiff (1.0.0)
jaro_winkler (1.5.2)
jaro_winkler (1.5.3)
kgio (2.11.2)
method_source (0.9.0)
multipart-post (2.0.0)
mustermann (1.0.3)
octokit (4.12.0)
sawyer (~> 0.8.0, >= 0.5.3)
parallel (1.17.0)
parser (2.6.3.0)
parallel (1.18.0)
parser (2.6.5.0)
ast (~> 2.4.0)
pry (0.11.3)
coderay (~> 1.1.0)
Expand All @@ -47,7 +48,7 @@ GEM
rack (>= 1.0, < 3)
rainbow (3.0.0)
raindrops (0.19.0)
rake (12.3.2)
rake (12.3.3)
rb-fsevent (0.10.3)
rb-inotify (0.10.0)
ffi (~> 1.0)
Expand All @@ -64,16 +65,19 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.7.0)
rspec-support (3.7.1)
rubocop (0.68.1)
rubocop (0.75.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.5, != 2.5.1.1)
parser (>= 2.6)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.6)
rubocop-rspec (1.32.0)
rubocop (>= 0.60.0)
ruby-progressbar (1.10.0)
unicode-display_width (>= 1.4.0, < 1.7)
rubocop-rails (2.3.2)
rack (>= 1.1)
rubocop (>= 0.72.0)
rubocop-rspec (1.36.0)
rubocop (>= 0.68.1)
ruby-progressbar (1.10.1)
safe_yaml (1.0.5)
sass (3.7.4)
sass-listen (~> 4.0.0)
Expand All @@ -96,7 +100,7 @@ GEM
thor (0.20.0)
tilt (2.0.8)
timecop (0.9.1)
unicode-display_width (1.5.0)
unicode-display_width (1.6.0)
unicorn (5.4.1)
kgio (~> 2.6)
raindrops (~> 0.7)
Expand Down
20 changes: 10 additions & 10 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
require_relative 'dependapanda'
require 'bundler/audit/database'
require 'vcr'
require 'net/http'
require_relative "dependapanda"
require "bundler/audit/database"
require "vcr"
require "net/http"

begin
require 'rspec/core/rake_task'
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)

task default: :spec
rescue LoadError
p 'Could not load RSpec'
p "Could not load RSpec"
end

task :dependapanda do
Expand All @@ -23,8 +23,8 @@ end
task :save_application_gemfiles do
UseCases::Gemfiles::Save.new(
fetch_gemfiles: UseCases::Gemfiles::Fetch.new(
teams_use_case: UseCases::Teams::Fetch.new
)
teams_use_case: UseCases::Teams::Fetch.new,
),
).execute
end

Expand All @@ -33,11 +33,11 @@ task :update_advisory_db do
end

desc "Recreate the vcr cassettes. For example `rake record_cassette[org:alphagov topic:govuk]`"
task :record_cassette, [:search_string] do |task, args|
task :record_cassette, [:search_string] do |_, args|
octokit = Octokit::Client.new(auto_paginate: true)

puts "Deleting old cassette"
File.delete("spec/fixtures/vcr_cassettes/repositories.yml") if File.exists?("spec/fixtures/vcr_cassettes/repositories.yml")
File.delete("spec/fixtures/vcr_cassettes/repositories.yml") if File.exist?("spec/fixtures/vcr_cassettes/repositories.yml")

VCR.configure do |config|
config.cassette_library_dir = "spec/fixtures/vcr_cassettes"
Expand Down
34 changes: 17 additions & 17 deletions app.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
require 'sinatra'
require_relative 'lib/loader'
require "sinatra"
require_relative "lib/loader"

class GovukDependencies < Sinatra::Base
get '/' do
get "/" do
cache :pull_requests_by_application do
erb :index, layout: :layout, locals: {
pull_requests_by_application: UseCases::Group::PullRequestsByApplication.new.execute
pull_requests_by_application: UseCases::Group::PullRequestsByApplication.new.execute,
}
end
end

get '/gem' do
get "/gem" do
cache :pull_requests_by_gem do
erb :gem, layout: :layout, locals: {
pull_requests_by_gem: UseCases::Group::PullRequestsByGem.new.execute
pull_requests_by_gem: UseCases::Group::PullRequestsByGem.new.execute,
}
end
end

get '/team' do
get "/team" do
cache :pull_requests_by_team do
pull_requests = UseCases::PullRequests::Fetch.new.execute
teams = UseCases::Teams::Fetch.new.execute
Expand All @@ -28,15 +28,15 @@ class GovukDependencies < Sinatra::Base
end
end

get '/stats' do
get "/stats" do
cache :stats do
erb :stats, locals: {
pull_request_count: UseCases::PullRequests::FetchCount.new.execute
pull_request_count: UseCases::PullRequests::FetchCount.new.execute,
}, layout: :layout
end
end

get '/team/:team_name' do
get "/team/:team_name" do
cache :"pull_requests_by_team_#{params.fetch(:team_name)}" do
pull_requests = UseCases::PullRequests::Fetch.new.execute
teams = UseCases::Teams::Fetch.new.execute
Expand All @@ -50,23 +50,23 @@ class GovukDependencies < Sinatra::Base
end
end

post '/slack/notify/:team/:secret' do
return '[unauthorised]' unless params[:secret] == ENV['DEPENDAPANDA_SECRET']
post "/slack/notify/:team/:secret" do
return "[unauthorised]" unless params[:secret] == ENV["DEPENDAPANDA_SECRET"]

UseCases::Slack::SendMessages.new(
message_presenter: Presenters::Slack::FullMessage.new
message_presenter: Presenters::Slack::FullMessage.new,
).execute(team: params.fetch(:team))
'[ok]'
"[ok]"
end

get '/security-alerts' do
get "/security-alerts" do
cache :security_alerts, 43200 do
Bundler::Audit::Database.update!(quiet: true)

UseCases::Gemfiles::Save.new(
fetch_gemfiles: UseCases::Gemfiles::Fetch.new(
teams_use_case: UseCases::Teams::Fetch.new
)
teams_use_case: UseCases::Teams::Fetch.new,
),
).execute

application_security_alerts = UseCases::SecurityAlerts::Fetch.new.execute
Expand Down
2 changes: 1 addition & 1 deletion config.ru
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
require './app'
require "./app"
run GovukDependencies
6 changes: 3 additions & 3 deletions dependapanda.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
require_relative 'lib/loader'
require_relative "lib/loader"

class Dependapanda
def send_simple_message
UseCases::Slack::SendMessages.new(
message_presenter: Presenters::Slack::SimpleMessage.new,
scheduler: UseCases::Slack::Schedulers::Weekday.new
scheduler: UseCases::Slack::Schedulers::Weekday.new,
).execute
end

def send_full_message
UseCases::Slack::SendMessages.new(
message_presenter: Presenters::Slack::FullMessage.new,
scheduler: UseCases::Slack::Schedulers::Weekday.new
scheduler: UseCases::Slack::Schedulers::Weekday.new,
).execute
end
end
4 changes: 2 additions & 2 deletions env.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'bundler/setup'
require "bundler/setup"

APP_ENV = ENV['RACK_ENV'] || 'development'
APP_ENV = ENV["RACK_ENV"] || "development"

Bundler.require :default, APP_ENV.to_sym
4 changes: 2 additions & 2 deletions helpers/cache.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
def cache(name, cache_duration_seconds = 120)
return yield unless ENV['RACK_ENV'] == 'production'
return yield unless ENV["RACK_ENV"] == "production"

UseCases::Cache.new(
path: "#{Dir.pwd}/public/cache/#{name}.html"
path: "#{Dir.pwd}/public/cache/#{name}.html",
).execute(cache_duration_seconds: cache_duration_seconds) { yield }
end
4 changes: 2 additions & 2 deletions lib/domain/pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ def days_open(opened_at)
days = (Date.today - opened_at).to_i
case days
when 0
'today'
"today"
when 1
'yesterday'
"yesterday"
else
"#{days} days ago"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/gateways/file.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module Gateways
class File
def write(path, content)
::File.open(path, 'w') { |f| f.write(content) }
::File.open(path, "w") { |f| f.write(content) }
end
end
end
4 changes: 2 additions & 2 deletions lib/gateways/gemfile.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require 'open-uri'
require "open-uri"

class GemfileNotFoundException < StandardError; end

Expand All @@ -16,7 +16,7 @@ def execute(application_name:)

private

ORGANIZATION = 'alphagov'.freeze
ORGANIZATION = "alphagov".freeze

def gemfile_url(application_name)
"https://raw.githubusercontent.com/#{ORGANIZATION}/#{application_name}/master/Gemfile.lock"
Expand Down
18 changes: 9 additions & 9 deletions lib/gateways/pull_request.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'octokit'
require "octokit"

module Gateways
class PullRequest
def initialize
@octokit = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'], auto_paginate: true)
@octokit = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"], auto_paginate: true)
end

def execute
Expand All @@ -13,18 +13,18 @@ def execute
private

def approved_pull_requests
approved_pull_requests = @octokit.search_issues('is:pr user:alphagov state:open author:app/dependabot-preview review:approved').items
build_pull_requests(approved_pull_requests, 'approved')
approved_pull_requests = @octokit.search_issues("is:pr user:alphagov state:open author:app/dependabot-preview review:approved").items
build_pull_requests(approved_pull_requests, "approved")
end

def review_required_pull_requests
review_required_pull_requests = @octokit.search_issues('is:pr user:alphagov state:open author:app/dependabot-preview review:required').items
build_pull_requests(review_required_pull_requests, 'review required')
review_required_pull_requests = @octokit.search_issues("is:pr user:alphagov state:open author:app/dependabot-preview review:required").items
build_pull_requests(review_required_pull_requests, "review required")
end

def changes_requested_pull_requests
changes_requested_pull_requests = @octokit.search_issues('is:pr user:alphagov state:open author:app/dependabot-preview review:changes_requested').items
build_pull_requests(changes_requested_pull_requests, 'changes requested')
changes_requested_pull_requests = @octokit.search_issues("is:pr user:alphagov state:open author:app/dependabot-preview review:changes_requested").items
build_pull_requests(changes_requested_pull_requests, "changes requested")
end

def build_pull_requests(api_response, status)
Expand All @@ -46,7 +46,7 @@ def govuk_repository_urls
end

def get_application_name(pull_request)
pull_request.repository_url.split('/').last
pull_request.repository_url.split("/").last
end
end
end
4 changes: 2 additions & 2 deletions lib/gateways/pull_request_count.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
module Gateways
class PullRequestCount
def initialize
@octokit = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'])
@octokit = Octokit::Client.new(access_token: ENV["GITHUB_TOKEN"])
end

def execute
@octokit.search_issues('is:pr user:alphagov author:app/dependabot-preview').total_count
@octokit.search_issues("is:pr user:alphagov author:app/dependabot-preview").total_count
end
end
end
Loading

0 comments on commit 5774909

Please sign in to comment.