Skip to content

Commit e815818

Browse files
committed
Run rubyocop -a.
1 parent 86bcbcf commit e815818

File tree

9 files changed

+44
-52
lines changed

9 files changed

+44
-52
lines changed

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
source "https://rubygems.org"
1+
source 'https://rubygems.org'
22

3-
ruby "2.2.5"
3+
ruby '2.2.5'
44

55
gem 'sinatra'
66
gem 'json'
@@ -12,7 +12,7 @@ group :development do
1212
gem 'guard-rubocop'
1313
end
1414

15-
group :test do
15+
group :test do
1616
gem 'rack-test'
1717
gem 'rspec'
1818
gem 'rspec-sinatra'

Guardfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
guard :rspec, cmd: "bundle exec rspec" do
1+
guard :rspec, cmd: 'bundle exec rspec' do
22
require 'guard/rspec/dsl'
33
dsl = Guard::RSpec::Dsl.new(self)
44

@@ -14,6 +14,6 @@ guard :rspec, cmd: "bundle exec rspec" do
1414
end
1515

1616
guard :rubocop do
17-
watch(%r{.+\.rb$})
17+
watch(/.+\.rb$/)
1818
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
1919
end

lib/api.rb

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,9 @@
22
require 'octokit'
33

44
class API
5-
65
attr_accessor :github_client
76

8-
def initialize(github_client = Octokit::Client.new(:access_token => ENV['GITHUB_TOKEN']))
7+
def initialize(github_client = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN']))
98
@github_client = github_client
109
end
1110

@@ -16,32 +15,29 @@ def handle_push(push)
1615
team_id = ENV['CONTRIBUTOR_TEAM_ID']
1716
pr_number = pull_request['number']
1817
repo_name = pull_request['base']['repo']['full_name']
19-
18+
2019
if needs_invitation?(team_id, username)
2120
invite_and_comment(team_id, username, pr_number, repo_name)
22-
return {'msg' => 'Invitation sent.'}
21+
return { 'msg' => 'Invitation sent.' }
2322
else
24-
return {'msg' => 'Already a member.'}
23+
return { 'msg' => 'Already a member.' }
2524
end
2625
else
27-
return {'msg' => 'Pull request not yet merged.'}
26+
return { 'msg' => 'Pull request not yet merged.' }
2827
end
2928
end
3029

31-
3230
def is_merged?(push)
3331
push['action'] == 'closed' && push['pull_request'] && push['pull_request']['merged'] == true
3432
end
3533

3634
def needs_invitation?(team_id, username)
37-
begin
38-
# This raises if the user has not been invited yet, as the happy
39-
# path is 'user invitation is pending' or 'user has accepted'.
40-
@github_client.team_membership(team_id, username)
41-
return false
42-
rescue Octokit::NotFound
43-
return true
44-
end
35+
# This raises if the user has not been invited yet, as the happy
36+
# path is 'user invitation is pending' or 'user has accepted'.
37+
@github_client.team_membership(team_id, username)
38+
return false
39+
rescue Octokit::NotFound
40+
return true
4541
end
4642

4743
def invite_and_comment(team_id, username, pr_number, repo_name)

lib/ping_checker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ class PingChecker
22
def is_ping?(push)
33
push['zen'].nil? == false
44
end
5-
end
5+
end

lib/server.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
require './lib/signature_verifier'
77

88
class AerynApp < Sinatra::Base
9-
109
set :logging, true
1110

1211
attr_accessor :signature_verifier
@@ -17,7 +16,7 @@ def initialize(
1716
signature_verifier = SignatureVerifier.new,
1817
ping_checker = PingChecker.new,
1918
api = API.new
20-
)
19+
)
2120
@signature_verifier = signature_verifier
2221
@ping_checker = ping_checker
2322
@api = api
@@ -36,12 +35,12 @@ def initialize(
3635

3736
if is_ping
3837
logger.info 'Received ping.'
39-
halt 200, {'Content-Type' => 'text/plain'}, 'Pong.'
38+
halt 200, { 'Content-Type' => 'text/plain' }, 'Pong.'
4039
end
4140

4241
unless is_valid_sig
4342
logger.info "Received Unauthorized request: #{request}"
44-
halt 403, "Unauthorized."
43+
halt 403, 'Unauthorized.'
4544
end
4645

4746
logger.info 'Received PR action.'

lib/signature_verifier.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
require 'sinatra'
22

33
class SignatureVerifier
4-
54
def verify_signature(payload_body, request)
65
signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), ENV['WEBHOOK_SECRET_TOKEN'], payload_body)
76
header = request.env['HTTP_X_HUB_SIGNATURE']
87
return false unless header
98
return false unless Rack::Utils.secure_compare(signature, header)
109
end
11-
1210
end

