Skip to content

Commit 0a7d4a8

Browse files
authored
Merge branch 'master' into upgrade-rails-5.2
2 parents 2a28bdb + b6bd5f3 commit 0a7d4a8

File tree

15 files changed

+142
-27
lines changed

15 files changed

+142
-27
lines changed

.circleci/config.yml

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
version: 2
2+
3+
jobs:
4+
build:
5+
parallelism: 3
6+
working_directory: ~/rails_contributors
7+
docker:
8+
- image: circleci/ruby:2.4-node
9+
environment:
10+
BUNDLE_JOBS: 3
11+
BUNDLE_RETRY: 3
12+
BUNDLE_PATH: vendor/bundle
13+
PGHOST: 127.0.0.1
14+
PGUSER: postgres
15+
RAILS_ENV: test
16+
- image: circleci/postgres:9.5-alpine
17+
environment:
18+
POSTGRES_USER: postgres
19+
POSTGRES_DB: rails_contributors_test
20+
POSTGRES_PASSWORD: ""
21+
steps:
22+
- run:
23+
name: Install dependencies
24+
command: sudo apt-get install -y git cmake pkg-config curl
25+
- checkout
26+
- run:
27+
name: Cloning rails.git
28+
command: git clone --mirror https://github.com/rails/rails.git
29+
- run:
30+
name: Which bundler?
31+
command: bundle -v
32+
- restore_cache:
33+
keys:
34+
- v1-bundle-{{ checksum "Gemfile.lock" }}
35+
- v1-bundle-
36+
- run:
37+
name: Bundle install
38+
command: bundle check || bundle install
39+
- save_cache:
40+
key: v1-bundle-{{ checksum "Gemfile.lock" }}
41+
paths:
42+
- vendor/bundle
43+
- run:
44+
name: Coping database.yml
45+
command: cp config/database.yml.example config/database.yml
46+
- run:
47+
name: Wait for DB
48+
command: dockerize -wait tcp://localhost:5432 -timeout 1m
49+
- run:
50+
name: Database setup
51+
command: bin/rails db:schema:load --trace
52+
- run:
53+
name: Run test
54+
command: bin/rails test

Capfile

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ install_plugin Capistrano::SCM::Git
77
require 'capistrano/rvm'
88
require 'capistrano/rails'
99
require 'capistrano/puma'
10+
install_plugin Capistrano::Puma

Gemfile

+9-9
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
44

55
gem 'rails', '~> 5.2.0'
66
gem 'pg'
7+
gem 'puma', '~> 3.7'
78
gem 'rugged', '0.27.0'
89
gem 'unf'
910
gem 'turbolinks', '~> 5'
@@ -20,19 +21,18 @@ end
2021
group :development do
2122
gem 'web-console', '>= 3.3.0'
2223
gem 'listen', '>= 3.0.5', '< 3.2'
23-
gem 'capistrano', '~> 3.10', require: false
24-
gem 'capistrano-rails', '~> 1.1', require: false
25-
gem 'capistrano-rvm', '0.1.1', require: false
26-
gem 'capistrano3-puma', '~> 1.0', require: false
27-
gem 'rbnacl', '>= 3.2', '< 5.0'
28-
gem 'rbnacl-libsodium'
29-
gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0'
3024
end
3125

3226
group :test do
3327
gem 'rails-controller-testing'
3428
end
3529

36-
group :production do
37-
gem 'puma', '~> 3.7'
30+
group :deployment do
31+
gem 'capistrano', '~> 3.10', require: false
32+
gem 'capistrano-rails', '~> 1.1', require: false
33+
gem 'capistrano-rvm', '0.1.1', require: false
34+
gem 'capistrano3-puma', '~> 3.1', require: false
35+
gem 'rbnacl', '>= 3.2', '< 5.0'
36+
gem 'rbnacl-libsodium'
37+
gem 'bcrypt_pbkdf', '>= 1.0', '< 2.0'
3838
end

Gemfile.lock

+5-4
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ GEM
7171
capistrano-rvm (0.1.1)
7272
capistrano (~> 3.0)
7373
sshkit (~> 1.2)
74-
capistrano3-puma (1.2.1)
75-
capistrano (~> 3.0)
76-
puma (>= 2.6)
74+
capistrano3-puma (3.1.1)
75+
capistrano (~> 3.7)
76+
capistrano-bundler
77+
puma (~> 3.4)
7778
coffee-rails (4.2.2)
7879
coffee-script (>= 2.2.0)
7980
railties (>= 4.0.0)
@@ -208,7 +209,7 @@ DEPENDENCIES
208209
capistrano (~> 3.10)
209210
capistrano-rails (~> 1.1)
210211
capistrano-rvm (= 0.1.1)
211-
capistrano3-puma (~> 1.0)
212+
capistrano3-puma (~> 3.1)
212213
coffee-rails (~> 4.2.1)
213214
listen (>= 3.0.5, < 3.2)
214215
pg

app/controllers/application_controller.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ def set_time_constraints
6262
ichiro |
6363
discobot |
6464
bingbot |
65-
yrspider
65+
FAST |
66+
MauiBot |
67+
yrspider |
68+
SemrushBot
6669
}xi
6770
def trace_user_agent
6871
if request.user_agent =~ BOTS_REGEXP

