Skip to content

Commit

Permalink
Autocorrect offences from new Rubocop cops
Browse files Browse the repository at this point in the history
  • Loading branch information
timrogers committed Jun 7, 2022
1 parent f87ac9e commit 786d21a
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 61 deletions.
8 changes: 4 additions & 4 deletions lib/octokit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ def respond_to_missing?(method_name, include_private = false)
enterprise_management_console_client.respond_to?(method_name, include_private)
end

def method_missing(method_name, *args, &block)
def method_missing(method_name, *args, &)
if client.respond_to?(method_name)
return client.send(method_name, *args, &block)
return client.send(method_name, *args, &)
elsif enterprise_admin_client.respond_to?(method_name)
return enterprise_admin_client.send(method_name, *args, &block)
return enterprise_admin_client.send(method_name, *args, &)
elsif enterprise_management_console_client.respond_to?(method_name)
return enterprise_management_console_client.send(method_name, *args, &block)
return enterprise_management_console_client.send(method_name, *args, &)
end

super
Expand Down
14 changes: 7 additions & 7 deletions lib/octokit/client/pub_sub_hubbub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ module PubSubHubbub
# client.subscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com")
def subscribe(topic, callback, secret = nil)
options = {
"hub.callback": callback,
"hub.mode": 'subscribe',
"hub.topic": topic
'hub.callback': callback,
'hub.mode': 'subscribe',
'hub.topic': topic
}
options.merge!("hub.secret": secret) unless secret.nil?
options.merge!('hub.secret': secret) unless secret.nil?

response = pub_sub_hubbub_request(options)

Expand All @@ -40,9 +40,9 @@ def subscribe(topic, callback, secret = nil)
# client.unsubscribe("https://github.com/joshk/devise_imapable/events/push", "github://Email?address=josh.kalderimis@gmail.com")
def unsubscribe(topic, callback)
options = {
"hub.callback": callback,
"hub.mode": 'unsubscribe',
"hub.topic": topic
'hub.callback': callback,
'hub.mode': 'unsubscribe',
'hub.topic': topic
}
response = pub_sub_hubbub_request(options)

Expand Down
2 changes: 1 addition & 1 deletion lib/octokit/configurable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ def netrc?
private

def options
Hash[Octokit::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }]
Octokit::Configurable.keys.to_h { |key| [key, instance_variable_get(:"@#{key}")] }
end

def fetch_client_id_and_secret(overrides = {})
Expand Down
36 changes: 18 additions & 18 deletions lib/octokit/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,55 +46,55 @@ class << self
# Configuration options
# @return [Hash]
def options
Hash[Octokit::Configurable.keys.map { |key| [key, send(key)] }]
Octokit::Configurable.keys.to_h { |key| [key, send(key)] }
end

# Default access token from ENV
# @return [String]
def access_token
ENV['OCTOKIT_ACCESS_TOKEN']
ENV.fetch('OCTOKIT_ACCESS_TOKEN', nil)
end

# Default API endpoint from ENV or {API_ENDPOINT}
# @return [String]
def api_endpoint
ENV['OCTOKIT_API_ENDPOINT'] || API_ENDPOINT
ENV.fetch('OCTOKIT_API_ENDPOINT') { API_ENDPOINT }
end

# Default pagination preference from ENV
# @return [String]
def auto_paginate
ENV['OCTOKIT_AUTO_PAGINATE']
ENV.fetch('OCTOKIT_AUTO_PAGINATE', nil)
end

# Default bearer token from ENV
# @return [String]
def bearer_token
ENV['OCTOKIT_BEARER_TOKEN']
ENV.fetch('OCTOKIT_BEARER_TOKEN', nil)
end

# Default OAuth app key from ENV
# @return [String]
def client_id
ENV['OCTOKIT_CLIENT_ID']
ENV.fetch('OCTOKIT_CLIENT_ID', nil)
end

# Default OAuth app secret from ENV
# @return [String]
def client_secret
ENV['OCTOKIT_SECRET']
ENV.fetch('OCTOKIT_SECRET', nil)
end