spec/api_spec.rb

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,38 @@
66
let(:api) { API.new(github_client) }
77
let(:github_client) { double(Octokit::Client) }
88

9-
109
it 'does not invite for unmerged PRs' do
11-
result = api.handle_push({'action' => 'closed', 'pull_request' => {'merged' => false}})
10+
result = api.handle_push('action' => 'closed', 'pull_request' => { 'merged' => false })
1211

1312
expect(result['msg']) == 'Pull request not yet merged.'
1413
end
1514

1615
it 'does not re-invite members' do
1716
allow(github_client).to receive(:team_membership).with('1234567', 'splendid_username')
18-
19-
result = api.handle_push({'action' => 'closed',
20-
'pull_request' => {
21-
'merged' => true,
22-
'number' => 13,
23-
'user' => {'login' => 'splendid_username'},
24-
'base' => {'repo' => {'full_name' => 'my_repo'}}
25-
}})
17+
18+
result = api.handle_push('action' => 'closed',
19+
'pull_request' => {
20+
'merged' => true,
21+
'number' => 13,
22+
'user' => { 'login' => 'splendid_username' },
23+
'base' => { 'repo' => { 'full_name' => 'my_repo' } }
24+
})
2625

2726
expect(result['msg']).to eq('Already a member.')
2827
end
2928

3029
it 'adds team membership and sends a friendly comment' do
31-
allow(github_client).to receive(:team_membership).with('1234567', 'splendid_username').and_raise (Octokit::NotFound)
30+
allow(github_client).to receive(:team_membership).with('1234567', 'splendid_username').and_raise Octokit::NotFound
3231
allow(github_client).to receive(:add_team_membership).with('1234567', 'splendid_username')
3332
allow(github_client).to receive(:add_comment).with('my_repo', 13, 'Thanks!')
3433

35-
result = api.handle_push({'action' => 'closed',
36-
'pull_request' => {
37-
'merged' => true,
38-
'number' => 13,
39-
'user' => {'login' => 'splendid_username'},
40-
'base' => {'repo' => {'full_name' => 'my_repo'}}
41-
}})
34+
result = api.handle_push('action' => 'closed',
35+
'pull_request' => {
36+
'merged' => true,
37+
'number' => 13,
38+
'user' => { 'login' => 'splendid_username' },
39+
'base' => { 'repo' => { 'full_name' => 'my_repo' } }
40+
})
4241

4342
expect(result['msg']) == 'Invitation sent.'
4443
end

spec/ping_checker_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
let(:subject) { PingChecker.new }
55

66
it 'handles a ping' do
7-
expect(subject.is_ping? '{"zen": "Howdy there!"}' ).to be_truthy
7+
expect(subject.is_ping?('{"zen": "Howdy there!"}')).to be_truthy
88
end
99

1010
it 'handles non-pings' do
11-
expect(subject.is_ping? '{"boring_pr_data": "so boring"}' ).to be_falsey
11+
expect(subject.is_ping?('{"boring_pr_data": "so boring"}')).to be_falsey
1212
end
13-
end
13+
end

spec/server_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
it 'passes on to the api' do
3131
allow(signature_verifier).to receive(:verify_signature).and_return(true)
3232
allow(ping_checker).to receive(:is_ping?).and_return(false)
33-
allow(api).to receive(:handle_push).and_return ({'msg' => 'Everything is fine.'})
34-
33+
allow(api).to receive(:handle_push).and_return ({ 'msg' => 'Everything is fine.' })
34+
3535
post '/payload', '{}'
3636

3737
expect(last_response).to be_ok
@@ -42,8 +42,8 @@
4242
it 'defers to the api for response code' do
4343
allow(signature_verifier).to receive(:verify_signature).and_return(true)
4444
allow(ping_checker).to receive(:is_ping?).and_return(false)
45-
allow(api).to receive(:handle_push).and_return({'error' => 'Something went wrong.'})
46-
45+
allow(api).to receive(:handle_push).and_return('error' => 'Something went wrong.')
46+
4747
post '/payload', '{}'
4848

4949
expect(last_response.status) == 400

0 commit comments

Comments
 (0)