app/models/contributor.rb

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
class Contributor < ApplicationRecord
2-
has_many :contributions, :dependent => :destroy
3-
has_many :commits, :through => :contributions
2+
has_many :contributions, dependent: :destroy
3+
has_many :commits, through: :contributions
44

5-
validates :name, :presence => true, :uniqueness => true
6-
validates :url_id, :presence => true, :uniqueness => true
5+
validates :name, presence: true, uniqueness: true
6+
validates :url_id, presence: true, uniqueness: true
77

88
nfc :name
99

1010
scope :with_no_commits, -> {
11-
joins('LEFT OUTER JOIN contributions ON contributors.id = contributions.contributor_id').
12-
where('contributions.commit_id' => nil)
11+
left_joins(:contributions).where(contributions: { commit_id: nil })
1312
}
1413

1514
def self.all_with_ncommits

app/models/names_manager/canonical_names.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def self.map(canonical_name, *also_as)
162162
map 'Alexey Zatsepin', 'alexey', 'Alexey'
163163
map 'Aliaksey Kandratsenka', 'Aleksey Kondratenko'
164164
map 'Aliaxandr Rahalevich', 'saksmlz', 'saks'
165-
map 'Alvaro Pereyra', 'Xenda'
165+
map 'Alessandra Pereyra', 'Xenda'
166166
map 'Amit Kumar Suroliya', 'amitkumarsuroliya'
167167
map 'Anand Muthukrishnan', 'Anand'
168168
map 'Anatoli Makarevich', 'Anatoly Makarevich'

config/application.rb

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# you've limited to :test, :development, or :production.
1818
Bundler.require(*Rails.groups)
1919

20+
require './lib/bot_killer'
21+
2022
module RailsContributors
2123
class Application < Rails::Application
2224
# Initialize configuration defaults for originally generated Rails version.
@@ -26,5 +28,7 @@ class Application < Rails::Application
2628
# Application configuration can go into files in config/initializers
2729
# -- all .rb files in that directory are automatically loaded after loading
2830
# the framework and any gems in your application.
31+
32+
config.middleware.insert 0, BotKiller
2933
end
3034
end

config/deploy.rb

+3
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,6 @@
1111
set :linked_dirs, %w{log tmp/pids tmp/cache tmp/sockets public/system public/assets rails.git}
1212

1313
set :keep_releases, 5
14+
15+
set :bundle_without, %w{development test deployment}.join(' ')
16+
set :bundle_gemfile, -> { release_path.join('Gemfile') }

config/deploy/production.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
set :puma_bind, 'unix:/tmp/rails-contributors.sock'
55
set :puma_preload_app, false
6-
set :puma_workers, 2
6+
set :puma_workers, 1
77

88
namespace :deploy do
99
after :normalize_assets, :gzip_assets do

doc/install.md

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ $ sudo apt-get install cmake pkg-config
1818
1919
# deploys trigger a webhook
2020
$ sudo apt-get install curl
21+
22+
# Cryptgraphy library (for deployment only)
23+
$ sudo apt-get install libsodium-dev
2124
```
2225

2326
## Application setup

lib/bot_killer.rb

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
class BotKiller
2+
BLACKLISTED_BOTS = %r{
3+
FAST |
4+
MauiBot
5+
}xi
6+
7+
def initialize(app)
8+
@app = app
9+
end
10+
11+
def call(env)
12+
request = Rack::Request.new(env)
13+
14+
if request.user_agent =~ BLACKLISTED_BOTS
15+
[404, {}, ["Not found"]]
16+
else
17+
@app.call(env)
18+
end
19+
end
20+
end

public/robots.txt

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file
2-
#
3-
# To ban all spiders from the entire site uncomment the next two lines:
4-
# User-Agent: *
5-
# Disallow: /
2+
3+
User-Agent: Google
4+
Allow: /
5+
6+
User-Agent: DuckDuckBot
7+
Allow: /
8+
9+
User-Agent: bingbot
10+
Crawl-delay: 5
11+
Allow: /
12+
13+
User-Agent: *
14+
Disallow: /

test/credits/canonical_names_test.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -4800,7 +4800,7 @@ class CanonicalNamesTest < ActiveSupport::TestCase
48004800
end
48014801

48024802
test 'Xenda' do
4803-
assert_contributor_names 'fabd2ce', 'Alvaro Pereyra'
4803+
assert_contributor_names 'fabd2ce', 'Alessandra Pereyra'
48044804
end
48054805

48064806
test "xyctka\100gmail.com" do

test/integration/bot_killer_test.rb

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
require 'test_helper'
2+
3+
class BotKillerTest < ActionDispatch::IntegrationTest
4+
test 'MauiBot is blacklisted' do
5+
get '/', headers: { 'User-Agent' => 'MauiBot ([email protected])' }
6+
assert_response :not_found
7+
end
8+
9+
test 'FAST Enterprise is blacklisted' do
10+
get '/', headers: { 'User-Agent' => 'FAST Enterprise Crawler/5.3.4 ([email protected])' }
11+
assert_response :not_found
12+
end
13+
14+
test 'other user agests are not blacklisted' do
15+
get '/', headers: { 'User-Agent' => 'Foo' }
16+
assert_response :ok
17+
end
18+
end

0 commit comments

Comments
 (0)