# Default management console password from ENV
# @return [String]
def management_console_password
ENV['OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD']
ENV.fetch('OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD', nil)
end

# Default management console endpoint from ENV
# @return [String]
def management_console_endpoint
ENV['OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT']
ENV.fetch('OCTOKIT_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT', nil)
end

# Default options for Faraday::Connection
Expand All @@ -111,13 +111,13 @@ def connection_options
# Default media type from ENV or {MEDIA_TYPE}
# @return [String]
def default_media_type
ENV['OCTOKIT_DEFAULT_MEDIA_TYPE'] || MEDIA_TYPE
ENV.fetch('OCTOKIT_DEFAULT_MEDIA_TYPE') { MEDIA_TYPE }
end

# Default GitHub username for Basic Auth from ENV
# @return [String]
def login
ENV['OCTOKIT_LOGIN']
ENV.fetch('OCTOKIT_LOGIN', nil)
end

# Default middleware stack for Faraday::Connection
Expand All @@ -130,21 +130,21 @@ def middleware
# Default GitHub password for Basic Auth from ENV
# @return [String]
def password
ENV['OCTOKIT_PASSWORD']
ENV.fetch('OCTOKIT_PASSWORD', nil)
end

# Default pagination page size from ENV
# @return [Integer] Page size
def per_page
page_size = ENV['OCTOKIT_PER_PAGE']
page_size = ENV.fetch('OCTOKIT_PER_PAGE', nil)

page_size&.to_i
end

# Default proxy server URI for Faraday connection from ENV
# @return [String]
def proxy
ENV['OCTOKIT_PROXY']
ENV.fetch('OCTOKIT_PROXY', nil)
end

# Default SSL verify mode from ENV
Expand All @@ -159,25 +159,25 @@ def ssl_verify_mode
# Default User-Agent header string from ENV or {USER_AGENT}
# @return [String]
def user_agent
ENV['OCTOKIT_USER_AGENT'] || USER_AGENT
ENV.fetch('OCTOKIT_USER_AGENT') { USER_AGENT }
end

# Default web endpoint from ENV or {WEB_ENDPOINT}
# @return [String]
def web_endpoint
ENV['OCTOKIT_WEB_ENDPOINT'] || WEB_ENDPOINT
ENV.fetch('OCTOKIT_WEB_ENDPOINT') { WEB_ENDPOINT }
end

# Default behavior for reading .netrc file
# @return [Boolean]
def netrc
ENV['OCTOKIT_NETRC'] || false
ENV.fetch('OCTOKIT_NETRC', false)
end

# Default path for .netrc file
# @return [String]
def netrc_file
ENV['OCTOKIT_NETRC_FILE'] || File.join(ENV['HOME'].to_s, '.netrc')
ENV.fetch('OCTOKIT_NETRC_FILE') { File.join(Dir.home.to_s, '.netrc') }
end
end
end
Expand Down
1 change: 1 addition & 0 deletions octokit.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,5 @@ Gem::Specification.new do |spec|
spec.required_rubygems_version = '>= 1.3.5'
spec.summary = 'Ruby toolkit for working with the GitHub API'
spec.version = Octokit::VERSION.dup
spec.metadata['rubygems_mfa_required'] = 'true'
end
40 changes: 20 additions & 20 deletions spec/octokit/client/pub_sub_hubbub_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
it 'subscribes to pull events' do
request = stub_post(github_url('/hub'))
.with(body: {
"hub.callback": 'github://Travis?token=travistoken',
"hub.mode": 'subscribe',
"hub.topic": 'https://github.com/elskwid/github-services/events/push',
"hub.secret": '12345'
'hub.callback': 'github://Travis?token=travistoken',
'hub.mode': 'subscribe',
'hub.topic': 'https://github.com/elskwid/github-services/events/push',
'hub.secret': '12345'
})
.to_return(status: 204)
result = @client.subscribe('https://github.com/elskwid/github-services/events/push',
Expand All @@ -26,9 +26,9 @@

it 'raises an error when topic is not recognized', :vcr do
subscribe_request_body = {
"hub.callback": 'github://Travis?token=travistoken',
"hub.mode": 'subscribe',
"hub.topic": 'https://github.com/joshk/not_existing_project/events/push'
'hub.callback': 'github://Travis?token=travistoken',
'hub.mode': 'subscribe',
'hub.topic': 'https://github.com/joshk/not_existing_project/events/push'
}
expect do
@client.subscribe('https://github.com/joshk/not_existing_project/events/push',
Expand All @@ -42,9 +42,9 @@
describe '.unsubscribe', :vcr do
it 'unsubscribes from pull events' do
unsubscribe_request_body = {
"hub.callback": 'github://Travis?token=travistoken',
"hub.mode": 'unsubscribe',
"hub.topic": "https://github.com/#{@test_repo}/events/push"
'hub.callback': 'github://Travis?token=travistoken',
'hub.mode': 'unsubscribe',
'hub.topic': "https://github.com/#{@test_repo}/events/push"
}

result = @client.unsubscribe("https://github.com/#{@test_repo}/events/push", 'github://Travis?token=travistoken')
Expand All @@ -58,10 +58,10 @@
it 'subscribes to pull event on specified topic' do
request = stub_post(github_url('/hub'))
.with(body: {
"hub.callback": 'github://Travis?token=travistoken',
"hub.mode": 'subscribe',
"hub.topic": 'https://github.com/elskwid/github-services/events/push',
"hub.secret": '12345'
'hub.callback': 'github://Travis?token=travistoken',
'hub.mode': 'subscribe',
'hub.topic': 'https://github.com/elskwid/github-services/events/push',
'hub.secret': '12345'
})
.to_return(status: 204)
result = @client.subscribe_service_hook('elskwid/github-services', 'Travis', { token: 'travistoken' }, '12345')
Expand All @@ -71,9 +71,9 @@

it 'encodes URL parameters', :vcr do
irc_request_body = {
"hub.callback": 'github://irc?server=chat.freenode.org&room=%23myproject',
"hub.mode": 'subscribe',
"hub.topic": 'https://github.com/joshk/completeness-fu/events/push'
'hub.callback': 'github://irc?server=chat.freenode.org&room=%23myproject',
'hub.mode': 'subscribe',
'hub.topic': 'https://github.com/joshk/completeness-fu/events/push'
}
stub_post('/hub')
.with(body: irc_request_body)
Expand All @@ -91,9 +91,9 @@
describe 'unsubscribe_service_hook', :vcr do
it 'unsubscribes to stop receiving events on specified topic' do
unsubscribe_request_body = {
"hub.callback": 'github://Travis',
"hub.mode": 'unsubscribe',
"hub.topic": "https://github.com/#{@test_repo}/events/push"
'hub.callback': 'github://Travis',
'hub.mode': 'unsubscribe',
'hub.topic': "https://github.com/#{@test_repo}/events/push"
}
expect(@client.unsubscribe_service_hook(@test_repo, 'Travis')).to eq(true)
assert_requested :post, github_url('/hub'), body: unsubscribe_request_body, times: 1,
Expand Down
18 changes: 9 additions & 9 deletions spec/octokit/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
client = Octokit::Client.new(@opts)
expect(client.per_page).to eq(40)
expect(client.login).to eq('defunkt')
expect(client.instance_variable_get(:"@password")).to eq('il0veruby')
expect(client.instance_variable_get(:@password)).to eq('il0veruby')
expect(client.auto_paginate).to eq(Octokit.auto_paginate)
expect(client.client_id).to eq(Octokit.client_id)
end
Expand All @@ -79,7 +79,7 @@
end
expect(client.per_page).to eq(40)
expect(client.login).to eq('defunkt')
expect(client.instance_variable_get(:"@password")).to eq('il0veruby')
expect(client.instance_variable_get(:@password)).to eq('il0veruby')
expect(client.auto_paginate).to eq(Octokit.auto_paginate)
expect(client.client_id).to eq(Octokit.client_id)
end
Expand Down Expand Up @@ -117,15 +117,15 @@
Octokit.reset!
client = Octokit::Client.new(netrc: true, netrc_file: File.join(fixture_path, '.netrc'))
expect(client.login).to eq('sferik')
expect(client.instance_variable_get(:"@password")).to eq('il0veruby')
expect(client.instance_variable_get(:@password)).to eq('il0veruby')
end

it 'can read non-standard API endpoint creds from .netrc' do
Octokit.reset!
client = Octokit::Client.new(netrc: true, netrc_file: File.join(fixture_path, '.netrc'),
api_endpoint: 'http://api.github.dev')
expect(client.login).to eq('defunkt')
expect(client.instance_variable_get(:"@password")).to eq('il0veruby')
expect(client.instance_variable_get(:@password)).to eq('il0veruby')
end
end
end
Expand Down Expand Up @@ -442,7 +442,7 @@
Octokit.configure do |config|
config.proxy = 'http://proxy.example.com:80'
end
conn = Octokit.client.send(:agent).instance_variable_get(:"@conn")
conn = Octokit.client.send(:agent).instance_variable_get(:@conn)
expect(conn.proxy[:uri].to_s).to eq('http://proxy.example.com')
end
it 'no sets an ssl verify' do
Expand All @@ -453,27 +453,27 @@
client = Octokit::Client.new(
connection_options: { ssl: { verify: true } }
)
conn = client.send(:agent).instance_variable_get(:"@conn")
conn = client.send(:agent).instance_variable_get(:@conn)
expect(conn.ssl[:verify]).to eq(true)
expect(conn.ssl[:verify_mode]).to eq(OpenSSL::SSL::VERIFY_PEER)
end
it 'sets an ssl verify => false' do
client = Octokit::Client.new(
connection_options: { ssl: { verify: false } }
)
conn = client.send(:agent).instance_variable_get(:"@conn")
conn = client.send(:agent).instance_variable_get(:@conn)
expect(conn.ssl[:verify]).to eq(false)
expect(conn.ssl[:verify_mode]).to eq(OpenSSL::SSL::VERIFY_NONE)
end
it 'sets an ssl verify mode' do
Octokit.configure do |config|
config.ssl_verify_mode = OpenSSL::SSL::VERIFY_NONE
end
conn = Octokit.client.send(:agent).instance_variable_get(:"@conn")
conn = Octokit.client.send(:agent).instance_variable_get(:@conn)
expect(conn.ssl[:verify_mode]).to eq(OpenSSL::SSL::VERIFY_NONE)
end
it 'ensures ssl verify mode is set to default when no override provided' do
conn = Octokit.client.send(:agent).instance_variable_get(:"@conn")
conn = Octokit.client.send(:agent).instance_variable_get(:@conn)
expect(conn.ssl[:verify_mode]).to eq(OpenSSL::SSL::VERIFY_PEER)
end
it 'passes along request headers for POST' do
Expand Down
4 changes: 2 additions & 2 deletions spec/octokit/enterprise_admin_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
fixture_path, '.netrc'
))
expect(admin_client.login).to eq('sferik')
expect(admin_client.instance_variable_get(:"@password")).to eq('il0veruby')
expect(admin_client.instance_variable_get(:@password)).to eq('il0veruby')
end

it 'can read non-standard API endpoint creds from .netrc' do
Octokit.reset!
admin_client = Octokit::EnterpriseAdminClient.new(netrc: true,
netrc_file: File.join(fixture_path, '.netrc'), api_endpoint: 'http://api.github.dev')
expect(admin_client.login).to eq('defunkt')
expect(admin_client.instance_variable_get(:"@password")).to eq('il0veruby')
expect(admin_client.instance_variable_get(:@password)).to eq('il0veruby')
end
end
end
Expand Down

0 comments on commit 786d21a

Please sign in to comment.