From d4f282c18dc7aa5cd95ed745462ea525bc7c3593 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Tue, 7 Jun 2022 13:04:14 +0100 Subject: [PATCH 01/13] Fix Rubocop configuration so Rubocop can run --- .rubocop.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rubocop.yml b/.rubocop.yml index 621674e56..0b45c8611 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,3 @@ Metrics/BlockLength: Exclude: - spec/**/*_spec.rb + - spec/**/*_spec.rb From eb635d86f39495def2b04893427f3eb8575b0208 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Tue, 7 Jun 2022 18:08:20 +0100 Subject: [PATCH 02/13] Run Rubocop in GitHub Actions on push and PR --- .github/workflows/octokit.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/octokit.yml b/.github/workflows/octokit.yml index c931902ea..2c3cbaa49 100644 --- a/.github/workflows/octokit.yml +++ b/.github/workflows/octokit.yml @@ -56,3 +56,7 @@ jobs: GITHUB_CI: 1 RUBYOPT: --enable-frozen-string-literal run: bundle exec rspec -w + - name: Lint with Rubocop + env: + GITHUB_CI: 1 + run: bundle exec rubocop From 748555927d6373cc661eac12170c19a84d9f9eeb Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Tue, 7 Jun 2022 18:33:43 +0100 Subject: [PATCH 03/13] Use Rubocop v0.81, the last version to support Ruby 2.3 --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index da391776d..695cd6fe1 100644 --- a/Gemfile +++ b/Gemfile @@ -33,13 +33,13 @@ group :test do end gem 'faraday', ENV.fetch('FARADAY_VERSION', '~> 2.0') -gem 'faraday-retry' gem 'faraday-multipart' +gem 'faraday-retry' group :test, :development do gem 'pry-byebug' gem 'redcarpet' - gem 'rubocop' + gem 'rubocop', '0.81' end gemspec From a53cb0aeb1d95ec612609ce0c24e4d4171b08069 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Tue, 7 Jun 2022 18:26:33 +0100 Subject: [PATCH 04/13] Target Rubocop to Ruby 2.3, our earliest supported Ruby version --- .rubocop.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 0b45c8611..cdb9c484c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +AllCops: + TargetRubyVersion: 2.3 Metrics/BlockLength: Exclude: - spec/**/*_spec.rb From ff8dc9c181e84de008c973db1745a65d895c1f9c Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Tue, 7 Jun 2022 18:36:41 +0100 Subject: [PATCH 05/13] Enable new Rubocop cops that have not been turned on yet --- .rubocop.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index cdb9c484c..15b38d111 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,3 +3,13 @@ AllCops: Metrics/BlockLength: Exclude: - spec/**/*_spec.rb +Lint/RaiseException: + Enabled: true +Lint/StructNewOverride: + Enabled: true +Style/HashEachMethods: + Enabled: true +Style/HashTransformKeys: + Enabled: true +Style/HashTransformValues: + Enabled: true \ No newline at end of file From b2aa43fa9201c6cddbd821b9923242eeb4972eca Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Tue, 7 Jun 2022 18:37:41 +0100 Subject: [PATCH 06/13] Autocorrect Rubocop offences --- Guardfile | 8 +- Rakefile | 8 +- lib/ext/sawyer/relation.rb | 6 +- lib/octokit.rb | 20 +- lib/octokit/arguments.rb | 4 +- lib/octokit/authentication.rb | 9 +- lib/octokit/client.rb | 29 +- lib/octokit/client/actions_secrets.rb | 5 +- lib/octokit/client/actions_workflow_runs.rb | 2 + lib/octokit/client/actions_workflows.rb | 3 +- lib/octokit/client/apps.rb | 52 +- lib/octokit/client/authorizations.rb | 37 +- lib/octokit/client/checks.rb | 10 +- lib/octokit/client/commit_branches.rb | 4 +- lib/octokit/client/commit_comments.rb | 16 +- lib/octokit/client/commit_pulls.rb | 4 +- lib/octokit/client/commits.rb | 58 +- lib/octokit/client/community_profile.rb | 4 +- lib/octokit/client/contents.rb | 37 +- lib/octokit/client/deployments.rb | 12 +- lib/octokit/client/downloads.rb | 11 +- lib/octokit/client/emojis.rb | 6 +- lib/octokit/client/events.rb | 8 +- lib/octokit/client/feeds.rb | 9 +- lib/octokit/client/gists.rb | 12 +- lib/octokit/client/gitignore.rb | 6 +- lib/octokit/client/hooks.rb | 20 +- lib/octokit/client/issues.rb | 28 +- lib/octokit/client/labels.rb | 12 +- lib/octokit/client/legacy_search.rb | 6 +- lib/octokit/client/licenses.rb | 6 +- lib/octokit/client/markdown.rb | 6 +- lib/octokit/client/marketplace.rb | 8 +- lib/octokit/client/meta.rb | 9 +- lib/octokit/client/milestones.rb | 10 +- lib/octokit/client/notifications.rb | 12 +- lib/octokit/client/oauth_applications.rb | 2 - lib/octokit/client/objects.rb | 28 +- lib/octokit/client/organizations.rb | 84 +- lib/octokit/client/pages.rb | 6 +- lib/octokit/client/projects.rb | 37 +- lib/octokit/client/pub_sub_hubbub.rb | 28 +- lib/octokit/client/pull_requests.rb | 83 +- lib/octokit/client/rate_limit.rb | 20 +- lib/octokit/client/reactions.rb | 12 +- lib/octokit/client/refs.rb | 27 +- lib/octokit/client/releases.rb | 26 +- lib/octokit/client/repositories.rb | 72 +- lib/octokit/client/repository_invitations.rb | 6 +- lib/octokit/client/reviews.rb | 14 +- lib/octokit/client/say.rb | 9 +- lib/octokit/client/search.rb | 18 +- lib/octokit/client/service_status.rb | 4 +- lib/octokit/client/source_import.rb | 12 +- lib/octokit/client/stats.rb | 19 +- lib/octokit/client/statuses.rb | 10 +- lib/octokit/client/traffic.rb | 5 +- lib/octokit/client/users.rb | 53 +- lib/octokit/configurable.rb | 56 +- lib/octokit/connection.rb | 35 +- lib/octokit/default.rb | 32 +- lib/octokit/enterprise_admin_client.rb | 7 +- .../enterprise_admin_client/admin_stats.rb | 27 +- .../enterprise_admin_client/license.rb | 7 +- lib/octokit/enterprise_admin_client/orgs.rb | 7 +- .../search_indexing.rb | 15 +- lib/octokit/enterprise_admin_client/users.rb | 9 +- .../enterprise_management_console_client.rb | 6 +- .../management_console.rb | 60 +- lib/octokit/error.rb | 44 +- lib/octokit/gist.rb | 5 +- lib/octokit/middleware/follow_redirects.rb | 23 +- lib/octokit/organization.rb | 4 +- lib/octokit/preview.rb | 58 +- lib/octokit/rate_limit.rb | 6 +- lib/octokit/repo_arguments.rb | 5 +- lib/octokit/repository.rb | 47 +- lib/octokit/response/base_middleware.rb | 2 + lib/octokit/response/feed_parser.rb | 8 +- lib/octokit/response/raise_error.rb | 4 +- lib/octokit/user.rb | 6 +- lib/octokit/version.rb | 2 + lib/octokit/warnable.rb | 9 +- octokit.gemspec | 17 +- spec/helper.rb | 103 +- spec/octokit/client/actions_secrets_spec.rb | 50 +- .../client/actions_workflow_runs_spec.rb | 4 +- spec/octokit/client/actions_workflows_spec.rb | 10 +- spec/octokit/client/apps_spec.rb | 215 ++-- spec/octokit/client/authorizations_spec.rb | 103 +- spec/octokit/client/checks_spec.rb | 218 ++-- spec/octokit/client/commit_branches_spec.rb | 13 +- spec/octokit/client/commit_comments_spec.rb | 50 +- spec/octokit/client/commit_pulls_spec.rb | 13 +- spec/octokit/client/commits_spec.rb | 167 +-- spec/octokit/client/community_profile_spec.rb | 4 +- spec/octokit/client/contents_spec.rb | 151 ++- spec/octokit/client/deployments_spec.rb | 43 +- spec/octokit/client/downloads_spec.rb | 30 +- spec/octokit/client/emojis_spec.rb | 7 +- spec/octokit/client/events_spec.rb | 85 +- spec/octokit/client/feeds_spec.rb | 24 +- spec/octokit/client/gists_spec.rb | 162 ++- spec/octokit/client/gitignore_spec.rb | 20 +- spec/octokit/client/hooks_spec.rb | 101 +- spec/octokit/client/issues_spec.rb | 197 +-- spec/octokit/client/labels_spec.rb | 93 +- spec/octokit/client/legacy_search_spec.rb | 38 +- spec/octokit/client/licenses_spec.rb | 23 +- spec/octokit/client/markdown_spec.rb | 12 +- spec/octokit/client/marketplace_spec.rb | 28 +- spec/octokit/client/meta_spec.rb | 10 +- spec/octokit/client/milestones_spec.rb | 29 +- spec/octokit/client/notifications_spec.rb | 51 +- .../octokit/client/oauth_applications_spec.rb | 58 +- spec/octokit/client/objects_spec.rb | 72 +- spec/octokit/client/organizations_spec.rb | 255 ++-- spec/octokit/client/pages_spec.rb | 43 +- spec/octokit/client/projects_spec.rb | 118 +- spec/octokit/client/pub_sub_hubbub_spec.rb | 119 +- spec/octokit/client/pull_requests_spec.rb | 146 ++- spec/octokit/client/rate_limit_spec.rb | 32 +- spec/octokit/client/reactions_spec.rb | 92 +- spec/octokit/client/refs_spec.rb | 107 +- spec/octokit/client/releases_spec.rb | 127 +- spec/octokit/client/repositories_spec.rb | 432 ++++--- .../client/repository_invitations_spec.rb | 46 +- spec/octokit/client/reviews_spec.rb | 26 +- spec/octokit/client/say_spec.rb | 15 +- spec/octokit/client/search_spec.rb | 50 +- spec/octokit/client/service_status_spec.rb | 28 +- spec/octokit/client/source_import_spec.rb | 66 +- spec/octokit/client/stats_spec.rb | 162 +-- spec/octokit/client/statuses_spec.rb | 22 +- spec/octokit/client/traffic_spec.rb | 18 +- spec/octokit/client/users_spec.rb | 262 ++-- spec/octokit/client_spec.rb | 1054 ++++++++--------- .../admin_stats_spec.rb | 72 +- .../enterprise_admin_client/license_spec.rb | 11 +- .../enterprise_admin_client/orgs_spec.rb | 11 +- .../search_indexing_spec.rb | 86 +- .../enterprise_admin_client/users_spec.rb | 85 +- spec/octokit/enterprise_admin_client_spec.rb | 30 +- .../management_console_spec.rb | 109 +- .../enterprise_management_console_spec.rb | 10 +- spec/octokit/gist_spec.rb | 29 +- spec/octokit/organization_spec.rb | 14 +- spec/octokit/rate_limit_spec.rb | 41 +- spec/octokit/repository_spec.rb | 191 +-- spec/octokit/user_spec.rb | 16 +- spec/octokit_spec.rb | 21 +- yard/default/layout/html/setup.rb | 6 +- 152 files changed, 3875 insertions(+), 3834 deletions(-) diff --git a/Guardfile b/Guardfile index 449d4de4d..3aba788bd 100644 --- a/Guardfile +++ b/Guardfile @@ -1,5 +1,7 @@ -guard "rspec", :cmd => "bundle exec rspec" do +# frozen_string_literal: true + +guard 'rspec', cmd: 'bundle exec rspec' do watch(%r{^spec/.+_spec\.rb$}) - watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } - watch("spec/helper.rb") { "spec" } + watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" } + watch('spec/helper.rb') { 'spec' } end diff --git a/Rakefile b/Rakefile index fccd9d226..bbf93557c 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,13 @@ +# frozen_string_literal: true + require 'bundler' Bundler::GemHelper.install_tasks require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -task :test => :spec -task :default => :spec +task test: :spec +task default: :spec namespace :doc do begin @@ -14,7 +16,7 @@ namespace :doc do task.files = ['README.md', 'LICENSE.md', 'lib/**/*.rb'] task.options = [ '--output-dir', 'doc/yard', - '--markup', 'markdown', + '--markup', 'markdown' ] end rescue LoadError diff --git a/lib/ext/sawyer/relation.rb b/lib/ext/sawyer/relation.rb index dd0665943..84e975be2 100644 --- a/lib/ext/sawyer/relation.rb +++ b/lib/ext/sawyer/relation.rb @@ -1,9 +1,11 @@ +# frozen_string_literal: true + require 'sawyer' patch = Module.new do - def href(options=nil) + def href(options = nil) # Temporary workaround for: https://github.com/octokit/octokit.rb/issues/727 - name.to_s == "ssh" ? @href : super + name.to_s == 'ssh' ? @href : super end end diff --git a/lib/octokit.rb b/lib/octokit.rb index b27e3257b..cf5340aad 100644 --- a/lib/octokit.rb +++ b/lib/octokit.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'octokit/default' require 'octokit/client' require 'octokit/enterprise_admin_client' @@ -13,6 +15,7 @@ class << self # @return [Octokit::Client] API wrapper def client return @client if defined?(@client) && @client.same_options?(options) + @client = Octokit::Client.new(options) end @@ -20,7 +23,10 @@ def client # # @return [Octokit::EnterpriseAdminClient] API wrapper def enterprise_admin_client - return @enterprise_admin_client if defined?(@enterprise_admin_client) && @enterprise_admin_client.same_options?(options) + if defined?(@enterprise_admin_client) && @enterprise_admin_client.same_options?(options) + return @enterprise_admin_client + end + @enterprise_admin_client = Octokit::EnterpriseAdminClient.new(options) end @@ -28,16 +34,19 @@ def enterprise_admin_client # # @return [Octokit::EnterpriseManagementConsoleClient] API wrapper def enterprise_management_console_client - return @enterprise_management_console_client if defined?(@enterprise_management_console_client) && @enterprise_management_console_client.same_options?(options) + if defined?(@enterprise_management_console_client) && @enterprise_management_console_client.same_options?(options) + return @enterprise_management_console_client + end + @enterprise_management_console_client = Octokit::EnterpriseManagementConsoleClient.new(options) end private - def respond_to_missing?(method_name, include_private=false) + def respond_to_missing?(method_name, include_private = false) client.respond_to?(method_name, include_private) || - enterprise_admin_client.respond_to?(method_name, include_private) || - enterprise_management_console_client.respond_to?(method_name, include_private) + enterprise_admin_client.respond_to?(method_name, include_private) || + enterprise_management_console_client.respond_to?(method_name, include_private) end def method_missing(method_name, *args, &block) @@ -51,7 +60,6 @@ def method_missing(method_name, *args, &block) super end - end end diff --git a/lib/octokit/arguments.rb b/lib/octokit/arguments.rb index 961e3b98b..d329ec492 100644 --- a/lib/octokit/arguments.rb +++ b/lib/octokit/arguments.rb @@ -1,5 +1,6 @@ -module Octokit +# frozen_string_literal: true +module Octokit # Extracts options from method arguments # @private class Arguments < Array @@ -9,6 +10,5 @@ def initialize(args) @options = args.last.is_a?(::Hash) ? args.pop : {} super(args) end - end end diff --git a/lib/octokit/authentication.rb b/lib/octokit/authentication.rb index 9b7c7387b..48a4c3e62 100644 --- a/lib/octokit/authentication.rb +++ b/lib/octokit/authentication.rb @@ -1,12 +1,12 @@ -module Octokit +# frozen_string_literal: true +module Octokit # Authentication methods for {Octokit::Client} module Authentication - # In Faraday 2.x, the authorization middleware uses new interface FARADAY_BASIC_AUTH_KEYS = if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0') - [:authorization, :basic] + %i[authorization basic] else [:basic_auth] end @@ -74,8 +74,7 @@ def login_from_netrc self.password = creds.shift end rescue LoadError - octokit_warn "Please install netrc gem for .netrc support" + octokit_warn 'Please install netrc gem for .netrc support' end - end end diff --git a/lib/octokit/client.rb b/lib/octokit/client.rb index e648c3133..43c8947f5 100644 --- a/lib/octokit/client.rb +++ b/lib/octokit/client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'octokit/connection' require 'octokit/warnable' require 'octokit/arguments' @@ -64,12 +66,10 @@ require 'ext/sawyer/relation' module Octokit - # Client for the GitHub API # # @see https://developer.github.com class Client - include Octokit::Authentication include Octokit::Configurable include Octokit::Connection @@ -128,11 +128,11 @@ class Client include Octokit::Client::Users # Header keys that can be passed in options hash to {#get},{#head} - CONVENIENCE_HEADERS = Set.new([:accept, :content_type]) + CONVENIENCE_HEADERS = Set.new(%i[accept content_type]) def initialize(options = {}) # Use options passed in, but fall back to module defaults - Octokit::Configurable.keys.each do |key| + Octokit::Configurable.each_key do |key| value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key] instance_variable_set(:"@#{key}", value) end @@ -148,11 +148,17 @@ def inspect # mask password inspected.gsub! @password, '*******' if @password - inspected.gsub! @management_console_password, '*******' if @management_console_password + if @management_console_password + inspected.gsub! @management_console_password, '*******' + end inspected.gsub! @bearer_token, '********' if @bearer_token # Only show last 4 of token, secret - inspected.gsub! @access_token, "#{'*'*36}#{@access_token[36..-1]}" if @access_token - inspected.gsub! @client_secret, "#{'*'*36}#{@client_secret[36..-1]}" if @client_secret + if @access_token + inspected.gsub! @access_token, "#{'*' * 36}#{@access_token[36..-1]}" + end + if @client_secret + inspected.gsub! @client_secret, "#{'*' * 36}#{@client_secret[36..-1]}" + end inspected end @@ -170,11 +176,12 @@ def inspect # # GET https://foo:bar@api.github.com/ # client.get "/" # end - def as_app(key = client_id, secret = client_secret, &block) + def as_app(key = client_id, secret = client_secret) if key.to_s.empty? || secret.to_s.empty? - raise ApplicationCredentialsRequired, "client_id and client_secret required" + raise ApplicationCredentialsRequired, 'client_id and client_secret required' end - app_client = self.dup + + app_client = dup app_client.client_id = app_client.client_secret = nil app_client.login = key app_client.password = secret @@ -235,7 +242,7 @@ def client_without_redirects(options = {}) conn_opts[:url] = @api_endpoint conn_opts[:builder] = @middleware.dup if @middleware conn_opts[:proxy] = @proxy if @proxy - conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode + conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode conn = Faraday.new(conn_opts) do |http| if basic_authenticated? http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password diff --git a/lib/octokit/client/actions_secrets.rb b/lib/octokit/client/actions_secrets.rb index 9407cbd57..de826dc12 100644 --- a/lib/octokit/client/actions_secrets.rb +++ b/lib/octokit/client/actions_secrets.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Actions Secrets API # # @see https://developer.github.com/v3/actions/secrets/ module ActionsSecrets - # Get public key for secrets encryption # # @param repo [Integer, String, Hash, Repository] A GitHub repository @@ -15,7 +15,6 @@ def get_public_key(repo) get "#{Repository.path repo}/actions/secrets/public-key" end - # List secrets # # @param repo [Integer, String, Hash, Repository] A GitHub repository diff --git a/lib/octokit/client/actions_workflow_runs.rb b/lib/octokit/client/actions_workflow_runs.rb index 7e44e8fa1..9d9bfb0bb 100644 --- a/lib/octokit/client/actions_workflow_runs.rb +++ b/lib/octokit/client/actions_workflow_runs.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Octokit class Client module ActionsWorkflowRuns diff --git a/lib/octokit/client/actions_workflows.rb b/lib/octokit/client/actions_workflows.rb index ab3c0d59c..ee62d6f89 100644 --- a/lib/octokit/client/actions_workflows.rb +++ b/lib/octokit/client/actions_workflows.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client # Methods for the Actions Workflows API # # @see https://developer.github.com/v3/actions/workflows module ActionsWorkflows - # Get the workflows in a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository diff --git a/lib/octokit/client/apps.rb b/lib/octokit/client/apps.rb index 5090ddb49..97f425d96 100644 --- a/lib/octokit/client/apps.rb +++ b/lib/octokit/client/apps.rb @@ -1,9 +1,9 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Apps API module Apps - # Get the authenticated App # # @param options [Hash] A customizable set of options @@ -12,7 +12,7 @@ module Apps # # @return [Sawyer::Resource] App information def app(options = {}) - get "app", options + get 'app', options end # Find all installations that belong to an App @@ -23,16 +23,16 @@ def app(options = {}) # # @return [Array] the total_count and an array of installations def find_app_installations(options = {}) - paginate "app/installations", options + paginate 'app/installations', options end alias find_installations find_app_installations def find_integration_installations(options = {}) octokit_warn( - "Deprecated: Octokit::Client::Apps#find_integration_installations "\ - "method is deprecated. Please update your call to use "\ - "Octokit::Client::Apps#find_app_installations before the next major "\ - "Octokit version update." + 'Deprecated: Octokit::Client::Apps#find_integration_installations '\ + 'method is deprecated. Please update your call to use '\ + 'Octokit::Client::Apps#find_app_installations before the next major '\ + 'Octokit version update.' ) find_app_installations(options) end @@ -45,7 +45,7 @@ def find_integration_installations(options = {}) # # @return [Sawyer::Resource] the total_count and an array of installations def find_user_installations(options = {}) - paginate("user/installations", options) do |data, last_response| + paginate('user/installations', options) do |data, last_response| data.installations.concat last_response.data.installations end end @@ -76,10 +76,10 @@ def create_app_installation_access_token(installation, options = {}) def create_integration_installation_access_token(installation, options = {}) octokit_warn( - "Deprecated: Octokit::Client::Apps#create_integration_installation_access_token "\ - "method is deprecated. Please update your call to use "\ - "Octokit::Client::Apps#create_app_installation_access_token before the next major "\ - "Octokit version update." + 'Deprecated: Octokit::Client::Apps#create_integration_installation_access_token '\ + 'method is deprecated. Please update your call to use '\ + 'Octokit::Client::Apps#create_app_installation_access_token before the next major '\ + 'Octokit version update.' ) create_app_installation_access_token(installation, options) end @@ -128,7 +128,7 @@ def find_user_installation(user, options = {}) # # @return [Sawyer::Resource] the total_count and an array of repositories def list_app_installation_repositories(options = {}) - paginate("installation/repositories", options) do |data, last_response| + paginate('installation/repositories', options) do |data, last_response| data.repositories.concat last_response.data.repositories end end @@ -136,10 +136,10 @@ def list_app_installation_repositories(options = {}) def list_integration_installation_repositories(options = {}) octokit_warn( - "Deprecated: Octokit::Client::Apps#list_integration_installation_repositories "\ - "method is deprecated. Please update your call to use "\ - "Octokit::Client::Apps#list_app_installation_repositories before the next major "\ - "Octokit version update." + 'Deprecated: Octokit::Client::Apps#list_integration_installation_repositories '\ + 'method is deprecated. Please update your call to use '\ + 'Octokit::Client::Apps#list_app_installation_repositories before the next major '\ + 'Octokit version update.' ) list_app_installation_repositories(options) end @@ -160,10 +160,10 @@ def add_repository_to_app_installation(installation, repo, options = {}) def add_repository_to_integration_installation(installation, repo, options = {}) octokit_warn( - "Deprecated: Octokit::Client::Apps#add_repository_to_integration_installation "\ - "method is deprecated. Please update your call to use "\ - "Octokit::Client::Apps#add_repository_to_app_installation before the next major "\ - "Octokit version update." + 'Deprecated: Octokit::Client::Apps#add_repository_to_integration_installation '\ + 'method is deprecated. Please update your call to use '\ + 'Octokit::Client::Apps#add_repository_to_app_installation before the next major '\ + 'Octokit version update.' ) add_repository_to_app_installation(installation, repo, options) end @@ -184,10 +184,10 @@ def remove_repository_from_app_installation(installation, repo, options = {}) def remove_repository_from_integration_installation(installation, repo, options = {}) octokit_warn( - "Deprecated: Octokit::Client::Apps#remove_repository_from_integration_installation "\ - "method is deprecated. Please update your call to use "\ - "Octokit::Client::Apps#remove_repository_from_app_installation before the next major "\ - "Octokit version update." + 'Deprecated: Octokit::Client::Apps#remove_repository_from_integration_installation '\ + 'method is deprecated. Please update your call to use '\ + 'Octokit::Client::Apps#remove_repository_from_app_installation before the next major '\ + 'Octokit version update.' ) remove_repository_from_app_installation(installation, repo, options) end diff --git a/lib/octokit/client/authorizations.rb b/lib/octokit/client/authorizations.rb index 3c678fed5..863e67d6d 100644 --- a/lib/octokit/client/authorizations.rb +++ b/lib/octokit/client/authorizations.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Authorizations API # # @see https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api module Authorizations - # List the authenticated user's authorizations # # API for users to manage their own tokens. @@ -64,16 +64,18 @@ def create_authorization(options = {}) options = options.dup if options.delete :idempotent client_id, client_secret = fetch_client_id_and_secret(options) - raise ArgumentError.new("Client ID and Secret required for idempotent authorizations") unless client_id && client_secret + unless client_id && client_secret + raise ArgumentError, 'Client ID and Secret required for idempotent authorizations' + end # Remove the client_id from the body otherwise # this will result in a 422. options.delete(:client_id) if (fingerprint = options.delete(:fingerprint)) - put "authorizations/clients/#{client_id}/#{fingerprint}", options.merge(:client_secret => client_secret) + put "authorizations/clients/#{client_id}/#{fingerprint}", options.merge(client_secret: client_secret) else - put "authorizations/clients/#{client_id}", options.merge(:client_secret => client_secret) + put "authorizations/clients/#{client_id}", options.merge(client_secret: client_secret) end else @@ -126,18 +128,18 @@ def delete_authorization(number, options = {}) # @return [Array] OAuth scopes # @see https://developer.github.com/v3/oauth/#scopes def scopes(token = @access_token, options = {}) - options= options.dup - raise ArgumentError.new("Access token required") if token.nil? + options = options.dup + raise ArgumentError, 'Access token required' if token.nil? - auth = { "Authorization" => "token #{token}" } + auth = { 'Authorization' => "token #{token}" } headers = (options.delete(:headers) || {}).merge(auth) - agent.call(:get, "user", :headers => headers). - headers['X-OAuth-Scopes']. - to_s. - split(','). - map(&:strip). - sort + agent.call(:get, 'user', headers: headers) + .headers['X-OAuth-Scopes'] + .to_s + .split(',') + .map(&:strip) + .sort end # Revoke all tokens for an app @@ -146,8 +148,8 @@ def scopes(token = @access_token, options = {}) # # @deprecated As of January 25th, 2016: https://developer.github.com/changes/2014-04-08-reset-api-tokens/ # @return [Boolean] false - def revoke_all_application_authorizations(options = {}) - octokit_warn("Deprecated: If you need to revoke all tokens for your application, you can do so via the settings page for your application.") + def revoke_all_application_authorizations(_options = {}) + octokit_warn('Deprecated: If you need to revoke all tokens for your application, you can do so via the settings page for your application.') false end @@ -165,8 +167,9 @@ def revoke_all_application_authorizations(options = {}) def authorize_url(app_id = client_id, options = {}) opts = options.dup if app_id.to_s.empty? - raise Octokit::ApplicationCredentialsRequired, "client_id required" + raise Octokit::ApplicationCredentialsRequired, 'client_id required' end + authorize_url = opts.delete(:endpoint) || Octokit.web_endpoint authorize_url << "login/oauth/authorize?client_id=#{app_id}" diff --git a/lib/octokit/client/checks.rb b/lib/octokit/client/checks.rb index fb71b68d3..c22c6be30 100644 --- a/lib/octokit/client/checks.rb +++ b/lib/octokit/client/checks.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Checks API # # @see https://developer.github.com/v3/checks/ module Checks - # Methods for Check Runs # # @see https://developer.github.com/v3/checks/runs/ @@ -65,7 +65,7 @@ def check_runs_for_ref(repo, ref, options = {}) data.total_count += last_response.data.total_count end end - alias :list_check_runs_for_ref :check_runs_for_ref + alias list_check_runs_for_ref check_runs_for_ref # List check runs in a check suite # @@ -89,7 +89,7 @@ def check_runs_for_check_suite(repo, id, options = {}) data.total_count += last_response.data.total_count end end - alias :list_check_runs_for_check_suite :check_runs_for_check_suite + alias list_check_runs_for_check_suite check_runs_for_check_suite # Get a single check run # @@ -151,7 +151,7 @@ def check_suites_for_ref(repo, ref, options = {}) data.total_count += last_response.data.total_count end end - alias :list_check_suites_for_ref :check_suites_for_ref + alias list_check_suites_for_ref check_suites_for_ref # Set preferences for check suites on a repository # diff --git a/lib/octokit/client/commit_branches.rb b/lib/octokit/client/commit_branches.rb index 9e253b6c4..fb060dbea 100644 --- a/lib/octokit/client/commit_branches.rb +++ b/lib/octokit/client/commit_branches.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Branches for HEAD API # # @see https://developer.github.com/v3/repos/commits/ module CommitBranches - # List branches for a single HEAD commit # # @param repo [Integer, String, Hash, Repository] A GitHub repository diff --git a/lib/octokit/client/commit_comments.rb b/lib/octokit/client/commit_comments.rb index 96341632d..36af53824 100644 --- a/lib/octokit/client/commit_comments.rb +++ b/lib/octokit/client/commit_comments.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Commit Comments API # # @see https://developer.github.com/v3/repos/comments/ module CommitComments - # List all commit comments # # @param repo [Integer, String, Hash, Repository] A GitHub repository @@ -53,12 +53,12 @@ def commit_comment(repo, id, options = {}) # comment.path # => "README.md" # comment.line # => 10 # comment.position # => 1 - def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, options = {}) + def create_commit_comment(repo, sha, body, path = nil, line = nil, position = nil, options = {}) params = { - :body => body, - :path => path, - :line => line, - :position => position + body: body, + path: path, + line: line, + position: position } post "#{Repository.path repo}/commits/#{sha}/comments", options.merge(params) end @@ -76,7 +76,7 @@ def create_commit_comment(repo, sha, body, path=nil, line=nil, position=nil, opt # comment.body # => "Updated commit comment" def update_commit_comment(repo, id, body, options = {}) params = { - :body => body + body: body } patch "#{Repository.path repo}/comments/#{id}", options.merge(params) end diff --git a/lib/octokit/client/commit_pulls.rb b/lib/octokit/client/commit_pulls.rb index 38d56f8e9..1e5a16f59 100644 --- a/lib/octokit/client/commit_pulls.rb +++ b/lib/octokit/client/commit_pulls.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Commit Pulls API # # @see https://developer.github.com/v3/repos/comments/ module CommitPulls - # List pulls for a single commit # # @param repo [Integer, String, Hash, Repository] A GitHub repository diff --git a/lib/octokit/client/commits.rb b/lib/octokit/client/commits.rb index 404a91994..fa73b7e2a 100644 --- a/lib/octokit/client/commits.rb +++ b/lib/octokit/client/commits.rb @@ -1,13 +1,13 @@ +# frozen_string_literal: true + require 'date' module Octokit class Client - # Methods for the Commits API # # @see https://developer.github.com/v3/repos/commits/ module Commits - # List commits # # @overload commits(repo, sha_or_branch, options = {}) @@ -23,12 +23,10 @@ module Commits def commits(*args) arguments = Octokit::RepoArguments.new(args) sha_or_branch = arguments.pop - if sha_or_branch - arguments.options[:sha] = sha_or_branch - end + arguments.options[:sha] = sha_or_branch if sha_or_branch paginate "#{Repository.new(arguments.repo).path}/commits", arguments.options end - alias :list_commits :commits + alias list_commits commits # Get commits after a specified date # @@ -48,13 +46,11 @@ def commits(*args) # Octokit.commits_since('octokit/octokit.rb', '2012-10-01') def commits_since(*args) arguments = Octokit::RepoArguments.new(args) - date = parse_date(arguments.shift) + date = parse_date(arguments.shift) params = arguments.options - params.merge!(:since => iso8601(date)) + params.merge!(since: iso8601(date)) sha_or_branch = arguments.pop - if sha_or_branch - params[:sha] = sha_or_branch - end + params[:sha] = sha_or_branch if sha_or_branch commits(arguments.repo, params) end @@ -74,13 +70,11 @@ def commits_since(*args) # Octokit.commits_before('octokit/octokit.rb', '2012-10-01') def commits_before(*args) arguments = Octokit::RepoArguments.new(args) - date = parse_date(arguments.shift) + date = parse_date(arguments.shift) params = arguments.options - params.merge!(:until => iso8601(date)) + params.merge!(until: iso8601(date)) sha_or_branch = arguments.pop - if sha_or_branch - params[:sha] = sha_or_branch - end + params[:sha] = sha_or_branch if sha_or_branch commits(arguments.repo, params) end @@ -100,14 +94,12 @@ def commits_before(*args) # Octokit.commits_on('octokit/octokit.rb', '2012-10-01') def commits_on(*args) arguments = Octokit::RepoArguments.new(args) - date = parse_date(arguments.shift) + date = parse_date(arguments.shift) params = arguments.options end_date = date + 1 - params.merge!(:since => iso8601(date), :until => iso8601(end_date)) + params.merge!(since: iso8601(date), until: iso8601(end_date)) sha_or_branch = arguments.pop - if sha_or_branch - params[:sha] = sha_or_branch - end + params[:sha] = sha_or_branch if sha_or_branch commits(arguments.repo, params) end @@ -129,16 +121,16 @@ def commits_on(*args) # Octokit.commits_between('octokit/octokit.rb', '2012-10-01', '2012-11-01') def commits_between(*args) arguments = Octokit::RepoArguments.new(args) - date = parse_date(arguments.shift) - end_date = parse_date(arguments.shift) - raise ArgumentError, "Start date #{date} does not precede #{end_date}" if date > end_date + date = parse_date(arguments.shift) + end_date = parse_date(arguments.shift) + if date > end_date + raise ArgumentError, "Start date #{date} does not precede #{end_date}" + end params = arguments.options - params.merge!(:since => iso8601(date), :until => iso8601(end_date)) + params.merge!(since: iso8601(date), until: iso8601(end_date)) sha_or_branch = arguments.pop - if sha_or_branch - params[:sha] = sha_or_branch - end + params[:sha] = sha_or_branch if sha_or_branch commits(arguments.repo, params) end @@ -181,8 +173,8 @@ def git_commit(repo, sha, options = {}) # commit.tree.sha # => "827efc6d56897b048c772eb4087f854f46256132" # commit.message # => "My commit message" # commit.committer # => { "name" => "Wynn Netherland", "email" => "wynn@github.com", ... } - def create_commit(repo, message, tree, parents=nil, options = {}) - params = { :message => message, :tree => tree } + def create_commit(repo, message, tree, parents = nil, options = {}) + params = { message: message, tree: tree } params[:parents] = [parents].flatten if parents post "#{Repository.path repo}/git/commits", options.merge(params) end @@ -213,8 +205,8 @@ def compare(repo, start, endd, options = {}) # @see https://developer.github.com/v3/repos/merging/#perform-a-merge def merge(repo, base, head, options = {}) params = { - :base => base, - :head => head + base: base, + head: head }.merge(options) post "#{Repository.path repo}/merges", params end @@ -225,7 +217,7 @@ def iso8601(date) if date.respond_to?(:iso8601) date.iso8601 else - date.strftime("%Y-%m-%dT%H:%M:%S%Z") + date.strftime('%Y-%m-%dT%H:%M:%S%Z') end end diff --git a/lib/octokit/client/community_profile.rb b/lib/octokit/client/community_profile.rb index 608bc0c10..6a72c1082 100644 --- a/lib/octokit/client/community_profile.rb +++ b/lib/octokit/client/community_profile.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Community Profile API # # @see https://developer.github.com/v3/repos/community/ module CommunityProfile - # Get community profile metrics for a repository # # @param repo [Integer, String, Hash, Repository] A GitHub repository diff --git a/lib/octokit/client/contents.rb b/lib/octokit/client/contents.rb index a2d6dd3dd..f32d7377e 100644 --- a/lib/octokit/client/contents.rb +++ b/lib/octokit/client/contents.rb @@ -1,13 +1,13 @@ +# frozen_string_literal: true + require 'base64' module Octokit class Client - # Methods for the Repo Contents API # # @see https://developer.github.com/v3/repos/contents/ module Contents - # Receive the default Readme for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository @@ -18,7 +18,7 @@ module Contents # Octokit.readme("octokit/octokit.rb") # @example Get the readme file for a particular branch of the repo # Octokit.readme("octokit/octokit.rb", :query => {:ref => 'some-other-branch'}) - def readme(repo, options={}) + def readme(repo, options = {}) get "#{Repository.path repo}/readme", options end @@ -33,13 +33,13 @@ def readme(repo, options={}) # Octokit.contents("octokit/octokit.rb", :path => 'lib/octokit.rb') # @example Lists the contents of lib /octokit.rb on a particular branch # Octokit.contents("octokit/octokit.rb", :path => 'lib/octokit.rb', :query => {:ref => 'some-other-branch'}) - def contents(repo, options={}) + def contents(repo, options = {}) options = options.dup repo_path = options.delete :path url = "#{Repository.path repo}/contents/#{repo_path}" get url, options end - alias :content :contents + alias content contents # Add content to a repository # @@ -59,7 +59,7 @@ def contents(repo, options={}) # "File content", # :branch => "my-new-feature") def create_contents(*args) - args = args.map { |item| item && item.dup } + args = args.map { |item| item&.dup } options = args.last.is_a?(Hash) ? args.pop : {} repo = args.shift path = args.shift @@ -69,7 +69,7 @@ def create_contents(*args) case file when String if File.exist?(file) - file = File.open(file, "r") + file = File.open(file, 'r') content = file.read file.close end @@ -78,7 +78,8 @@ def create_contents(*args) file.close end end - raise ArgumentError.new("content or :file option required") if content.nil? + raise ArgumentError, 'content or :file option required' if content.nil? + options[:content] = Base64.respond_to?(:strict_encode64) ? Base64.strict_encode64(content) : Base64.encode64(content).delete("\n") # Ruby 1.9.2 @@ -86,9 +87,9 @@ def create_contents(*args) url = "#{Repository.path repo}/contents/#{path}" put url, options end - alias :create_content :create_contents - alias :add_content :create_contents - alias :add_contents :create_contents + alias create_content create_contents + alias add_content create_contents + alias add_contents create_contents # Update content in a repository # @@ -116,10 +117,10 @@ def update_contents(*args) message = args.shift sha = args.shift content = args.shift - options.merge!(:sha => sha) + options.merge!(sha: sha) create_contents(repo, path, message, content, options) end - alias :update_content :update_contents + alias update_content update_contents # Delete content in a repository # @@ -142,9 +143,9 @@ def delete_contents(repo, path, message, sha, options = {}) url = "#{Repository.path repo}/contents/#{path}" delete url, options end - alias :delete_content :delete_contents - alias :remove_content :delete_contents - alias :remove_contents :delete_contents + alias delete_content delete_contents + alias remove_content delete_contents + alias remove_contents delete_contents # This method will provide a URL to download a tarball or zipball archive for a repository. # @@ -155,8 +156,8 @@ def delete_contents(repo, path, message, sha, options = {}) # @see https://developer.github.com/v3/repos/contents/#get-archive-link # @example Get archive link for octokit/octokit.rb # Octokit.archive_link("octokit/octokit.rb") - def archive_link(repo, options={}) - repo_ref = ERB::Util.url_encode(options.delete :ref) + def archive_link(repo, options = {}) + repo_ref = ERB::Util.url_encode(options.delete(:ref)) format = (options.delete :format) || 'tarball' url = "#{Repository.path repo}/#{format}/#{repo_ref}" diff --git a/lib/octokit/client/deployments.rb b/lib/octokit/client/deployments.rb index 3d95885a3..99052743c 100644 --- a/lib/octokit/client/deployments.rb +++ b/lib/octokit/client/deployments.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Deployments API # # @see https://developer.github.com/v3/repos/commits/deployments/ module Deployments - # Fetch a single deployment for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository @@ -24,7 +24,7 @@ def deployment(repo, deployment_id, options = {}) def deployments(repo, options = {}) get("#{Repository.path repo}/deployments", options) end - alias :list_deployments :deployments + alias list_deployments deployments # Create a deployment for a ref # @@ -59,10 +59,10 @@ def delete_deployment(repo, deployment_id, options = {}) # @return [Array] A list of deployment statuses # @see https://developer.github.com/v3/repos/deployments/#list-deployment-statuses def deployment_statuses(deployment_url, options = {}) - deployment = get(deployment_url, :accept => options[:accept]) + deployment = get(deployment_url, accept: options[:accept]) get(deployment.rels[:statuses].href, options) end - alias :list_deployment_statuses :deployment_statuses + alias list_deployment_statuses deployment_statuses # Create a deployment status for a Deployment # @@ -73,7 +73,7 @@ def deployment_statuses(deployment_url, options = {}) # @return [Sawyer::Resource] A deployment status # @see https://developer.github.com/v3/repos/deployments/#create-a-deployment-status def create_deployment_status(deployment_url, state, options = {}) - deployment = get(deployment_url, :accept => options[:accept]) + deployment = get(deployment_url, accept: options[:accept]) options[:state] = state.to_s.downcase post(deployment.rels[:statuses].href, options) end diff --git a/lib/octokit/client/downloads.rb b/lib/octokit/client/downloads.rb index 5a81c0d02..2543e6ff0 100644 --- a/lib/octokit/client/downloads.rb +++ b/lib/octokit/client/downloads.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Repo Downloads API # # @see https://developer.github.com/v3/repos/downloads/ module Downloads - # List available downloads for a repository # # @param repo [Integer, String, Repository, Hash] A Github Repository @@ -14,10 +14,10 @@ module Downloads # @see https://developer.github.com/v3/repos/downloads/#list-downloads-for-a-repository # @example List all downloads for Github/Hubot # Octokit.downloads("github/hubot") - def downloads(repo, options={}) + def downloads(repo, options = {}) paginate "#{Repository.path repo}/downloads", options end - alias :list_downloads :downloads + alias list_downloads downloads # Get single download for a repository # @@ -28,7 +28,7 @@ def downloads(repo, options={}) # @see https://developer.github.com/v3/repos/downloads/#get-a-single-download # @example Get the "Robawt" download from Github/Hubot # Octokit.download("github/hubot") - def download(repo, id, options={}) + def download(repo, id, options = {}) get "#{Repository.path repo}/downloads/#{id}", options end @@ -44,7 +44,6 @@ def download(repo, id, options={}) def delete_download(repo, id, options = {}) boolean_from_response :delete, "#{Repository.path repo}/downloads/#{id}", options end - end end end diff --git a/lib/octokit/client/emojis.rb b/lib/octokit/client/emojis.rb index c5bd3be1e..969383ff0 100644 --- a/lib/octokit/client/emojis.rb +++ b/lib/octokit/client/emojis.rb @@ -1,9 +1,9 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Emojis API module Emojis - # List all emojis used on GitHub # # @return [Sawyer::Resource] A list of all emojis on GitHub @@ -11,7 +11,7 @@ module Emojis # @example List all emojis # Octokit.emojis def emojis(options = {}) - get "emojis", options + get 'emojis', options end end end diff --git a/lib/octokit/client/events.rb b/lib/octokit/client/events.rb index 41b8e4742..62e38303e 100644 --- a/lib/octokit/client/events.rb +++ b/lib/octokit/client/events.rb @@ -1,12 +1,12 @@ +# frozen_string_literal: true + module Octokit class Client - # Method for the Events API # # @see https://developer.github.com/v3/activity/events/ # @see https://developer.github.com/v3/issues/events/ module Events - # List all public events for GitHub # # @return [Array] A list of all public events from GitHub @@ -14,7 +14,7 @@ module Events # @example List all pubilc events # Octokit.public_events def public_events(options = {}) - paginate "events", options + paginate 'events', options end # List all user events @@ -119,7 +119,7 @@ def organization_public_events(org, options = {}) def repository_issue_events(repo, options = {}) paginate "#{Repository.path repo}/issues/events", options end - alias :repo_issue_events :repository_issue_events + alias repo_issue_events repository_issue_events # List events for an Issue # diff --git a/lib/octokit/client/feeds.rb b/lib/octokit/client/feeds.rb index 1d6b4bad6..a689a6367 100644 --- a/lib/octokit/client/feeds.rb +++ b/lib/octokit/client/feeds.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Feeds API # # @see https://developer.github.com/v3/activity/feeds/ module Feeds - # List Feeds # # The feeds returned depend on authentication, see the GitHub API docs @@ -14,7 +14,7 @@ module Feeds # @return [Array] list of feeds # @see https://developer.github.com/v3/activity/feeds/#list-feeds def feeds - get "feeds" + get 'feeds' end # Get a Feed by name @@ -24,10 +24,9 @@ def feeds # parser. def feed(name, options = {}) if rel = feeds._links[name] - get rel.href, :accept => rel.type, :options => options + get rel.href, accept: rel.type, options: options end end - end end end diff --git a/lib/octokit/client/gists.rb b/lib/octokit/client/gists.rb index 2078e81cc..34b7921ea 100644 --- a/lib/octokit/client/gists.rb +++ b/lib/octokit/client/gists.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Gists API # # @see https://developer.github.com/v3/gists/ module Gists - # List gists for a user or all public gists # # @param user [String] An optional user to filter listing @@ -15,14 +15,14 @@ module Gists # @example Fetch all public gists # Octokit.gists # @see https://developer.github.com/v3/gists/#list-gists - def gists(user=nil, options = {}) + def gists(user = nil, options = {}) if user.nil? paginate 'gists', options else paginate "#{User.path user}/gists", options end end - alias :list_gists :gists + alias list_gists gists # List public gists # @@ -196,7 +196,7 @@ def gist_comment(gist_id, gist_comment_id, options = {}) # @example # @client.create_gist_comment('3528645', 'This is very helpful.') def create_gist_comment(gist_id, comment, options = {}) - options = options.merge({:body => comment}) + options = options.merge({ body: comment }) post "gists/#{gist_id}/comments", options end @@ -212,7 +212,7 @@ def create_gist_comment(gist_id, comment, options = {}) # @example # @client.update_gist_comment('208sdaz3', '3528645', ':heart:') def update_gist_comment(gist_id, gist_comment_id, comment, options = {}) - options = options.merge({:body => comment}) + options = options.merge({ body: comment }) patch "gists/#{gist_id}/comments/#{gist_comment_id}", options end diff --git a/lib/octokit/client/gitignore.rb b/lib/octokit/client/gitignore.rb index 4206f626d..9436f9d30 100644 --- a/lib/octokit/client/gitignore.rb +++ b/lib/octokit/client/gitignore.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Gitignore API # # @see https://developer.github.com/v3/gitignore/ module Gitignore - # Listing available gitignore templates. # # These templates can be passed option when creating a repository. @@ -17,7 +17,7 @@ module Gitignore # @example Git all the gitignore templates # @client.gitignore_templates def gitignore_templates(options = {}) - get "gitignore/templates", options + get 'gitignore/templates', options end # Get a gitignore template. diff --git a/lib/octokit/client/hooks.rb b/lib/octokit/client/hooks.rb index 5229ffd6d..e81050c07 100644 --- a/lib/octokit/client/hooks.rb +++ b/lib/octokit/client/hooks.rb @@ -1,9 +1,9 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Hooks API module Hooks - # List all Service Hooks supported by GitHub # # @return [Sawyer::Resource] A list of all hooks on GitHub @@ -11,7 +11,7 @@ module Hooks # @example List all hooks # Octokit.available_hooks def available_hooks(options = {}) - get "hooks", options + get 'hooks', options end # List repo hooks @@ -73,7 +73,7 @@ def hook(repo, id, options = {}) # } # ) def create_hook(repo, name, config, options = {}) - options = {:name => name, :config => config, :events => ["push"], :active => true}.merge(options) + options = { name: name, config: config, events: ['push'], active: true }.merge(options) post "#{Repository.path repo}/hooks", options end @@ -116,7 +116,7 @@ def create_hook(repo, name, config, options = {}) # } # ) def edit_hook(repo, id, name, config, options = {}) - options = {:name => name, :config => config}.merge(options) + options = { name: name, config: config }.merge(options) patch "#{Repository.path repo}/hooks/#{id}", options end @@ -158,7 +158,7 @@ def test_hook(repo, id, options = {}) # @see https://developer.github.com/v3/repos/hooks/#ping-a-hook # @example # @client.ping_hook('octokit/octokit.rb', 1000000) - def ping_hook(repo, id, options={}) + def ping_hook(repo, id, options = {}) boolean_from_response :post, "#{Repository.path repo}/hooks/#{id}/pings", options end @@ -174,7 +174,7 @@ def ping_hook(repo, id, options={}) def org_hooks(org, options = {}) paginate "#{Organization.path org}/hooks", options end - alias :list_org_hooks :org_hooks + alias list_org_hooks org_hooks # Get an org hook # @@ -217,7 +217,7 @@ def org_hook(org, id, options = {}) # } # ) def create_org_hook(org, config, options = {}) - options = { :name => "web", :config => config }.merge(options) + options = { name: 'web', config: config }.merge(options) post "#{Organization.path org}/hooks", options end @@ -250,10 +250,10 @@ def create_org_hook(org, config, options = {}) # } # ) def edit_org_hook(org, id, config, options = {}) - options = { :config => config }.merge(options) + options = { config: config }.merge(options) patch "#{Organization.path org}/hooks/#{id}", options end - alias :update_org_hook :edit_org_hook + alias update_org_hook edit_org_hook # Ping org hook # diff --git a/lib/octokit/client/issues.rb b/lib/octokit/client/issues.rb index bdf346bda..c63564a1e 100644 --- a/lib/octokit/client/issues.rb +++ b/lib/octokit/client/issues.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Issues API # # @see https://developer.github.com/v3/issues/ module Issues - # List issues for the authenticated user or repository # # @param repository [Integer, String, Repository, Hash] A GitHub repository. @@ -28,10 +28,10 @@ module Issues # @client = Octokit::Client.new(:login => 'foo', :password => 'bar') # @client.list_issues def list_issues(repository = nil, options = {}) - path = repository ? "#{Repository.new(repository).path}/issues" : "issues" + path = repository ? "#{Repository.new(repository).path}/issues" : 'issues' paginate path, options end - alias :issues :list_issues + alias issues list_issues # List all issues across owned and member repositories for the authenticated user # @@ -91,17 +91,17 @@ def org_issues(org, options = {}) def create_issue(repo, title, body = nil, options = {}) options[:labels] = case options[:labels] when String - options[:labels].split(",").map(&:strip) + options[:labels].split(',').map(&:strip) when Array options[:labels] else [] end - parameters = { :title => title } + parameters = { title: title } parameters[:body] = body unless body.nil? post "#{Repository.path repo}/issues", options.merge(parameters) end - alias :open_issue :create_issue + alias open_issue create_issue # Get a single issue from a repository # @@ -129,7 +129,7 @@ def issue(repo, number, options = {}) # @example Close Issue #25 from octokit/octokit.rb # Octokit.close_issue("octokit/octokit.rb", "25") def close_issue(repo, number, options = {}) - patch "#{Repository.path repo}/issues/#{number}", options.merge({:state => "closed"}) + patch "#{Repository.path repo}/issues/#{number}", options.merge({ state: 'closed' }) end # Reopen an issue @@ -146,7 +146,7 @@ def close_issue(repo, number, options = {}) # @example Reopen Issue #25 from octokit/octokit.rb # Octokit.reopen_issue("octokit/octokit.rb", "25") def reopen_issue(repo, number, options = {}) - patch "#{Repository.path repo}/issues/#{number}", options.merge({:state => "open"}) + patch "#{Repository.path repo}/issues/#{number}", options.merge({ state: 'open' }) end # Lock an issue's conversation, limiting it to collaborators @@ -210,7 +210,7 @@ def update_issue(repo, number, *args) arguments = Arguments.new(args) opts = arguments.options - if arguments.length > 0 + unless arguments.empty? opts[:title] = arguments.shift opts[:body] = arguments.shift end @@ -281,7 +281,7 @@ def issue_comment(repo, number, options = {}) # @example Add the comment "Almost to v1" to Issue #23 on octokit/octokit.rb # Octokit.add_comment("octokit/octokit.rb", 23, "Almost to v1") def add_comment(repo, number, comment, options = {}) - post "#{Repository.path repo}/issues/#{number}/comments", options.merge({:body => comment}) + post "#{Repository.path repo}/issues/#{number}/comments", options.merge({ body: comment }) end # Update a single comment on an issue @@ -294,7 +294,7 @@ def add_comment(repo, number, comment, options = {}) # @example Update the comment #1194549 with body "I've started this on my 25-issue-comments-v3 fork" on an issue on octokit/octokit.rb # Octokit.update_comment("octokit/octokit.rb", 1194549, "Almost to v1, added this on my fork") def update_comment(repo, number, comment, options = {}) - patch "#{Repository.path repo}/issues/comments/#{number}", options.merge({:body => comment}) + patch "#{Repository.path repo}/issues/comments/#{number}", options.merge({ body: comment }) end # Delete a single comment @@ -343,7 +343,7 @@ def list_assignees(repo, options = {}) # @example Add assignees "pengwynn" and "joeyw" to Issue #23 on octokit/octokit.rb # Octokit.add_assignees("octokit/octokit.rb", 23, ["pengwynn", "joeyw"]) def add_assignees(repo, number, assignees, options = {}) - post "#{Repository.path repo}/issues/#{number}/assignees", options.merge({:assignees => assignees}) + post "#{Repository.path repo}/issues/#{number}/assignees", options.merge({ assignees: assignees }) end # Remove assignees from an issue @@ -361,7 +361,7 @@ def add_assignees(repo, number, assignees, options = {}) # Octokit.remove_assignees("octokit/octokit.rb", 23, ["pengwynn"], # :accept => "application/vnd.github.v3+json") def remove_assignees(repo, number, assignees, options = {}) - delete "#{Repository.path repo}/issues/#{number}/assignees", options.merge({:assignees => assignees}) + delete "#{Repository.path repo}/issues/#{number}/assignees", options.merge({ assignees: assignees }) end end end diff --git a/lib/octokit/client/labels.rb b/lib/octokit/client/labels.rb index 50a568b8b..99a9bbd04 100644 --- a/lib/octokit/client/labels.rb +++ b/lib/octokit/client/labels.rb @@ -1,13 +1,13 @@ -require "erb" +# frozen_string_literal: true + +require 'erb' module Octokit class Client - # Methods for the Issue Labels API # # @see https://developer.github.com/v3/issues/labels/ module Labels - # List available labels for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository @@ -40,8 +40,8 @@ def label(repo, name, options = {}) # @see https://developer.github.com/v3/issues/labels/#create-a-label # @example Add a new label "Version 1.0" with color "#cccccc" # Octokit.add_label("octokit/octokit.rb", "Version 1.0", "cccccc") - def add_label(repo, label, color="ffffff", options = {}) - post "#{Repository.path repo}/labels", options.merge({:name => label, :color => color}) + def add_label(repo, label, color = 'ffffff', options = {}) + post "#{Repository.path repo}/labels", options.merge({ name: label, color: color }) end # Update a label @@ -136,7 +136,7 @@ def add_labels_to_an_issue(repo, number, labels) # @see https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue # @example Replace labels for octokit/octokit.rb Issue #10 # Octokit.replace_all_labels("octokit/octokit.rb", 10, ['V3 Transition', 'Improvement']) - def replace_all_labels(repo, number, labels, options = {}) + def replace_all_labels(repo, number, labels, _options = {}) put "#{Repository.path repo}/issues/#{number}/labels", labels end diff --git a/lib/octokit/client/legacy_search.rb b/lib/octokit/client/legacy_search.rb index 947251659..64caf9aa9 100644 --- a/lib/octokit/client/legacy_search.rb +++ b/lib/octokit/client/legacy_search.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Legacy Search API # # @see https://developer.github.com/v3/search/ module LegacySearch - # Legacy repository search # # @see https://developer.github.com/v3/search/#search-repositories @@ -23,7 +23,7 @@ def legacy_search_repositories(q, options = {}) # @return [Array] A list of issues matching the search term and state # @example Search for 'test' in the open issues for sferik/rails_admin # Octokit.search_issues("sferik/rails_admin", 'test', 'open') - def legacy_search_issues(repo, search_term, state='open', options = {}) + def legacy_search_issues(repo, search_term, state = 'open', options = {}) get("legacy/issues/search/#{Repository.new(repo)}/#{state}/#{search_term}", options)['issues'] end diff --git a/lib/octokit/client/licenses.rb b/lib/octokit/client/licenses.rb index a541609c8..084f253e4 100644 --- a/lib/octokit/client/licenses.rb +++ b/lib/octokit/client/licenses.rb @@ -1,10 +1,10 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for licenses API # module Licenses - # List all licenses # # @see https://developer.github.com/v3/licenses/#list-all-licenses @@ -13,7 +13,7 @@ module Licenses # Octokit.licenses def licenses(options = {}) options = ensure_api_media_type(:licenses, options) - paginate "licenses", options + paginate 'licenses', options end # List an individual license diff --git a/lib/octokit/client/markdown.rb b/lib/octokit/client/markdown.rb index 06b162879..f1de79904 100644 --- a/lib/octokit/client/markdown.rb +++ b/lib/octokit/client/markdown.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Markdown API # # @see https://developer.github.com/v3/markdown/ module Markdown - # Render an arbitrary Markdown document # # @param text [String] Markdown source @@ -20,7 +20,7 @@ def markdown(text, options = {}) options[:repo] = Repository.new(options[:repo]) if options[:repo] options[:accept] = 'application/vnd.github.raw' - post "markdown", options + post 'markdown', options end end end diff --git a/lib/octokit/client/marketplace.rb b/lib/octokit/client/marketplace.rb index bf8ed2bff..53d593e78 100644 --- a/lib/octokit/client/marketplace.rb +++ b/lib/octokit/client/marketplace.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Marketplace Listing API # # @see https://developer.github.com/v3/apps/marketplace/ module Marketplace - # List all plans for an app's marketplace listing # # @param options [Hash] A customizable set of options @@ -14,7 +14,7 @@ module Marketplace # # @return [Array] A list of plans def list_plans(options = {}) - paginate "/marketplace_listing/plans", options + paginate '/marketplace_listing/plans', options end # List all GitHub accounts on a specific plan @@ -49,7 +49,7 @@ def plan_for_account(account_id, options = {}) # # @return [Array] A list of Marketplace purchases def marketplace_purchases(options = {}) - get "/user/marketplace_purchases", options + get '/user/marketplace_purchases', options end end end diff --git a/lib/octokit/client/meta.rb b/lib/octokit/client/meta.rb index 1dc56cf20..aa7d97ce0 100644 --- a/lib/octokit/client/meta.rb +++ b/lib/octokit/client/meta.rb @@ -1,21 +1,20 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Meta API # # @see https://developer.github.com/v3/meta/ module Meta - # Get meta information about GitHub.com, the service. # @see https://developer.github.com/v3/meta/#meta # @return [Sawyer::Resource] Hash with meta information. # @example Get GitHub meta information # @client.github_meta def meta(options = {}) - get "meta", options + get 'meta', options end - alias :github_meta :meta - + alias github_meta meta end end end diff --git a/lib/octokit/client/milestones.rb b/lib/octokit/client/milestones.rb index 340790c11..07a41b9c5 100644 --- a/lib/octokit/client/milestones.rb +++ b/lib/octokit/client/milestones.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Issues Milestones API # # @see https://developer.github.com/v3/issues/milestones/ module Milestones - # List milestones for a repository # # @param repository [Integer, String, Repository, Hash] A GitHub repository @@ -21,7 +21,7 @@ module Milestones def list_milestones(repository, options = {}) paginate "#{Repository.path repository}/milestones", options end - alias :milestones :list_milestones + alias milestones list_milestones # Get a single milestone for a repository # @@ -49,7 +49,7 @@ def milestone(repository, number, options = {}) # @example Create a milestone for a repository # Octokit.create_milestone("octokit/octokit.rb", "0.7.0", {:description => 'Add support for v3 of Github API'}) def create_milestone(repository, title, options = {}) - post "#{Repository.path repository}/milestones", options.merge({:title => title}) + post "#{Repository.path repository}/milestones", options.merge({ title: title }) end # Update a milestone for a repository @@ -68,7 +68,7 @@ def create_milestone(repository, title, options = {}) def update_milestone(repository, number, options = {}) patch "#{Repository.path repository}/milestones/#{number}", options end - alias :edit_milestone :update_milestone + alias edit_milestone update_milestone # Delete a single milestone for a repository # diff --git a/lib/octokit/client/notifications.rb b/lib/octokit/client/notifications.rb index 4b42ef579..5e8236bca 100644 --- a/lib/octokit/client/notifications.rb +++ b/lib/octokit/client/notifications.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Notifications API # # @see https://developer.github.com/v3/activity/notifications/ module Notifications - # List your notifications # # @param options [Hash] Optional parameters @@ -24,7 +24,7 @@ module Notifications # @example Get all notifications since a certain time. # @client.notifications({all: true, since: '2012-10-09T23:39:01Z'}) def notifications(options = {}) - paginate "notifications", options + paginate 'notifications', options end # List your notifications in a repository @@ -48,7 +48,7 @@ def notifications(options = {}) def repository_notifications(repo, options = {}) paginate "#{Repository.path repo}/notifications", options end - alias :repo_notifications :repository_notifications + alias repo_notifications repository_notifications # Mark notifications as read # @@ -66,7 +66,7 @@ def repository_notifications(repo, options = {}) # @example # @client.mark_notifications_as_read def mark_notifications_as_read(options = {}) - request :put, "notifications", options + request :put, 'notifications', options last_response.status == 205 end @@ -91,7 +91,7 @@ def mark_repository_notifications_as_read(repo, options = {}) last_response.status == 205 end - alias :mark_repo_notifications_as_read :mark_repository_notifications_as_read + alias mark_repo_notifications_as_read mark_repository_notifications_as_read # List notifications for a specific thread # diff --git a/lib/octokit/client/oauth_applications.rb b/lib/octokit/client/oauth_applications.rb index a118e71fc..78ec365a1 100644 --- a/lib/octokit/client/oauth_applications.rb +++ b/lib/octokit/client/oauth_applications.rb @@ -2,12 +2,10 @@ module Octokit class Client - # Methods for the OauthApplications API # # @see https://developer.github.com/v3/apps/oauth_applications module OauthApplications - # Check if a token is valid. # # Applications can check if a token is valid without rate limits. diff --git a/lib/octokit/client/objects.rb b/lib/octokit/client/objects.rb index bbb449e4e..0b3f5d7e6 100644 --- a/lib/octokit/client/objects.rb +++ b/lib/octokit/client/objects.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Git Data API # # @see https://developer.github.com/v3/git/ module Objects - # Get a single tree, fetching information about its root-level objects # # Pass :recursive => true in options to fetch information about all of the tree's objects, including those in subdirectories. @@ -38,7 +38,7 @@ def tree(repo, tree_sha, options = {}) # tree.sha # => "cd8274d15fa3ae2ab983129fb037999f264ba9a7" # tree.tree.first.path # => "file.rb" def create_tree(repo, tree, options = {}) - parameters = { :tree => tree } + parameters = { tree: tree } post "#{Repository.path repo}/git/trees", options.merge(parameters) end @@ -74,10 +74,10 @@ def blob(repo, blob_sha, options = {}) # @example Create a blob containing foo bar baz, encoded using base64 # require "base64" # Octokit.create_blob("octocat/Hello-World", Base64.encode64("foo bar baz"), "base64") - def create_blob(repo, content, encoding="utf-8", options = {}) + def create_blob(repo, content, encoding = 'utf-8', options = {}) parameters = { - :content => content, - :encoding => encoding + content: content, + encoding: encoding } blob = post "#{Repository.path repo}/git/blobs", options.merge(parameters) @@ -124,14 +124,14 @@ def tag(repo, tag_sha, options = {}) # ) def create_tag(repo, tag, message, object_sha, type, tagger_name, tagger_email, tagger_date, options = {}) options.merge!( - :tag => tag, - :message => message, - :object => object_sha, - :type => type, - :tagger => { - :name => tagger_name, - :email => tagger_email, - :date => tagger_date + tag: tag, + message: message, + object: object_sha, + type: type, + tagger: { + name: tagger_name, + email: tagger_email, + date: tagger_date } ) post "#{Repository.path repo}/git/tags", options diff --git a/lib/octokit/client/organizations.rb b/lib/octokit/client/organizations.rb index 237e1b803..3af802709 100644 --- a/lib/octokit/client/organizations.rb +++ b/lib/octokit/client/organizations.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Organizations API # # @see https://developer.github.com/v3/orgs/ module Organizations - # Get an organization # # @param org [String, Integer] Organization GitHub login or id. @@ -18,7 +18,7 @@ module Organizations def organization(org, options = {}) get Organization.path(org), options end - alias :org :organization + alias org organization # Update an organization. # @@ -48,7 +48,7 @@ def organization(org, options = {}) def update_organization(org, values, options = {}) patch Organization.path(org), options.merge(values) end - alias :update_org :update_organization + alias update_org update_organization # Get organizations for a user. # @@ -78,12 +78,12 @@ def update_organization(org, values, options = {}) # Octokit.list_orgs('pengwynn') # @example # @client.organizations - def organizations(user=nil, options = {}) + def organizations(user = nil, options = {}) paginate "#{User.path user}/orgs", options end - alias :list_organizations :organizations - alias :list_orgs :organizations - alias :orgs :organizations + alias list_organizations organizations + alias list_orgs organizations + alias orgs organizations # List all GitHub organizations # @@ -98,9 +98,9 @@ def organizations(user=nil, options = {}) # # @return [Array] List of GitHub organizations. def all_organizations(options = {}) - paginate "organizations", options + paginate 'organizations', options end - alias :all_orgs :all_organizations + alias all_orgs all_organizations # List organization repositories # @@ -125,8 +125,8 @@ def all_organizations(options = {}) def organization_repositories(org, options = {}) paginate "#{Organization.path org}/repos", options end - alias :org_repositories :organization_repositories - alias :org_repos :organization_repositories + alias org_repositories organization_repositories + alias org_repos organization_repositories # Get organization members # @@ -143,10 +143,10 @@ def organization_repositories(org, options = {}) # Octokit.org_members('github') def organization_members(org, options = {}) options = options.dup - path = "public_" if options.delete(:public) + path = 'public_' if options.delete(:public) paginate "#{Organization.path org}/#{path}members", options end - alias :org_members :organization_members + alias org_members organization_members # Get organization public members # @@ -160,9 +160,9 @@ def organization_members(org, options = {}) # @example # Octokit.org_public_members('github') def organization_public_members(org, options = {}) - organization_members org, options.merge(:public => true) + organization_members org, options.merge(public: true) end - alias :org_public_members :organization_public_members + alias org_public_members organization_public_members # Check if a user is a member of an organization. # @@ -188,7 +188,7 @@ def organization_member?(org, user, options = {}) result end end - alias :org_member? :organization_member? + alias org_member? organization_member? # Check if a user is a public member of an organization. # @@ -208,7 +208,7 @@ def organization_member?(org, user, options = {}) def organization_public_member?(org, user, options = {}) boolean_from_response :get, "#{Organization.path org}/public_members/#{user}", options end - alias :org_public_member? :organization_public_member? + alias org_public_member? organization_public_member? # List pending organization invitations # @@ -223,7 +223,7 @@ def organization_public_member?(org, user, options = {}) def organization_invitations(org, options = {}) get "#{Organization.path org}/invitations", options end - alias :org_invitations :organization_invitations + alias org_invitations organization_invitations # List outside collaborators for an organization # @@ -235,7 +235,7 @@ def organization_invitations(org, options = {}) # # @example # @client.outside_collaborators('github') - def outside_collaborators(org, options={}) + def outside_collaborators(org, options = {}) paginate "#{Organization.path org}/outside_collaborators", options end @@ -250,7 +250,7 @@ def outside_collaborators(org, options={}) # # @example # @client.remove_outside_collaborator('github', 'lizzhale') - def remove_outside_collaborator(org, user, options={}) + def remove_outside_collaborator(org, user, options = {}) boolean_from_response :delete, "#{Organization.path org}/outside_collaborators/#{user}", options end @@ -265,7 +265,7 @@ def remove_outside_collaborator(org, user, options={}) # # @example # @client.convert_to_outside_collaborator('github', 'lizzhale') - def convert_to_outside_collaborator(org, user, options={}) + def convert_to_outside_collaborator(org, user, options = {}) boolean_from_response :put, "#{Organization.path org}/outside_collaborators/#{user}", options end @@ -283,7 +283,7 @@ def convert_to_outside_collaborator(org, user, options={}) def organization_teams(org, options = {}) paginate "#{Organization.path org}/teams", options end - alias :org_teams :organization_teams + alias org_teams organization_teams # Create team # @@ -303,7 +303,7 @@ def organization_teams(org, options = {}) # }) def create_team(org, options = {}) if options.key?(:permission) - octokit_warn "Deprecated: Passing :permission option to #create_team. Assign team repository permission by passing :permission to #add_team_repository instead." + octokit_warn 'Deprecated: Passing :permission option to #create_team. Assign team repository permission by passing :permission to #add_team_repository instead.' end if options.key?(:parent_team_id) options = ensure_api_media_type(:nested_teams, options) @@ -429,7 +429,7 @@ def add_team_member(team_id, user, options = {}) # There's a bug in this API call. The docs say to leave the body blank, # but it fails if the body is both blank and the content-length header # is not 0. - boolean_from_response :put, "teams/#{team_id}/members/#{user}", options.merge({:name => user}) + boolean_from_response :put, "teams/#{team_id}/members/#{user}", options.merge({ name: user }) end # Remove team member @@ -494,7 +494,7 @@ def team_invitations(team_id, options = {}) def team_repositories(team_id, options = {}) paginate "teams/#{team_id}/repos", options end - alias :team_repos :team_repositories + alias team_repos team_repositories # Check if a repo is managed by a specific team # @@ -508,10 +508,10 @@ def team_repositories(team_id, options = {}) # @client.team_repository?(8675309, 'octokit/octokit.rb') # @example # @client.team_repo?(8675309, 'octokit/octokit.rb') - def team_repository?(team_id, repo, options = {}) + def team_repository?(team_id, repo, _options = {}) boolean_from_response :get, "teams/#{team_id}/repos/#{Repository.new(repo)}" end - alias :team_repo? :team_repository? + alias team_repo? team_repository? # Add team repository # @@ -540,7 +540,7 @@ def team_repository?(team_id, repo, options = {}) def add_team_repository(team_id, repo, options = {}) boolean_from_response :put, "teams/#{team_id}/repos/#{Repository.new(repo)}", options end - alias :add_team_repo :add_team_repository + alias add_team_repo add_team_repository # Remove team repository # @@ -557,10 +557,10 @@ def add_team_repository(team_id, repo, options = {}) # @client.remove_team_repository(100000, 'github/developer.github.com') # @example # @client.remove_team_repo(100000, 'github/developer.github.com') - def remove_team_repository(team_id, repo, options = {}) + def remove_team_repository(team_id, repo, _options = {}) boolean_from_response :delete, "teams/#{team_id}/repos/#{Repository.new(repo)}" end - alias :remove_team_repo :remove_team_repository + alias remove_team_repo remove_team_repository # Remove organization member # @@ -579,7 +579,7 @@ def remove_organization_member(org, user, options = {}) # provided in the GH API v3 boolean_from_response :delete, "#{Organization.path org}/members/#{user}", options end - alias :remove_org_member :remove_organization_member + alias remove_org_member remove_organization_member # Publicize a user's membership of an organization # @@ -610,14 +610,14 @@ def publicize_membership(org, user, options = {}) def unpublicize_membership(org, user, options = {}) boolean_from_response :delete, "#{Organization.path org}/public_members/#{user}", options end - alias :conceal_membership :unpublicize_membership + alias conceal_membership unpublicize_membership # List all teams for the authenticated user across all their orgs # # @return [Array] Array of team resources. # @see https://developer.github.com/v3/orgs/teams/#list-user-teams def user_teams(options = {}) - paginate "user/teams", options + paginate 'user/teams', options end # Check if a user has a team membership. @@ -667,9 +667,9 @@ def remove_team_membership(team_id, user, options = {}) # @return [Array] Array of organizations memberships. # @see https://developer.github.com/v3/orgs/members/#list-your-organization-memberships def organization_memberships(options = {}) - paginate "user/memberships/orgs", options + paginate 'user/memberships/orgs', options end - alias :org_memberships :organization_memberships + alias org_memberships organization_memberships # Get an organization membership # @@ -686,7 +686,7 @@ def organization_membership(org, options = {}) get "user/memberships/orgs/#{org}", options end end - alias :org_membership :organization_membership + alias org_membership organization_membership # Edit an organization membership # @@ -707,7 +707,7 @@ def update_organization_membership(org, options = {}) patch "user/memberships/orgs/#{org}", options end end - alias :update_org_membership :update_organization_membership + alias update_org_membership update_organization_membership # Remove an organization membership # @@ -719,7 +719,7 @@ def remove_organization_membership(org, options = {}) user = options.delete(:user) user && boolean_from_response(:delete, "#{Organization.path(org)}/memberships/#{user}", options) end - alias :remove_org_membership :remove_organization_membership + alias remove_org_membership remove_organization_membership # Initiates the generation of a migration archive. # @@ -803,13 +803,13 @@ def unlock_repository(org, id, repo, options = {}) end # Get GitHub Actions billing for an organization - # + # # Requires authenticated organization owner. - # + # # @param org [String, Integer] Organization GitHub login or id. # @return [Sawyer::Resource] Hash representing GitHub Actions billing for an organization. # @see https://docs.github.com/en/rest/reference/billing#get-github-actions-billing-for-an-organization - # + # # @example # @client.billing_actions('github') def billing_actions(org) diff --git a/lib/octokit/client/pages.rb b/lib/octokit/client/pages.rb index 08f3f78c4..ada6e7d91 100644 --- a/lib/octokit/client/pages.rb +++ b/lib/octokit/client/pages.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Pages API # # @see https://developer.github.com/v3/repos/pages/ module Pages - # List Pages information for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository @@ -36,7 +36,7 @@ def pages_build(repo, id, options = {}) def pages_builds(repo, options = {}) get "#{Repository.path repo}/pages/builds", options end - alias :list_pages_builds :pages_builds + alias list_pages_builds pages_builds # List the latest Pages build information for a repository # diff --git a/lib/octokit/client/projects.rb b/lib/octokit/client/projects.rb index 2df3f8a04..3aa71aad0 100644 --- a/lib/octokit/client/projects.rb +++ b/lib/octokit/client/projects.rb @@ -1,18 +1,18 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for Projects API # # @see https://developer.github.com/v3/repos/projects module Projects - # List projects for a repository # # Requires authenticated client # # @param repo [Integer, String, Repository, Hash] A GitHub repository # @return [Array] Repository projects - # @see https://developer.github.com/v3/projects/#list-repository-projects + # @see https://developer.github.com/v3/projects/#list-repository-projects # @example # @client.projects('octokit/octokit.rb') def projects(repo, options = {}) @@ -28,7 +28,7 @@ def projects(repo, options = {}) # @param name [String] Project name # @option options [String] :body Body of the project # @return [Sawyer::Resource] Fresh new project - # @see https://developer.github.com/v3/projects/#create-a-repository-project + # @see https://developer.github.com/v3/projects/#create-a-repository-project # @example Create project with only a name # @client.create_project('octokit/octokit.rb', 'implement new APIs') # @@ -53,7 +53,7 @@ def org_projects(org, options = {}) opts = ensure_api_media_type(:projects, options) paginate "orgs/#{org}/projects", opts end - alias :organization_projects :org_projects + alias organization_projects org_projects # Create organization project # @@ -73,13 +73,13 @@ def create_org_project(org, name, options = {}) opts[:name] = name post "orgs/#{org}/projects", opts end - alias :create_organization_project :create_org_project + alias create_organization_project create_org_project - # Get a project by id + # Get a project by id # # @param id [Integer] Project id # @return [Sawyer::Resource] Project - # @see https://developer.github.com/v3/projects/#get-a-project + # @see https://developer.github.com/v3/projects/#get-a-project # @example # Octokit.project(123942) def project(id, options = {}) @@ -95,7 +95,7 @@ def project(id, options = {}) # @option options [String] :name Project name # @option options [String] :body Project body # @return [Sawyer::Resource] Project - # @see https://developer.github.com/v3/projects/#update-a-project + # @see https://developer.github.com/v3/projects/#update-a-project # @example Update project name # @client.update_project(123942, name: 'New name') def update_project(id, options = {}) @@ -109,7 +109,7 @@ def update_project(id, options = {}) # # @param id [Integer] Project id # @return [Boolean] Result of deletion - # @see https://developer.github.com/v3/projects/#delete-a-project + # @see https://developer.github.com/v3/projects/#delete-a-project # @example # @client.delete_project(123942) def delete_project(id, options = {}) @@ -119,9 +119,9 @@ def delete_project(id, options = {}) # List project columns # - # @param id [Integer] Project id + # @param id [Integer] Project id # @return [Array] List of project columns - # @see https://developer.github.com/v3/projects/columns/#list-project-columns + # @see https://developer.github.com/v3/projects/columns/#list-project-columns # @example # @client.project_columns(123942) def project_columns(id, options = {}) @@ -136,7 +136,7 @@ def project_columns(id, options = {}) # @param id [Integer] Project column id # @param name [String] New column name # @return [Sawyer::Resource] Newly created column - # @see https://developer.github.com/v3/projects/columns/#create-a-project-column + # @see https://developer.github.com/v3/projects/columns/#create-a-project-column # @example # @client.create_project_column(123942, "To Dones") def create_project_column(id, name, options = {}) @@ -149,7 +149,7 @@ def create_project_column(id, name, options = {}) # # @param id [Integer] Project column id # @return [Sawyer::Resource] Project column - # @see https://developer.github.com/v3/projects/columns/#get-a-project-column + # @see https://developer.github.com/v3/projects/columns/#get-a-project-column # @example # Octokit.project_column(30294) def project_column(id, options = {}) @@ -164,7 +164,7 @@ def project_column(id, options = {}) # @param id [Integer] Project column id # @param name [String] New column name # @return [Sawyer::Resource] Updated column - # @see https://developer.github.com/v3/projects/columns/#update-a-project-column + # @see https://developer.github.com/v3/projects/columns/#update-a-project-column # @example # @client.update_project_column(30294, "new column name") def update_project_column(id, name, options = {}) @@ -179,7 +179,7 @@ def update_project_column(id, name, options = {}) # # @param id [Integer] Project column id # @return [Boolean] Result of deletion request, true when deleted - # @see https://developer.github.com/v3/projects/columns/#delete-a-project-column + # @see https://developer.github.com/v3/projects/columns/#delete-a-project-column # @example # @client.delete_project_column(30294) def delete_project_column(id, options = {}) @@ -192,7 +192,7 @@ def delete_project_column(id, options = {}) # Requires authenticated client # # @param id [Integer] Project column id - # @param position [String] New position for the column. Can be one of + # @param position [String] New position for the column. Can be one of # first, last, or after:, where # is the id value of a column in the same project. # @return [Sawyer::Resource] Result @@ -296,7 +296,7 @@ def move_project_card(id, position, options = {}) end # Delete a project card - # + # # Requires authenticated client # # @param id [Integer] Project card id @@ -308,7 +308,6 @@ def delete_project_card(id, options = {}) opts = ensure_api_media_type(:projects, options) boolean_from_response :delete, "projects/columns/cards/#{id}", opts end - end # Projects end end diff --git a/lib/octokit/client/pub_sub_hubbub.rb b/lib/octokit/client/pub_sub_hubbub.rb index 5ae011700..94c99f76f 100644 --- a/lib/octokit/client/pub_sub_hubbub.rb +++ b/lib/octokit/client/pub_sub_hubbub.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the PubSubHubbub API # # @see https://developer.github.com/v3/repos/hooks/#pubsubhubbub module PubSubHubbub - # Subscribe to a pubsub topic # # @param topic [String] A recoginized and supported pubsub topic @@ -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) @@ -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) @@ -64,7 +64,7 @@ def unsubscribe(topic, callback) # client.subscribe_service_hook('joshk/device_imapable', 'Travis', { :token => "test", :domain => "domain", :user => "user" }) def subscribe_service_hook(repo, service_name, service_arguments = {}, secret = nil) topic = "#{Octokit.web_endpoint}#{Repository.new(repo)}/events/push" - callback = "github://#{service_name}?#{service_arguments.collect{ |k,v| [ k,v ].map{ |p| URI.encode_www_form_component(p) }.join("=") }.join("&") }" + callback = "github://#{service_name}?#{service_arguments.collect { |k, v| [k, v].map { |p| URI.encode_www_form_component(p) }.join('=') }.join('&')}" subscribe(topic, callback, secret) end @@ -88,20 +88,20 @@ def unsubscribe_service_hook(repo, service_name) def pub_sub_hubbub_request(options = {}) # This method is janky, bypass normal stack so we don't # serialize request as JSON - conn = Faraday.new(:url => @api_endpoint) do |http| + conn = Faraday.new(url: @api_endpoint) do |http| http.headers[:user_agent] = user_agent if basic_authenticated? http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password elsif token_authenticated? http.request :authorization, 'token', @access_token end - http.request :url_encoded + http.request :url_encoded http.use Octokit::Response::RaiseError - http.adapter Faraday.default_adapter + http.adapter Faraday.default_adapter end conn.post do |req| - req.url "hub" + req.url 'hub' req.headers['Content-Type'] = 'application/x-www-form-urlencoded' req.body = options end diff --git a/lib/octokit/client/pull_requests.rb b/lib/octokit/client/pull_requests.rb index d90bcd4b0..e7f4274e5 100644 --- a/lib/octokit/client/pull_requests.rb +++ b/lib/octokit/client/pull_requests.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Pull Requests API # # @see https://developer.github.com/v3/pulls/ module PullRequests - # List pull requests for a repository # # @overload pull_requests(repo, options) @@ -19,7 +19,7 @@ module PullRequests def pull_requests(repo, options = {}) paginate "#{Repository.path repo}/pulls", options end - alias :pulls :pull_requests + alias pulls pull_requests # Get a pull request # @@ -28,11 +28,11 @@ def pull_requests(repo, options = {}) # @param number [Integer] Number of the pull request to fetch # @return [Sawyer::Resource] Pull request info # @example - # Octokit.pull_request('rails/rails', 42, :state => 'closed') + # Octokit.pull_request('rails/rails', 42, :state => 'closed') def pull_request(repo, number, options = {}) get "#{Repository.path repo}/pulls/#{number}", options end - alias :pull :pull_request + alias pull pull_request # Create a pull request # @@ -51,9 +51,9 @@ def pull_request(repo, number, options = {}) # "Pull Request title", "Pull Request body") def create_pull_request(repo, base, head, title, body = nil, options = {}) pull = { - :base => base, - :head => head, - :title => title, + base: base, + head: head, + title: title } pull[:body] = body unless body.nil? post "#{Repository.path repo}/pulls", options.merge(pull) @@ -72,9 +72,9 @@ def create_pull_request(repo, base, head, title, body = nil, options = {}) # @return [Sawyer::Resource] The newly created pull request def create_pull_request_for_issue(repo, base, head, issue, options = {}) pull = { - :base => base, - :head => head, - :issue => issue + base: base, + head: head, + issue: issue } post "#{Repository.path repo}/pulls", options.merge(pull) end @@ -103,7 +103,7 @@ def create_pull_request_for_issue(repo, base, head, issue, options = {}) # @client.update_pull_request('octokit/octokit.rb', 67, nil, '') def update_pull_request(*args) arguments = Octokit::Arguments.new(args) - repo = arguments.shift + repo = arguments.shift number = arguments.shift patch "#{Repository.path repo}/pulls/#{number}", arguments.options end @@ -117,7 +117,7 @@ def update_pull_request(*args) # @example # @client.close_pull_request('octokit/octokit.rb', 67) def close_pull_request(repo, number, options = {}) - options.merge! :state => 'closed' + options.merge! state: 'closed' update_pull_request(repo, number, options) end @@ -130,7 +130,7 @@ def close_pull_request(repo, number, options = {}) def pull_request_commits(repo, number, options = {}) paginate "#{Repository.path repo}/pulls/#{number}/commits", options end - alias :pull_commits :pull_request_commits + alias pull_commits pull_request_commits # List pull request comments for a repository # @@ -160,8 +160,8 @@ def pull_request_commits(repo, number, options = {}) def pull_requests_comments(repo, options = {}) paginate("#{Repository.path repo}/pulls/comments", options) end - alias :pulls_comments :pull_requests_comments - alias :reviews_comments :pull_requests_comments + alias pulls_comments pull_requests_comments + alias reviews_comments pull_requests_comments # List comments on a pull request # @@ -173,8 +173,8 @@ def pull_request_comments(repo, number, options = {}) # return the comments for a pull request paginate("#{Repository.path repo}/pulls/#{number}/comments", options) end - alias :pull_comments :pull_request_comments - alias :review_comments :pull_request_comments + alias pull_comments pull_request_comments + alias review_comments pull_request_comments # Get a pull request comment # @@ -187,8 +187,8 @@ def pull_request_comments(repo, number, options = {}) def pull_request_comment(repo, comment_id, options = {}) get "#{Repository.path repo}/pulls/comments/#{comment_id}", options end - alias :pull_comment :pull_request_comment - alias :review_comment :pull_request_comment + alias pull_comment pull_request_comment + alias review_comment pull_request_comment # Create a pull request comment # @@ -205,15 +205,15 @@ def pull_request_comment(repo, comment_id, options = {}) # "2d3201e4440903d8b04a5487842053ca4883e5f0", "lib/octokit/request.rb", 47) def create_pull_request_comment(repo, pull_id, body, commit_id, path, position, options = {}) options.merge!({ - :body => body, - :commit_id => commit_id, - :path => path, - :position => position - }) + body: body, + commit_id: commit_id, + path: path, + position: position + }) post "#{Repository.path repo}/pulls/#{pull_id}/comments", options end - alias :create_pull_comment :create_pull_request_comment - alias :create_view_comment :create_pull_request_comment + alias create_pull_comment create_pull_request_comment + alias create_view_comment create_pull_request_comment # Create reply to a pull request comment # @@ -227,13 +227,13 @@ def create_pull_request_comment(repo, pull_id, body, commit_id, path, position, # @client.create_pull_request_comment_reply("octokit/octokit.rb", 163, "done.", 1903950) def create_pull_request_comment_reply(repo, pull_id, body, comment_id, options = {}) options.merge!({ - :body => body, - :in_reply_to => comment_id - }) + body: body, + in_reply_to: comment_id + }) post "#{Repository.path repo}/pulls/#{pull_id}/comments", options end - alias :create_pull_reply :create_pull_request_comment_reply - alias :create_review_reply :create_pull_request_comment_reply + alias create_pull_reply create_pull_request_comment_reply + alias create_review_reply create_pull_request_comment_reply # Update pull request comment # @@ -245,11 +245,11 @@ def create_pull_request_comment_reply(repo, pull_id, body, comment_id, options = # @example # @client.update_pull_request_comment("octokit/octokit.rb", 1903950, ":shipit:") def update_pull_request_comment(repo, comment_id, body, options = {}) - options.merge! :body => body + options.merge! body: body patch("#{Repository.path repo}/pulls/comments/#{comment_id}", options) end - alias :update_pull_comment :update_pull_request_comment - alias :update_review_comment :update_pull_request_comment + alias update_pull_comment update_pull_request_comment + alias update_review_comment update_pull_request_comment # Delete pull request comment # @@ -262,8 +262,8 @@ def update_pull_request_comment(repo, comment_id, body, options = {}) def delete_pull_request_comment(repo, comment_id, options = {}) boolean_from_response(:delete, "#{Repository.path repo}/pulls/comments/#{comment_id}", options) end - alias :delete_pull_comment :delete_pull_request_comment - alias :delete_review_comment :delete_pull_request_comment + alias delete_pull_comment delete_pull_request_comment + alias delete_review_comment delete_pull_request_comment # List files on a pull request # @@ -274,7 +274,7 @@ def delete_pull_request_comment(repo, comment_id, options = {}) def pull_request_files(repo, number, options = {}) paginate "#{Repository.path repo}/pulls/#{number}/files", options end - alias :pull_files :pull_request_files + alias pull_files pull_request_files # Merge a pull request # @@ -283,8 +283,8 @@ def pull_request_files(repo, number, options = {}) # @param number [Integer] Number of pull request # @param commit_message [String] Optional commit message for the merge commit # @return [Array] Merge commit info if successful - def merge_pull_request(repo, number, commit_message='', options = {}) - put "#{Repository.path repo}/pulls/#{number}/merge", options.merge({:commit_message => commit_message}) + def merge_pull_request(repo, number, commit_message = '', options = {}) + put "#{Repository.path repo}/pulls/#{number}/merge", options.merge({ commit_message: commit_message }) end # Check pull request merge status @@ -296,8 +296,7 @@ def merge_pull_request(repo, number, commit_message='', options = {}) def pull_merged?(repo, number, options = {}) boolean_from_response :get, "#{Repository.path repo}/pulls/#{number}/merge", options end - alias :pull_request_merged? :pull_merged? - + alias pull_request_merged? pull_merged? end end end diff --git a/lib/octokit/client/rate_limit.rb b/lib/octokit/client/rate_limit.rb index 8cdae88db..7387a0290 100644 --- a/lib/octokit/client/rate_limit.rb +++ b/lib/octokit/client/rate_limit.rb @@ -1,17 +1,17 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for API rate limiting info # # @see https://developer.github.com/v3/#rate-limiting module RateLimit - # Get rate limit info from last response if available # or make a new request to fetch rate limit # # @see https://developer.github.com/v3/rate_limit/#rate-limit # @return [Octokit::RateLimit] Rate limit info - def rate_limit(options = {}) + def rate_limit(_options = {}) return rate_limit! if last_response.nil? Octokit::RateLimit.from_response(last_response) @@ -22,8 +22,8 @@ def rate_limit(options = {}) # # @see https://developer.github.com/v3/rate_limit/#rate-limit # @return [Integer] Number of requests remaining in this period - def rate_limit_remaining(options = {}) - octokit_warn "Deprecated: Please use .rate_limit.remaining" + def rate_limit_remaining(_options = {}) + octokit_warn 'Deprecated: Please use .rate_limit.remaining' rate_limit.remaining end alias ratelimit_remaining rate_limit_remaining @@ -32,8 +32,8 @@ def rate_limit_remaining(options = {}) # # @see https://developer.github.com/v3/rate_limit/#rate-limit # @return [Octokit::RateLimit] Rate limit info - def rate_limit!(options = {}) - get "rate_limit" + def rate_limit!(_options = {}) + get 'rate_limit' Octokit::RateLimit.from_response(last_response) end alias ratelimit! rate_limit! @@ -42,13 +42,11 @@ def rate_limit!(options = {}) # # @see https://developer.github.com/v3/rate_limit/#rate-limit # @return [Integer] Number of requests remaining in this period - def rate_limit_remaining!(options = {}) - octokit_warn "Deprecated: Please use .rate_limit!.remaining" + def rate_limit_remaining!(_options = {}) + octokit_warn 'Deprecated: Please use .rate_limit!.remaining' rate_limit!.remaining end alias ratelimit_remaining! rate_limit_remaining! - end end end - diff --git a/lib/octokit/client/reactions.rb b/lib/octokit/client/reactions.rb index 0d2965550..02a921095 100644 --- a/lib/octokit/client/reactions.rb +++ b/lib/octokit/client/reactions.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Reacions API # # @see https://developer.github.com/v3/reactions/ module Reactions - # List reactions for a commit comment # # @param repo [Integer, String, Hash, Repository] A GitHub repository @@ -34,7 +34,7 @@ def commit_comment_reactions(repo, id, options = {}) # # @return [] Hash representing the reaction def create_commit_comment_reaction(repo, id, reaction, options = {}) - options = ensure_api_media_type(:reactions, options.merge(:content => reaction)) + options = ensure_api_media_type(:reactions, options.merge(content: reaction)) post "#{Repository.path repo}/comments/#{id}/reactions", options end @@ -67,7 +67,7 @@ def issue_reactions(repo, number, options = {}) # # @return [] Hash representing the reaction. def create_issue_reaction(repo, number, reaction, options = {}) - options = ensure_api_media_type(:reactions, options.merge(:content => reaction)) + options = ensure_api_media_type(:reactions, options.merge(content: reaction)) post "#{Repository.path repo}/issues/#{number}/reactions", options end @@ -101,7 +101,7 @@ def issue_comment_reactions(repo, id, options = {}) # # @return [] Hashes representing the reaction. def create_issue_comment_reaction(repo, id, reaction, options = {}) - options = ensure_api_media_type(:reactions, options.merge(:content => reaction)) + options = ensure_api_media_type(:reactions, options.merge(content: reaction)) post "#{Repository.path repo}/issues/comments/#{id}/reactions", options end @@ -135,7 +135,7 @@ def pull_request_review_comment_reactions(repo, id, options = {}) # # @return [] Hash representing the reaction. def create_pull_request_review_comment_reaction(repo, id, reaction, options = {}) - options = ensure_api_media_type(:reactions, options.merge(:content => reaction)) + options = ensure_api_media_type(:reactions, options.merge(content: reaction)) post "#{Repository.path repo}/pulls/comments/#{id}/reactions", options end diff --git a/lib/octokit/client/refs.rb b/lib/octokit/client/refs.rb index ac6188035..12692c56b 100644 --- a/lib/octokit/client/refs.rb +++ b/lib/octokit/client/refs.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for References for Git Data API # # @see https://developer.github.com/v3/git/refs/ module Refs - # List all refs for a given user and repo # # @param repo [Integer, String, Repository, Hash] A GitHub repository @@ -19,9 +19,9 @@ def refs(repo, namespace = nil, options = {}) path += "/#{namespace}" unless namespace.nil? paginate path, options end - alias :list_refs :refs - alias :references :refs - alias :list_references :refs + alias list_refs refs + alias references refs + alias list_references refs # Fetch matching refs # @@ -46,7 +46,7 @@ def matching_refs(repo, ref, options = {}) def ref(repo, ref, options = {}) get "#{Repository.path repo}/git/refs/#{ref}", options end - alias :reference :ref + alias reference ref # Create a reference # @@ -60,12 +60,12 @@ def ref(repo, ref, options = {}) def create_ref(repo, ref, sha, options = {}) ref = "refs/#{ref}" unless ref =~ %r{\Arefs/} parameters = { - :ref => ref, - :sha => sha + ref: ref, + sha: sha } post "#{Repository.path repo}/git/refs", options.merge(parameters) end - alias :create_reference :create_ref + alias create_reference create_ref # Update a reference # @@ -81,12 +81,12 @@ def create_ref(repo, ref, sha, options = {}) # Octokit.update_ref("octocat/Hello-World", "heads/sc/featureA", "aa218f56b14c9653891f9e74264a383fa43fefbd", false) def update_ref(repo, ref, sha, force = true, options = {}) parameters = { - :sha => sha, - :force => force + sha: sha, + force: force } patch "#{Repository.path repo}/git/refs/#{ref}", options.merge(parameters) end - alias :update_reference :update_ref + alias update_reference update_ref # Update a branch # @@ -127,8 +127,7 @@ def delete_branch(repo, branch, options = {}) def delete_ref(repo, ref, options = {}) boolean_from_response :delete, "#{Repository.path repo}/git/refs/#{ref}", options end - alias :delete_reference :delete_ref - + alias delete_reference delete_ref end end end diff --git a/lib/octokit/client/releases.rb b/lib/octokit/client/releases.rb index fe41be75e..5a6efdd19 100644 --- a/lib/octokit/client/releases.rb +++ b/lib/octokit/client/releases.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Releases API # # @see https://developer.github.com/v3/repos/releases/ module Releases - # List releases for a repository # # @param repo [Integer, String, Repository, Hash] A GitHub repository @@ -14,7 +14,7 @@ module Releases def releases(repo, options = {}) paginate "#{Repository.path repo}/releases", options end - alias :list_releases :releases + alias list_releases releases # Create a release # @@ -28,7 +28,7 @@ def releases(repo, options = {}) # @return [Sawyer::Resource] The release # @see https://developer.github.com/v3/repos/releases/#create-a-release def create_release(repo, tag_name, options = {}) - opts = options.merge(:tag_name => tag_name) + opts = options.merge(tag_name: tag_name) post "#{Repository.path repo}/releases", opts end @@ -55,7 +55,7 @@ def release(url, options = {}) def update_release(url, options = {}) patch url, options end - alias :edit_release :update_release + alias edit_release update_release # Delete a release # @@ -84,17 +84,18 @@ def release_assets(release_url, options = {}) # @return [Sawyer::Resource] The release asset # @see https://developer.github.com/v3/repos/releases/#upload-a-release-asset def upload_asset(release_url, path_or_file, options = {}) - file = path_or_file.respond_to?(:read) ? path_or_file : File.new(path_or_file, "rb") + file = path_or_file.respond_to?(:read) ? path_or_file : File.new(path_or_file, 'rb') options[:content_type] ||= content_type_from_file(file) - raise Octokit::MissingContentType.new if options[:content_type].nil? + raise Octokit::MissingContentType if options[:content_type].nil? + unless name = options[:name] name = File.basename(file.path) end - upload_url = release(release_url).rels[:upload].href_template.expand(:name => name) + upload_url = release(release_url).rels[:upload].href_template.expand(name: name) request :post, upload_url, file.read, parse_query_and_convenience_headers(options) ensure - file.close if file + file&.close end # Get a single release asset @@ -117,7 +118,7 @@ def release_asset(asset_url, options = {}) def update_release_asset(asset_url, options = {}) patch(asset_url, options) end - alias :edit_release_asset :update_release_asset + alias edit_release_asset update_release_asset # Delete a release asset # @@ -155,10 +156,9 @@ def content_type_from_file(file) mime_type.content_type end rescue LoadError - msg = "Please pass content_type or install mime-types gem to guess content type from file" - raise Octokit::MissingContentType.new(msg) + msg = 'Please pass content_type or install mime-types gem to guess content type from file' + raise Octokit::MissingContentType, msg end - end end end diff --git a/lib/octokit/client/repositories.rb b/lib/octokit/client/repositories.rb index bf8bb284d..83e2a0b46 100644 --- a/lib/octokit/client/repositories.rb +++ b/lib/octokit/client/repositories.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Repositories API # # @see https://developer.github.com/v3/repos/ module Repositories - # Check if a repository exists # # @see https://developer.github.com/v3/repos/#get @@ -28,7 +28,7 @@ def repository?(repo, options = {}) def repository(repo, options = {}) get Repository.path(repo), options end - alias :repo :repository + alias repo repository # Edit a repository # @@ -53,9 +53,9 @@ def edit_repository(repo, options = {}) options[:name] ||= repo.name patch "repos/#{repo}", options end - alias :edit :edit_repository - alias :update_repository :edit_repository - alias :update :edit_repository + alias edit edit_repository + alias update_repository edit_repository + alias update edit_repository # List user repositories # @@ -71,12 +71,12 @@ def edit_repository(repo, options = {}) # @param user [Integer, String] Optional GitHub user login or id for which # to list repos. # @return [Array] List of repositories - def repositories(user=nil, options = {}) + def repositories(user = nil, options = {}) paginate "#{User.path user}/repos", options end - alias :list_repositories :repositories - alias :list_repos :repositories - alias :repos :repositories + alias list_repositories repositories + alias list_repos repositories + alias repos repositories # List all repositories # @@ -159,7 +159,7 @@ def fork(repo, options = {}) def create_repository(name, options = {}) opts = options.dup organization = opts.delete :organization - opts.merge! :name => name + opts.merge! name: name if opts.include? :is_template opts = ensure_api_media_type(:template_repositories, opts) end @@ -170,8 +170,8 @@ def create_repository(name, options = {}) post "#{Organization.path organization}/repos", opts end end - alias :create_repo :create_repository - alias :create :create_repository + alias create_repo create_repository + alias create create_repository # Delete repository # @@ -183,7 +183,7 @@ def create_repository(name, options = {}) def delete_repository(repo, options = {}) boolean_from_response :delete, Repository.path(repo), options end - alias :delete_repo :delete_repository + alias delete_repo delete_repository # Transfer repository # @@ -198,7 +198,7 @@ def transfer_repository(repo, new_owner, options = {}) options = ensure_api_media_type(:transfer_repository, options) post "#{Repository.path repo}/transfer", options.merge({ new_owner: new_owner }) end - alias :transfer_repo :transfer_repository + alias transfer_repo transfer_repository # Create a repository for a user or organization generated from a template repository # @@ -210,11 +210,11 @@ def transfer_repository(repo, new_owner, options = {}) # @option options [Boolean] :include_all_branches `true` copies all branches from the template repository, `false` (default) makes it only copy the master branch. # @return [Sawyer::Resource] Repository info for the new repository def create_repository_from_template(repo, name, options = {}) - options.merge! :name => name + options.merge! name: name options = ensure_api_media_type(:template_repositories, options) post "#{Repository.path repo}/generate", options end - alias :create_repo_from_template :create_repository_from_template + alias create_repo_from_template create_repository_from_template # Hide a public repository # @@ -222,7 +222,7 @@ def create_repository_from_template(repo, name, options = {}) # @return [Sawyer::Resource] Updated repository info def set_private(repo, options = {}) # GitHub Api for setting private updated to use private attr, rather than public - update_repository repo, options.merge({ :private => true }) + update_repository repo, options.merge({ private: true }) end # Unhide a private repository @@ -231,7 +231,7 @@ def set_private(repo, options = {}) # @return [Sawyer::Resource] Updated repository info def set_public(repo, options = {}) # GitHub Api for setting private updated to use private attr, rather than public - update_repository repo, options.merge({ :private => false }) + update_repository repo, options.merge({ private: false }) end # Get deploy keys on a repo @@ -248,7 +248,7 @@ def set_public(repo, options = {}) def deploy_keys(repo, options = {}) paginate "#{Repository.path repo}/keys", options end - alias :list_deploy_keys :deploy_keys + alias list_deploy_keys deploy_keys # Get a single deploy key for a repo # @@ -258,7 +258,7 @@ def deploy_keys(repo, options = {}) # @see https://developer.github.com/v3/repos/keys/#get-a-deploy-key # @example # @client.deploy_key('octokit/octokit.rb', 8675309) - def deploy_key(repo, id, options={}) + def deploy_key(repo, id, options = {}) get "#{Repository.path repo}/keys/#{id}", options end @@ -274,7 +274,7 @@ def deploy_key(repo, id, options={}) # @example # @client.add_deploy_key('octokit/octokit.rb', 'Staging server', 'ssh-rsa AAA...') def add_deploy_key(repo, title, key, options = {}) - post "#{Repository.path repo}/keys", options.merge(:title => title, :key => key) + post "#{Repository.path repo}/keys", options.merge(title: title, key: key) end # Edit a deploy key @@ -295,7 +295,7 @@ def add_deploy_key(repo, title, key, options = {}) def edit_deploy_key(repo, id, options) patch "#{Repository.path repo}/keys/#{id}", options end - alias :update_deploy_key :edit_deploy_key + alias update_deploy_key edit_deploy_key # Remove deploy key from a repo # @@ -330,7 +330,7 @@ def remove_deploy_key(repo, id, options = {}) def collaborators(repo, options = {}) paginate "#{Repository.path repo}/collaborators", options end - alias :collabs :collaborators + alias collabs collaborators # Add collaborator to repo # @@ -355,7 +355,7 @@ def collaborators(repo, options = {}) def add_collaborator(repo, collaborator, options = {}) boolean_from_response :put, "#{Repository.path repo}/collaborators/#{collaborator}", options end - alias :add_collab :add_collaborator + alias add_collab add_collaborator # Remove collaborator from repo. # @@ -372,7 +372,7 @@ def add_collaborator(repo, collaborator, options = {}) def remove_collaborator(repo, collaborator, options = {}) boolean_from_response :delete, "#{Repository.path repo}/collaborators/#{collaborator}", options end - alias :remove_collab :remove_collaborator + alias remove_collab remove_collaborator # Checks if a user is a collaborator for a repo. # @@ -384,7 +384,7 @@ def remove_collaborator(repo, collaborator, options = {}) # @see https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator # @example # @client.collaborator?('octokit/octokit.rb', 'holman') - def collaborator?(repo, collaborator, options={}) + def collaborator?(repo, collaborator, options = {}) boolean_from_response :get, "#{Repository.path repo}/collaborators/#{collaborator}", options end @@ -396,7 +396,7 @@ def collaborator?(repo, collaborator, options={}) # @see https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level # @example # @client.permission_level('octokit/octokit.rb', 'lizzhale') - def permission_level(repo, collaborator, options={}) + def permission_level(repo, collaborator, options = {}) get "#{Repository.path repo}/collaborators/#{collaborator}/permission", options end @@ -416,8 +416,8 @@ def permission_level(repo, collaborator, options={}) def repository_teams(repo, options = {}) paginate "#{Repository.path repo}/teams", options end - alias :repo_teams :repository_teams - alias :teams :repository_teams + alias repo_teams repository_teams + alias teams repository_teams # List all topics for a repository # @@ -449,7 +449,7 @@ def topics(repo, options = {}) # client.replace_all_topics('octokit/octokit.rb', []) def replace_all_topics(repo, names, options = {}) opts = ensure_api_media_type(:topics, options) - put "#{Repository.path repo}/topics", opts.merge(:names => names) + put "#{Repository.path repo}/topics", opts.merge(names: names) end # List contributors to a repo @@ -470,7 +470,7 @@ def contributors(repo, anon = nil, options = {}) options[:anon] = 1 if anon.to_s[/1|true/] paginate "#{Repository.path repo}/contributors", options end - alias :contribs :contributors + alias contribs contributors # List stargazers of a repo # @@ -520,7 +520,7 @@ def watchers(repo, options = {}) def forks(repo, options = {}) paginate "#{Repository.path repo}/forks", options end - alias :network :forks + alias network forks # List languages of code in the repo. # @@ -578,7 +578,7 @@ def branches(repo, options = {}) def branch(repo, branch, options = {}) get "#{Repository.path repo}/branches/#{branch}", options end - alias :get_branch :branch + alias get_branch branch # Lock a single branch from a repository # @@ -653,7 +653,7 @@ def unprotect_branch(repo, branch, options = {}) # @client.rename_branch('octokit/octokit.rb', 'master', 'main') def rename_branch(repo, branch, new_name, options = {}) params = { - new_name: new_name, + new_name: new_name } post "#{Repository.path repo}/branches/#{branch}/rename", params.merge(options) end @@ -674,7 +674,7 @@ def rename_branch(repo, branch, new_name, options = {}) def repository_assignees(repo, options = {}) paginate "#{Repository.path repo}/assignees", options end - alias :repo_assignees :repository_assignees + alias repo_assignees repository_assignees # Check to see if a particular user is an assignee for a repository. # diff --git a/lib/octokit/client/repository_invitations.rb b/lib/octokit/client/repository_invitations.rb index 47fdb880b..e3e2c809c 100644 --- a/lib/octokit/client/repository_invitations.rb +++ b/lib/octokit/client/repository_invitations.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Repository Invitations API # # @see https://developer.github.com/v3/repos/invitations/ module RepositoryInvitations - # Invite a user to a repository # # Requires authenticated client @@ -64,7 +64,7 @@ def update_repository_invitation(repo, invitation_id, options = {}) # @return [Array] The users repository invitations # @see https://developer.github.com/v3/repos/invitations/#list-a-users-repository-invitations def user_repository_invitations(options = {}) - paginate "/user/repository_invitations", options + paginate '/user/repository_invitations', options end alias user_repo_invitations user_repository_invitations diff --git a/lib/octokit/client/reviews.rb b/lib/octokit/client/reviews.rb index 7e478e3e1..e081a8108 100644 --- a/lib/octokit/client/reviews.rb +++ b/lib/octokit/client/reviews.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Reviews API # # @see https://developer.github.com/v3/pulls/reviews/ module Reviews - # List reviews on a pull request # # @param repo [Integer, String, Hash, Repository] A GitHub repository @@ -161,9 +161,9 @@ def request_pull_request_review(repo, number, reviewers = {}, options = {}) # TODO(5.0): remove deprecated behavior if reviewers.is_a?(Array) octokit_warn( - "Deprecated: Octokit::Client#request_pull_request_review "\ + 'Deprecated: Octokit::Client#request_pull_request_review '\ "no longer takes a separate :reviewers argument.\n" \ - "Please update your call to pass :reviewers and :team_reviewers as part of the options hash." + 'Please update your call to pass :reviewers and :team_reviewers as part of the options hash.' ) options = options.merge(reviewers: reviewers) else @@ -190,13 +190,13 @@ def request_pull_request_review(repo, number, reviewers = {}, options = {}) # @client.delete_pull_request_review_request('octokit/octokit.rb', 2, options) # # @return [Sawyer::Resource>] Hash representing the pull request - def delete_pull_request_review_request(repo, id, reviewers={}, options = {}) + def delete_pull_request_review_request(repo, id, reviewers = {}, options = {}) # TODO(5.0): remove deprecated behavior if !reviewers.empty? && !options.empty? octokit_warn( - "Deprecated: Octokit::Client#delete_pull_request_review_request "\ + 'Deprecated: Octokit::Client#delete_pull_request_review_request '\ "no longer takes a separate :reviewers argument.\n" \ - "Please update your call to pass :reviewers and :team_reviewers as part of the options hash." + 'Please update your call to pass :reviewers and :team_reviewers as part of the options hash.' ) end # For backwards compatibility, this endpoint can be called with a separate reviewers hash. diff --git a/lib/octokit/client/say.rb b/lib/octokit/client/say.rb index 082be183c..6245adf30 100644 --- a/lib/octokit/client/say.rb +++ b/lib/octokit/client/say.rb @@ -1,19 +1,18 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the unpublished Octocat API module Say - # Return a nifty ASCII Octocat with GitHub wisdom # or your own # # @return [String] def say(text = nil, options = {}) options[:s] = text if text - get "octocat", options + get 'octocat', options end - alias :octocat :say - + alias octocat say end end end diff --git a/lib/octokit/client/search.rb b/lib/octokit/client/search.rb index 181e6cd9c..10c10d7bd 100644 --- a/lib/octokit/client/search.rb +++ b/lib/octokit/client/search.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Search API # # @see https://developer.github.com/v3/search/ module Search - # Search code # # @param query [String] Search term and qualifiers @@ -17,7 +17,7 @@ module Search # @return [Sawyer::Resource] Search results object # @see https://developer.github.com/v3/search/#search-code def search_code(query, options = {}) - search "search/code", query, options + search 'search/code', query, options end # Search commits @@ -32,7 +32,7 @@ def search_code(query, options = {}) # @see https://developer.github.com/v3/search/#search-commits def search_commits(query, options = {}) options = ensure_api_media_type(:commit_search, options) - search "search/commits", query, options + search 'search/commits', query, options end # Search issues @@ -46,7 +46,7 @@ def search_commits(query, options = {}) # @return [Sawyer::Resource] Search results object # @see https://developer.github.com/v3/search/#search-issues-and-pull-requests def search_issues(query, options = {}) - search "search/issues", query, options + search 'search/issues', query, options end # Search repositories @@ -60,9 +60,9 @@ def search_issues(query, options = {}) # @return [Sawyer::Resource] Search results object # @see https://developer.github.com/v3/search/#search-repositories def search_repositories(query, options = {}) - search "search/repositories", query, options + search 'search/repositories', query, options end - alias :search_repos :search_repositories + alias search_repos search_repositories # Search users # @@ -75,13 +75,13 @@ def search_repositories(query, options = {}) # @return [Sawyer::Resource] Search results object # @see https://developer.github.com/v3/search/#search-users def search_users(query, options = {}) - search "search/users", query, options + search 'search/users', query, options end private def search(path, query, options = {}) - opts = options.merge(:q => query) + opts = options.merge(q: query) paginate(path, opts) do |data, last_response| data.items.concat last_response.data.items end diff --git a/lib/octokit/client/service_status.rb b/lib/octokit/client/service_status.rb index df58862f6..2e8a1826d 100644 --- a/lib/octokit/client/service_status.rb +++ b/lib/octokit/client/service_status.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the GitHub Status API # # @see https://status.github.com/api module ServiceStatus - # Root for status API # @private SUMMARY_ROOT = 'https://www.githubstatus.com/api/v2/summary.json' diff --git a/lib/octokit/client/source_import.rb b/lib/octokit/client/source_import.rb index 4ffdb642c..f7d02769d 100644 --- a/lib/octokit/client/source_import.rb +++ b/lib/octokit/client/source_import.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Source Import API # # @see https://developer.github.com/v3/migration/source_imports module SourceImport - # Start a source import to a GitHub repository using GitHub Importer. # # @overload start_source_import(repo, vcs, vcs_url, options = {}) @@ -39,10 +39,10 @@ def start_source_import(*args) vcs_url = arguments.pop vcs = arguments.pop if vcs - octokit_warn "Octokit#start_source_import vcs parameter is now an option, please update your call before the next major Octokit version update." - arguments.options.merge!(:vcs => vcs) + octokit_warn 'Octokit#start_source_import vcs parameter is now an option, please update your call before the next major Octokit version update.' + arguments.options.merge!(vcs: vcs) end - options = ensure_api_media_type(:source_imports, arguments.options.merge(:vcs_url => vcs_url)) + options = ensure_api_media_type(:source_imports, arguments.options.merge(vcs_url: vcs_url)) put "#{Repository.path arguments.repo}/import", options end @@ -153,7 +153,7 @@ def source_import_large_files(repo, options = {}) # @example # @client.opt_in_source_import_lfs("octokit/octokit.rb", "opt_in") def set_source_import_lfs_preference(repo, use_lfs, options = {}) - options = ensure_api_media_type(:source_imports, options.merge(:use_lfs => use_lfs)) + options = ensure_api_media_type(:source_imports, options.merge(use_lfs: use_lfs)) patch "#{Repository.path repo}/import/lfs", options end end diff --git a/lib/octokit/client/stats.rb b/lib/octokit/client/stats.rb index 8dcc8223d..637efa66f 100644 --- a/lib/octokit/client/stats.rb +++ b/lib/octokit/client/stats.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Repository Statistics API # # @see https://developer.github.com/v3/repos/statistics/ module Stats - # Get contributors list with additions, deletions, and commit counts # # @param repo [Integer, String, Hash, Repository] A GitHub repository @@ -16,9 +16,9 @@ module Stats # @example Get contributor stats for octokit # @client.contributors_stats('octokit/octokit.rb') def contributors_stats(repo, options = {}) - get_stats(repo, "contributors", options) + get_stats(repo, 'contributors', options) end - alias :contributor_stats :contributors_stats + alias contributor_stats contributors_stats # Get the last year of commit activity data # @@ -31,7 +31,7 @@ def contributors_stats(repo, options = {}) # @example Get commit activity for octokit # @client.commit_activity_stats('octokit/octokit.rb') def commit_activity_stats(repo, options = {}) - get_stats(repo, "commit_activity", options) + get_stats(repo, 'commit_activity', options) end # Get the number of additions and deletions per week @@ -45,7 +45,7 @@ def commit_activity_stats(repo, options = {}) # @example Get code frequency stats for octokit # @client.code_frequency_stats('octokit/octokit.rb') def code_frequency_stats(repo, options = {}) - get_stats(repo, "code_frequency", options) + get_stats(repo, 'code_frequency', options) end # Get the weekly commit count for the repo owner and everyone else @@ -61,7 +61,7 @@ def code_frequency_stats(repo, options = {}) # @example Get weekly commit counts for octokit # @client.participation_stats("octokit/octokit.rb") def participation_stats(repo, options = {}) - get_stats(repo, "participation", options) + get_stats(repo, 'participation', options) end # Get the number of commits per hour in each day @@ -75,9 +75,9 @@ def participation_stats(repo, options = {}) # @example Get octokit punch card # @octokit.punch_card_stats def punch_card_stats(repo, options = {}) - get_stats(repo, "punch_card", options) + get_stats(repo, 'punch_card', options) end - alias :punch_card :punch_card_stats + alias punch_card punch_card_stats private @@ -99,6 +99,7 @@ def get_stats(repo, metric, options = {}) return [] if last_response.status == 204 return nil unless retry_timeout return nil if Time.now >= timeout + sleep retry_wait if retry_wait end end diff --git a/lib/octokit/client/statuses.rb b/lib/octokit/client/statuses.rb index 9a24883b3..6696424e9 100644 --- a/lib/octokit/client/statuses.rb +++ b/lib/octokit/client/statuses.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Commit Statuses API # # @see https://developer.github.com/v3/repos/statuses/ module Statuses - # List all statuses for a given commit # # @param repo [Integer, String, Repository, Hash] A GitHub repository @@ -15,7 +15,7 @@ module Statuses def statuses(repo, sha, options = {}) paginate "#{Repository.path repo}/statuses/#{sha}", options end - alias :list_statuses :statuses + alias list_statuses statuses # Get the combined status for a ref # @@ -26,7 +26,7 @@ def statuses(repo, sha, options = {}) def combined_status(repo, ref, options = {}) get "#{Repository.path repo}/commits/#{ref}/status", options end - alias :status :combined_status + alias status combined_status # Create status for a commit # @@ -39,7 +39,7 @@ def combined_status(repo, ref, options = {}) # @return [Sawyer::Resource] A status # @see https://developer.github.com/v3/repos/statuses/#create-a-status def create_status(repo, sha, state, options = {}) - options = options.merge(:state => state) + options = options.merge(state: state) post "#{Repository.path repo}/statuses/#{sha}", options end end diff --git a/lib/octokit/client/traffic.rb b/lib/octokit/client/traffic.rb index e6802f982..19ec1654d 100644 --- a/lib/octokit/client/traffic.rb +++ b/lib/octokit/client/traffic.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Traffic API # # @see https://developer.github.com/v3/repos/traffic/ module Traffic - # Get the top 10 referrers over the last 14 days # # @param repo [Integer, String, Repository, Hash] A GitHub repository @@ -63,7 +63,6 @@ def clones(repo, options = {}) opts = ensure_api_media_type(:traffic, options) get "#{Repository.path repo}/traffic/clones", opts end - end end end diff --git a/lib/octokit/client/users.rb b/lib/octokit/client/users.rb index 0ad66ee42..aa101d96c 100644 --- a/lib/octokit/client/users.rb +++ b/lib/octokit/client/users.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class Client - # Methods for the Users API # # @see https://developer.github.com/v3/users/ module Users - # List all GitHub users # # This provides a list of every user, in the order that they signed up @@ -19,7 +19,7 @@ module Users # # @return [Array] List of GitHub users. def all_users(options = {}) - paginate "users", options + paginate 'users', options end # Get a single user @@ -30,7 +30,7 @@ def all_users(options = {}) # @see https://developer.github.com/v3/users/#get-the-authenticated-user # @example # Octokit.user("sferik") - def user(user=nil, options = {}) + def user(user = nil, options = {}) get User.path(user), options end @@ -45,14 +45,14 @@ def user(user=nil, options = {}) # Octokit.exchange_code_for_token('aaaa', 'xxxx', 'yyyy', {:accept => 'application/json'}) def exchange_code_for_token(code, app_id = client_id, app_secret = client_secret, options = {}) options = options.merge({ - :code => code, - :client_id => app_id, - :client_secret => app_secret, - :headers => { - :content_type => 'application/json', - :accept => 'application/json' - } - }) + code: code, + client_id: app_id, + client_secret: app_secret, + headers: { + content_type: 'application/json', + accept: 'application/json' + } + }) post "#{web_endpoint}login/oauth/access_token", options end @@ -84,7 +84,7 @@ def validate_credentials(options = {}) # @example # Octokit.update_user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false) def update_user(options) - patch "user", options + patch 'user', options end # Get a user's followers. @@ -96,7 +96,7 @@ def update_user(options) # @see https://developer.github.com/v3/users/followers/#list-followers-of-a-user # @example # Octokit.followers('pengwynn') - def followers(user=login, options = {}) + def followers(user = login, options = {}) paginate "#{User.path user}/followers", options end @@ -109,7 +109,7 @@ def followers(user=login, options = {}) # @see https://developer.github.com/v3/users/followers/#list-users-followed-by-another-user # @example # Octokit.following('pengwynn') - def following(user=login, options = {}) + def following(user = login, options = {}) paginate "#{User.path user}/following", options end @@ -174,7 +174,7 @@ def unfollow(user, options = {}) # @see https://developer.github.com/v3/activity/starring/#list-repositories-being-starred # @example # Octokit.starred('pengwynn') - def starred(user=login, options = {}) + def starred(user = login, options = {}) paginate user_path(user, 'starred'), options end @@ -227,7 +227,7 @@ def key(key_id, options = {}) # @example # @client.keys def keys(options = {}) - paginate "user/keys", options + paginate 'user/keys', options end # Get list of public keys for user. @@ -253,7 +253,7 @@ def user_keys(user, options = {}) # @example # @client.add_key('Personal projects key', 'ssh-rsa AAA...') def add_key(title, key, options = {}) - post "user/keys", options.merge({:title => title, :key => key}) + post 'user/keys', options.merge({ title: title, key: key }) end # Update a public key @@ -297,7 +297,7 @@ def remove_key(id, options = {}) # @example # @client.emails def emails(options = {}) - paginate "user/emails", options + paginate 'user/emails', options end # Add email address to user. @@ -309,9 +309,9 @@ def emails(options = {}) # @see https://developer.github.com/v3/users/emails/#add-email-addresses # @example # @client.add_email('new_email@user.com') - def add_email(email, options = {}) + def add_email(email, _options = {}) email = Array(email) - post "user/emails", email + post 'user/emails', email end # Remove email from user. @@ -325,7 +325,7 @@ def add_email(email, options = {}) # @client.remove_email('old_email@user.com') def remove_email(email) email = Array(email) - boolean_from_response :delete, "user/emails", email + boolean_from_response :delete, 'user/emails', email end # List repositories being watched by a user. @@ -335,10 +335,10 @@ def remove_email(email) # @see https://developer.github.com/v3/activity/watching/#list-repositories-being-watched # @example # @client.subscriptions("pengwynn") - def subscriptions(user=login, options = {}) + def subscriptions(user = login, options = {}) paginate user_path(user, 'subscriptions'), options end - alias :watched :subscriptions + alias watched subscriptions # Initiates the generation of a migration archive. # @@ -354,7 +354,7 @@ def subscriptions(user=login, options = {}) def start_user_migration(repositories, options = {}) options = ensure_api_media_type(:migrations, options) options[:repositories] = repositories - post "user/migrations", options + post 'user/migrations', options end # Lists the most recent migrations. @@ -365,7 +365,7 @@ def start_user_migration(repositories, options = {}) # @see https://docs.github.com/en/rest/reference/migrations#list-user-migrations def user_migrations(options = {}) options = ensure_api_media_type(:migrations, options) - paginate "user/migrations", options + paginate 'user/migrations', options end # Fetches the status of a migration. @@ -429,6 +429,7 @@ def unlock_user_repository(id, repo, options = {}) end private + # convenience method for constructing a user specific path, if the user is logged in def user_path(user, path) if user == login && user_authenticated? diff --git a/lib/octokit/configurable.rb b/lib/octokit/configurable.rb index f3d0568db..b84832d4d 100644 --- a/lib/octokit/configurable.rb +++ b/lib/octokit/configurable.rb @@ -1,5 +1,6 @@ -module Octokit +# frozen_string_literal: true +module Octokit # Configuration options for {Client}, defaulting to values # in {Default} module Configurable @@ -61,31 +62,30 @@ module Configurable :management_console_endpoint, :management_console_password class << self - # List of configurable keys for {Octokit::Client} # @return [Array] of option keys def keys - @keys ||= [ - :access_token, - :api_endpoint, - :auto_paginate, - :bearer_token, - :client_id, - :client_secret, - :connection_options, - :default_media_type, - :login, - :management_console_endpoint, - :management_console_password, - :middleware, - :netrc, - :netrc_file, - :per_page, - :password, - :proxy, - :ssl_verify_mode, - :user_agent, - :web_endpoint + @keys ||= %i[ + access_token + api_endpoint + auto_paginate + bearer_token + client_id + client_secret + connection_options + default_media_type + login + management_console_endpoint + management_console_password + middleware + netrc + netrc_file + per_page + password + proxy + ssl_verify_mode + user_agent + web_endpoint ] end end @@ -97,7 +97,7 @@ def configure # Reset configuration options to default values def reset! - Octokit::Configurable.keys.each do |key| + Octokit::Configurable.each_key do |key| instance_variable_set(:"@#{key}", Octokit::Default.options[key]) end self @@ -113,18 +113,18 @@ def same_options?(opts) end def api_endpoint - File.join(@api_endpoint, "") + File.join(@api_endpoint, '') end def management_console_endpoint - File.join(@management_console_endpoint, "") + File.join(@management_console_endpoint, '') end # Base URL for generated web URLs # # @return [String] Default: https://github.com/ def web_endpoint - File.join(@web_endpoint, "") + File.join(@web_endpoint, '') end def login @@ -140,7 +140,7 @@ def netrc? private def options - Hash[Octokit::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}] + Hash[Octokit::Configurable.keys.map { |key| [key, instance_variable_get(:"@#{key}")] }] end def fetch_client_id_and_secret(overrides = {}) diff --git a/lib/octokit/connection.rb b/lib/octokit/connection.rb index 5b7df9958..be8e0e36c 100644 --- a/lib/octokit/connection.rb +++ b/lib/octokit/connection.rb @@ -1,14 +1,14 @@ +# frozen_string_literal: true + require 'sawyer' require 'octokit/authentication' module Octokit - # Network layer for API clients. module Connection - include Octokit::Authentication # Header keys that can be passed in options hash to {#get},{#head} - CONVENIENCE_HEADERS = Set.new([:accept, :content_type]) + CONVENIENCE_HEADERS = Set.new(%i[accept content_type]) # Make a HTTP GET request # @@ -75,17 +75,17 @@ def head(url, options = {}) # contains the contents of the requests so far and the second parameter # contains the latest response. # @return [Sawyer::Resource] - def paginate(url, options = {}, &block) + def paginate(url, options = {}) opts = parse_query_and_convenience_headers(options) if @auto_paginate || @per_page - opts[:query][:per_page] ||= @per_page || (@auto_paginate ? 100 : nil) + opts[:query][:per_page] ||= @per_page || (@auto_paginate ? 100 : nil) end data = request(:get, url, opts.dup) if @auto_paginate while @last_response.rels[:next] && rate_limit.remaining > 0 - @last_response = @last_response.rels[:next].get(:headers => opts[:headers]) + @last_response = @last_response.rels[:next].get(headers: opts[:headers]) if block_given? yield(data, @last_response) else @@ -104,7 +104,7 @@ def paginate(url, options = {}, &block) def agent @agent ||= Sawyer::Agent.new(endpoint, sawyer_options) do |http| http.headers[:accept] = default_media_type - http.headers[:content_type] = "application/json" + http.headers[:content_type] = 'application/json' http.headers[:user_agent] = user_agent if basic_authenticated? http.request *FARADAY_BASIC_AUTH_KEYS, @login, @password @@ -122,7 +122,7 @@ def agent # # @return [Sawyer::Resource] def root - get "/" + get '/' end # Response for last HTTP request @@ -155,9 +155,9 @@ def request(method, path, data, options = {}) @last_response = response = agent.call(method, Addressable::URI.parse(path.to_s).normalize.to_s, data, options) response.data - rescue Octokit::Error => error + rescue Octokit::Error => e @last_response = nil - raise error + raise e end # Executes the request, checking if it was successful @@ -170,21 +170,20 @@ def boolean_from_response(method, path, options = {}) false end - def sawyer_options opts = { - :links_parser => Sawyer::LinkParsers::Simple.new + links_parser: Sawyer::LinkParsers::Simple.new } conn_opts = @connection_options conn_opts[:builder] = @middleware.dup if @middleware conn_opts[:proxy] = @proxy if @proxy if conn_opts[:ssl].nil? - conn_opts[:ssl] = { :verify_mode => @ssl_verify_mode } if @ssl_verify_mode + conn_opts[:ssl] = { verify_mode: @ssl_verify_mode } if @ssl_verify_mode else verify = @connection_options[:ssl][:verify] conn_opts[:ssl] = { - :verify => verify, - :verify_mode => verify == false ? 0 : @ssl_verify_mode + verify: verify, + verify_mode: verify == false ? 0 : @ssl_verify_mode } end opts[:faraday] = Faraday.new(conn_opts) @@ -194,15 +193,15 @@ def sawyer_options def parse_query_and_convenience_headers(options) options = options.dup - headers = options.delete(:headers) { Hash.new } + headers = options.delete(:headers) { {} } CONVENIENCE_HEADERS.each do |h| if header = options.delete(h) headers[h] = header end end query = options.delete(:query) - opts = {:query => options} - opts[:query].merge!(query) if query && query.is_a?(Hash) + opts = { query: options } + opts[:query].merge!(query) if query&.is_a?(Hash) opts[:headers] = headers unless headers.empty? opts diff --git a/lib/octokit/default.rb b/lib/octokit/default.rb index 4cd1e750e..bd5806037 100644 --- a/lib/octokit/default.rb +++ b/lib/octokit/default.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'octokit/middleware/follow_redirects' require 'octokit/response/raise_error' require 'octokit/response/feed_parser' @@ -13,28 +15,30 @@ end module Octokit - # Default configuration options for {Client} module Default - # Default API endpoint - API_ENDPOINT = "https://api.github.com".freeze + API_ENDPOINT = 'https://api.github.com' # Default User Agent header string - USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}".freeze + USER_AGENT = "Octokit Ruby Gem #{Octokit::VERSION}" # Default media type - MEDIA_TYPE = "application/vnd.github.v3+json".freeze + MEDIA_TYPE = 'application/vnd.github.v3+json' # Default WEB endpoint - WEB_ENDPOINT = "https://github.com".freeze + WEB_ENDPOINT = 'https://github.com' # Default Faraday middleware stack MIDDLEWARE = Faraday::RackBuilder.new do |builder| # In Faraday 2.x, Faraday::Request::Retry was moved to a separate gem # so we use it only when it's available. - builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError] if defined?(Faraday::Request::Retry) - builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError] if defined?(Faraday::Retry::Middleware) + if defined?(Faraday::Request::Retry) + builder.use Faraday::Request::Retry, exceptions: [Octokit::ServerError] + end + if defined?(Faraday::Retry::Middleware) + builder.use Faraday::Retry::Middleware, exceptions: [Octokit::ServerError] + end builder.use Octokit::Middleware::FollowRedirects builder.use Octokit::Response::RaiseError @@ -43,11 +47,10 @@ module Default end class << self - # Configuration options # @return [Hash] def options - Hash[Octokit::Configurable.keys.map{|key| [key, send(key)]}] + Hash[Octokit::Configurable.keys.map { |key| [key, send(key)] }] end # Default access token from ENV @@ -102,9 +105,9 @@ def management_console_endpoint # @return [Hash] def connection_options { - :headers => { - :accept => default_media_type, - :user_agent => user_agent + headers: { + accept: default_media_type, + user_agent: user_agent } } end @@ -139,7 +142,7 @@ def password def per_page page_size = ENV['OCTOKIT_PER_PAGE'] - page_size.to_i if page_size + page_size&.to_i end # Default proxy server URI for Faraday connection from ENV @@ -180,7 +183,6 @@ def netrc def netrc_file ENV['OCTOKIT_NETRC_FILE'] || File.join(ENV['HOME'].to_s, '.netrc') end - end end end diff --git a/lib/octokit/enterprise_admin_client.rb b/lib/octokit/enterprise_admin_client.rb index 64a1c56f9..4da56bb11 100644 --- a/lib/octokit/enterprise_admin_client.rb +++ b/lib/octokit/enterprise_admin_client.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'octokit/connection' require 'octokit/configurable' require 'octokit/warnable' @@ -8,7 +10,6 @@ require 'octokit/enterprise_admin_client/users' module Octokit - # EnterpriseAdminClient is only meant to be used by GitHub Enterprise Admins # and provides access the Admin only API endpoints including Admin Stats, # Management Console, and the Search Indexing API. @@ -17,7 +18,6 @@ module Octokit # and GitHub Enterprise. # @see https://developer.github.com/v3/enterprise/ class EnterpriseAdminClient - include Octokit::Configurable include Octokit::Connection include Octokit::Warnable @@ -29,12 +29,11 @@ class EnterpriseAdminClient def initialize(options = {}) # Use options passed in, but fall back to module defaults - Octokit::Configurable.keys.each do |key| + Octokit::Configurable.each_key do |key| instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}")) end login_from_netrc unless user_authenticated? || application_authenticated? end - end end diff --git a/lib/octokit/enterprise_admin_client/admin_stats.rb b/lib/octokit/enterprise_admin_client/admin_stats.rb index fd469382b..80d3d813b 100644 --- a/lib/octokit/enterprise_admin_client/admin_stats.rb +++ b/lib/octokit/enterprise_admin_client/admin_stats.rb @@ -1,18 +1,18 @@ +# frozen_string_literal: true + module Octokit class EnterpriseAdminClient - # Methods for the Enterprise Admin Stats API # # @see https://developer.github.com/v3/enterprise-admin/admin_stats/ module AdminStats - # Get all available stats # # @return [Sawyer::Resource] All available stats # @example Get all available stats # @client.admin_stats def admin_stats - get_admin_stats "all" + get_admin_stats 'all' end # Get only repository-related stats @@ -21,7 +21,7 @@ def admin_stats # @example Get only repository-related stats # @client.admin_repository_stats def admin_repository_stats - get_admin_stats "repos" + get_admin_stats 'repos' end # Get only hooks-related stats @@ -30,7 +30,7 @@ def admin_repository_stats # @example Get only hooks-related stats # @client.admin_hooks_stats def admin_hooks_stats - get_admin_stats "hooks" + get_admin_stats 'hooks' end # Get only pages-related stats @@ -39,7 +39,7 @@ def admin_hooks_stats # @example Get only pages-related stats # @client.admin_pages_stats def admin_pages_stats - get_admin_stats "pages" + get_admin_stats 'pages' end # Get only organization-related stats @@ -48,7 +48,7 @@ def admin_pages_stats # @example Get only organization-related stats # @client.admin_organization_stats def admin_organization_stats - get_admin_stats "orgs" + get_admin_stats 'orgs' end # Get only user-related stats @@ -57,7 +57,7 @@ def admin_organization_stats # @example Get only user-related stats # @client.admin_users_stats def admin_users_stats - get_admin_stats "users" + get_admin_stats 'users' end # Get only pull request-related stats @@ -66,7 +66,7 @@ def admin_users_stats # @example Get only pull request-related stats # @client.admin_pull_requests_stats def admin_pull_requests_stats - get_admin_stats "pulls" + get_admin_stats 'pulls' end # Get only issue-related stats @@ -75,7 +75,7 @@ def admin_pull_requests_stats # @example Get only issue-related stats # @client.admin_issues_stats def admin_issues_stats - get_admin_stats "issues" + get_admin_stats 'issues' end # Get only milestone-related stats @@ -84,7 +84,7 @@ def admin_issues_stats # @example Get only milestone-related stats # @client.admin_milestones_stats def admin_milestones_stats - get_admin_stats "milestones" + get_admin_stats 'milestones' end # Get only gist-related stats @@ -93,7 +93,7 @@ def admin_milestones_stats # @example Get only gist-related stats # @client.admin_gits_stats def admin_gists_stats - get_admin_stats "gists" + get_admin_stats 'gists' end # Get only comment-related stats @@ -102,7 +102,7 @@ def admin_gists_stats # @example Get only comment-related stats # @client.admin_comments_stats def admin_comments_stats - get_admin_stats "comments" + get_admin_stats 'comments' end private @@ -115,6 +115,5 @@ def get_admin_stats(metric) get "enterprise/stats/#{metric}" end end - end end diff --git a/lib/octokit/enterprise_admin_client/license.rb b/lib/octokit/enterprise_admin_client/license.rb index 25785f961..4150cb51b 100644 --- a/lib/octokit/enterprise_admin_client/license.rb +++ b/lib/octokit/enterprise_admin_client/license.rb @@ -1,18 +1,17 @@ +# frozen_string_literal: true + module Octokit class EnterpriseAdminClient - # Methods for the Enterprise License API # # @see https://developer.github.com/v3/enterprise-admin/license/ module License - # Get information about the Enterprise license # # @return [Sawyer::Resource] The license information def license_info - get "enterprise/settings/license" + get 'enterprise/settings/license' end - end end end diff --git a/lib/octokit/enterprise_admin_client/orgs.rb b/lib/octokit/enterprise_admin_client/orgs.rb index ce86ab8d6..2dd2af29f 100644 --- a/lib/octokit/enterprise_admin_client/orgs.rb +++ b/lib/octokit/enterprise_admin_client/orgs.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class EnterpriseAdminClient - # Methods for the Enterprise Orgs API # # @see https://developer.github.com/v3/enterprise-admin/orgs/ module Orgs - # Create a new organization on the instance. # # @param login [String] The organization's username. @@ -19,9 +19,8 @@ module Orgs def create_organization(login, admin, options = {}) options[:login] = login options[:admin] = admin - post "admin/organizations", options + post 'admin/organizations', options end - end end end diff --git a/lib/octokit/enterprise_admin_client/search_indexing.rb b/lib/octokit/enterprise_admin_client/search_indexing.rb index cb0bc6c60..d725af9c7 100644 --- a/lib/octokit/enterprise_admin_client/search_indexing.rb +++ b/lib/octokit/enterprise_admin_client/search_indexing.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class EnterpriseAdminClient - # Methods for the Enterprise Search Indexing API # # @see https://developer.github.com/v3/enterprise-admin/search_indexing/ module SearchIndexing - # Queue a User or Organization to be indexed # # @param user [String] A GitHub Enterprise user or organization @@ -13,7 +13,7 @@ module SearchIndexing def index_user(user) queue_index user end - alias :index_organization :index_user + alias index_organization index_user # Queue a Repository to be indexed # @@ -46,7 +46,7 @@ def index_repository_code(repo) def index_users_repositories(user) queue_index "#{user}/*" end - alias :index_organizations_repositories :index_users_repositories + alias index_organizations_repositories index_users_repositories # Queue an index of all the issues across all of a user's or # organization's repositories @@ -56,7 +56,7 @@ def index_users_repositories(user) def index_users_repositories_issues(user) queue_index "#{user}/*/issues" end - alias :index_organizations_repositories_issues :index_users_repositories_issues + alias index_organizations_repositories_issues index_users_repositories_issues # Queue an index of all the code contained in all of a user's or # organization's repositories @@ -66,7 +66,7 @@ def index_users_repositories_issues(user) def index_users_repositories_code(user) queue_index "#{user}/*/code" end - alias :index_organizations_repositories_code :index_users_repositories_code + alias index_organizations_repositories_code index_users_repositories_code private @@ -75,9 +75,8 @@ def index_users_repositories_code(user) # @param target [String] Target to index # @return [Sawyer:Resource] Result of the queuing containing `:message` def queue_index(target) - post "staff/indexing_jobs", :target => target + post 'staff/indexing_jobs', target: target end end - end end diff --git a/lib/octokit/enterprise_admin_client/users.rb b/lib/octokit/enterprise_admin_client/users.rb index 2a4e30e50..182d851a4 100644 --- a/lib/octokit/enterprise_admin_client/users.rb +++ b/lib/octokit/enterprise_admin_client/users.rb @@ -1,6 +1,7 @@ +# frozen_string_literal: true + module Octokit class EnterpriseAdminClient - # Methods for the Enterprise User Administration API # # @see https://developer.github.com/enterprise/v3/enterprise-admin/users/ @@ -15,7 +16,7 @@ module Users def create_user(login, email, options = {}) options[:login] = login options[:email] = email - post "admin/users", options + post 'admin/users', options end # Promote an ordinary user to a site administrator @@ -111,7 +112,7 @@ def delete_impersonation_token(login, options = {}) # @example # @admin_client.list_all_keys def list_all_keys(options = {}) - get "admin/keys", options + get 'admin/keys', options end # Deletes a public SSH keys. @@ -121,7 +122,7 @@ def list_all_keys(options = {}) # @example # @admin_client.delete_key(1) def delete_key(id, options = {}) - boolean_from_response :delete, "admin/keys/#{id}", options + boolean_from_response :delete, "admin/keys/#{id}", options end end end diff --git a/lib/octokit/enterprise_management_console_client.rb b/lib/octokit/enterprise_management_console_client.rb index 0310ead83..641c495da 100644 --- a/lib/octokit/enterprise_management_console_client.rb +++ b/lib/octokit/enterprise_management_console_client.rb @@ -1,10 +1,11 @@ +# frozen_string_literal: true + require 'octokit/configurable' require 'octokit/connection' require 'octokit/warnable' require 'octokit/enterprise_management_console_client/management_console' module Octokit - # EnterpriseManagementConsoleClient is only meant to be used by GitHub Enterprise Admins # and provides access to the management console API endpoints. # @@ -12,7 +13,6 @@ module Octokit # and GitHub Enterprise. # @see https://developer.github.com/v3/enterprise-admin/management_console/ class EnterpriseManagementConsoleClient - include Octokit::Configurable include Octokit::Connection include Octokit::Warnable @@ -20,7 +20,7 @@ class EnterpriseManagementConsoleClient def initialize(options = {}) # Use options passed in, but fall back to module defaults - Octokit::Configurable.keys.each do |key| + Octokit::Configurable.each_key do |key| instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}")) end end diff --git a/lib/octokit/enterprise_management_console_client/management_console.rb b/lib/octokit/enterprise_management_console_client/management_console.rb index 5128df57b..f267ee58c 100644 --- a/lib/octokit/enterprise_management_console_client/management_console.rb +++ b/lib/octokit/enterprise_management_console_client/management_console.rb @@ -1,11 +1,11 @@ +# frozen_string_literal: true + module Octokit class EnterpriseManagementConsoleClient - # Methods for the Enterprise Management Console API # # @see https://developer.github.com/v3/enterprise-admin/management_console/ module ManagementConsole - # Uploads a license for the first time # # @param license [String] The path to your .ghl license file. @@ -16,19 +16,19 @@ module ManagementConsole def upload_license(license, settings = nil) conn = faraday_configuration - params = { } + params = {} params[:license] = Faraday::UploadIO.new(license, 'binary') params[:password] = @management_console_password - params[:settings] = "#{settings.to_json}" unless settings.nil? + params[:settings] = settings.to_json.to_s unless settings.nil? - @last_response = conn.post("/setup/api/start", params) + @last_response = conn.post('/setup/api/start', params) end # Start a configuration process. # # @return nil def start_configuration - post "/setup/api/configure", password_hash + post '/setup/api/configure', password_hash end # Upgrade an Enterprise installation @@ -39,27 +39,27 @@ def start_configuration def upgrade(license) conn = faraday_configuration - params = { } + params = {} params[:license] = Faraday::UploadIO.new(license, 'binary') params[:api_key] = @management_console_password - @last_response = conn.post("/setup/api/upgrade", params) + @last_response = conn.post('/setup/api/upgrade', params) end # Get information about the Enterprise installation # # @return [Sawyer::Resource] The installation information def config_status - get "/setup/api/configcheck", password_hash + get '/setup/api/configcheck', password_hash end - alias :config_check :config_status + alias config_check config_status # Get information about the Enterprise installation # # @return [Sawyer::Resource] The settings def settings - get "/setup/api/settings", password_hash + get '/setup/api/settings', password_hash end - alias :get_settings :settings + alias get_settings settings # Modify the Enterprise settings # @@ -68,17 +68,17 @@ def settings # @return [nil] def edit_settings(settings) queries = password_hash - queries[:query][:settings] = "#{settings.to_json}" - put "/setup/api/settings", queries + queries[:query][:settings] = settings.to_json.to_s + put '/setup/api/settings', queries end # Get information about the Enterprise maintenance status # # @return [Sawyer::Resource] The maintenance status def maintenance_status - get "/setup/api/maintenance", password_hash + get '/setup/api/maintenance', password_hash end - alias :get_maintenance_status :maintenance_status + alias get_maintenance_status maintenance_status # Start (or turn off) the Enterprise maintenance mode # @@ -86,18 +86,18 @@ def maintenance_status # @return [nil] def set_maintenance_status(maintenance) queries = password_hash - queries[:query][:maintenance] = "#{maintenance.to_json}" - post "/setup/api/maintenance", queries + queries[:query][:maintenance] = maintenance.to_json.to_s + post '/setup/api/maintenance', queries end - alias :edit_maintenance_status :set_maintenance_status + alias edit_maintenance_status set_maintenance_status # Fetch the authorized SSH keys on the Enterprise install # # @return [Sawyer::Resource] An array of authorized SSH keys def authorized_keys - get "/setup/api/settings/authorized-keys", password_hash + get '/setup/api/settings/authorized-keys', password_hash end - alias :get_authorized_keys :authorized_keys + alias get_authorized_keys authorized_keys # Add an authorized SSH keys on the Enterprise install # @@ -108,7 +108,7 @@ def add_authorized_key(key) case key when String if File.exist?(key) - key = File.open(key, "r") + key = File.open(key, 'r') content = key.read.strip key.close else @@ -120,7 +120,7 @@ def add_authorized_key(key) end queries[:query][:authorized_key] = content - post "/setup/api/settings/authorized-keys", queries + post '/setup/api/settings/authorized-keys', queries end # Removes an authorized SSH keys from the Enterprise install @@ -132,7 +132,7 @@ def remove_authorized_key(key) case key when String if File.exist?(key) - key = File.open(key, "r") + key = File.open(key, 'r') content = key.read.strip key.close else @@ -144,27 +144,27 @@ def remove_authorized_key(key) end queries[:query][:authorized_key] = content - delete "/setup/api/settings/authorized-keys", queries + delete '/setup/api/settings/authorized-keys', queries end - alias :delete_authorized_key :remove_authorized_key - + alias delete_authorized_key remove_authorized_key end + private def password_hash - { :query => { :api_key => @management_console_password } } + { query: { api_key: @management_console_password } } end # We fall back to raw Faraday for handling the licenses because I'm suspicious # that Sawyer isn't handling binary POSTs correctly: https://github.com/lostisland/sawyer/blob/03fca4c020f465ec42856d0486ec3991859b0aed/lib/sawyer/agent.rb#L85 def faraday_configuration - @faraday_configuration ||= Faraday.new(:url => @management_console_endpoint) do |http| + @faraday_configuration ||= Faraday.new(url: @management_console_endpoint) do |http| http.headers[:user_agent] = user_agent http.request :multipart http.request :url_encoded # Disabling SSL is essential for certain self-hosted Enterprise instances - if self.connection_options[:ssl] && !self.connection_options[:ssl][:verify] + if connection_options[:ssl] && !connection_options[:ssl][:verify] http.ssl[:verify] = false end diff --git a/lib/octokit/error.rb b/lib/octokit/error.rb index 6206a66ae..0b18aa916 100644 --- a/lib/octokit/error.rb +++ b/lib/octokit/error.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Octokit # Custom error class for rescuing from all GitHub errors class Error < StandardError @@ -34,13 +36,13 @@ def self.from_response(response) end end - def build_error_context - if RATE_LIMITED_ERRORS.include?(self.class) - @context = Octokit::RateLimit.from_response(@response) - end - end + def build_error_context + if RATE_LIMITED_ERRORS.include?(self.class) + @context = Octokit::RateLimit.from_response(@response) + end + end - def initialize(response=nil) + def initialize(response = nil) @response = response super(build_error_message) build_error_context @@ -118,7 +120,7 @@ def self.error_for_422(body) # Array of validation errors # @return [Array] Error info def errors - if data && data.is_a?(Hash) + if data&.is_a?(Hash) data[:errors] || [] else [] @@ -152,15 +154,13 @@ def data @data ||= if (body = @response[:body]) && !body.empty? if body.is_a?(String) && - @response[:response_headers] && - @response[:response_headers][:content_type] =~ /json/ + @response[:response_headers] && + @response[:response_headers][:content_type] =~ /json/ Sawyer::Agent.serializer.decode(body) else body end - else - nil end end @@ -183,7 +183,7 @@ def response_error_summary summary = +"\nError summary:\n" summary << data[:errors].map do |error| if error.is_a? Hash - error.map { |k,v| " #{k}: #{v}" } + error.map { |k, v| " #{k}: #{v}" } else " #{error}" end @@ -196,18 +196,20 @@ def build_error_message return nil if @response.nil? message = +"#{@response[:method].to_s.upcase} " - message << redact_url(@response[:url].to_s.dup) + ": " + message << redact_url(@response[:url].to_s.dup) + ': ' message << "#{@response[:status]} - " - message << "#{response_message}" unless response_message.nil? - message << "#{response_error}" unless response_error.nil? - message << "#{response_error_summary}" unless response_error_summary.nil? + message << response_message.to_s unless response_message.nil? + message << response_error.to_s unless response_error.nil? + message << response_error_summary.to_s unless response_error_summary.nil? message << " // See: #{documentation_url}" unless documentation_url.nil? message end def redact_url(url_string) %w[client_secret access_token].each do |token| - url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)") if url_string.include? token + if url_string.include? token + url_string.gsub!(/#{token}=\S+/, "#{token}=(redacted)") + end end url_string end @@ -225,10 +227,10 @@ class Unauthorized < ClientError; end # Raised when GitHub returns a 401 HTTP status code # and headers include "X-GitHub-OTP" class OneTimePasswordRequired < ClientError - #@private - OTP_DELIVERY_PATTERN = /required; (\w+)/i + # @private + OTP_DELIVERY_PATTERN = /required; (\w+)/i.freeze - #@private + # @private def self.required_header(headers) OTP_DELIVERY_PATTERN.match headers['X-GitHub-OTP'].to_s end @@ -350,5 +352,5 @@ class ApplicationCredentialsRequired < StandardError; end # Raised when a repository is created with an invalid format class InvalidRepository < ArgumentError; end - RATE_LIMITED_ERRORS = [Octokit::TooManyRequests, Octokit::AbuseDetected] + RATE_LIMITED_ERRORS = [Octokit::TooManyRequests, Octokit::AbuseDetected].freeze end diff --git a/lib/octokit/gist.rb b/lib/octokit/gist.rb index 6b06b44e7..dbc0740fc 100644 --- a/lib/octokit/gist.rb +++ b/lib/octokit/gist.rb @@ -1,8 +1,8 @@ -module Octokit +# frozen_string_literal: true +module Octokit # Class to parse and create Gist URLs class Gist - # !@attribute id # @return [String] Gist ID attr_accessor :id @@ -31,6 +31,5 @@ def to_s def url "https://gist.github.com/#{@id}" end - end end diff --git a/lib/octokit/middleware/follow_redirects.rb b/lib/octokit/middleware/follow_redirects.rb index 60ca6c16d..9558b0abd 100644 --- a/lib/octokit/middleware/follow_redirects.rb +++ b/lib/octokit/middleware/follow_redirects.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' require 'set' @@ -7,9 +9,7 @@ # https://github.com/lostisland/faraday_middleware/blob/138766e/lib/faraday_middleware/response/follow_redirects.rb module Octokit - module Middleware - # Public: Exception thrown when the maximum amount of requests is exceeded. class RedirectLimitReached < Faraday::ClientError attr_reader :response @@ -30,13 +30,13 @@ def initialize(response) # doesn't support parallelism. class FollowRedirects < Faraday::Middleware # HTTP methods for which 30x redirects can be followed - ALLOWED_METHODS = Set.new [:head, :options, :get, :post, :put, :patch, :delete] + ALLOWED_METHODS = Set.new %i[head options get post put patch delete] # HTTP redirect status codes that this middleware implements REDIRECT_CODES = Set.new [301, 302, 303, 307] # Keys in env hash which will get cleared between requests - ENV_TO_CLEAR = Set.new [:status, :response, :response_headers] + ENV_TO_CLEAR = Set.new %i[status response response_headers] # Default value for max redirects followed FOLLOW_LIMIT = 3 @@ -44,7 +44,7 @@ class FollowRedirects < Faraday::Middleware # Regex that matches characters that need to be escaped in URLs, sans # the "%" character which we assume already represents an escaped # sequence. - URI_UNSAFE = /[^\-_.!~*'()a-zA-Z\d;\/?:@&=+$,\[\]%]/ + URI_UNSAFE = %r{[^\-_.!~*'()a-zA-Z\d;/?:@&=+$,\[\]%]}.freeze # Public: Initialize the middleware. # @@ -64,7 +64,7 @@ def call(env) private def convert_to_get?(response) - ![:head, :options].include?(response.env[:method]) && + !%i[head options].include?(response.env[:method]) && @convert_to_get.include?(response.status) end @@ -75,6 +75,7 @@ def perform_with_redirection(env, follows) response.on_complete do |response_env| if follow_redirect?(response_env, response) raise(RedirectLimitReached, response) if follows.zero? + new_request_env = update_env(response_env, request_body, response) response = perform_with_redirection(new_request_env, follows - 1) end @@ -84,12 +85,12 @@ def perform_with_redirection(env, follows) def update_env(env, request_body, response) original_url = env[:url] - env[:url] += safe_escape(response["location"]) + env[:url] += safe_escape(response['location']) unless same_host?(original_url, env[:url]) # HACK: Faraday’s Authorization middlewares don’t touch the request if the `Authorization` header is set. # This is a workaround to drop authentication info. # See https://github.com/octokit/octokit.rb/pull/1359#issuecomment-925609697 - env[:request_headers]["Authorization"] = "dummy" + env[:request_headers]['Authorization'] = 'dummy' end if convert_to_get?(response) @@ -125,9 +126,9 @@ def same_host?(original_url, redirect_url) # URI:HTTP using the `+` operator. Doesn't escape "%" characters so to not # risk double-escaping. def safe_escape(uri) - uri.to_s.gsub(URI_UNSAFE) { |match| - "%" + match.unpack("H2" * match.bytesize).join("%").upcase - } + uri.to_s.gsub(URI_UNSAFE) do |match| + '%' + match.unpack('H2' * match.bytesize).join('%').upcase + end end end end diff --git a/lib/octokit/organization.rb b/lib/octokit/organization.rb index 24bd2da34..a3cb0dece 100644 --- a/lib/octokit/organization.rb +++ b/lib/octokit/organization.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Octokit # GitHub organization class to generate API path urls class Organization @@ -5,7 +7,7 @@ class Organization # # @param org [String, Integer] GitHub organization login or id # @return [String] Organization Api path - def self.path org + def self.path(org) case org when String "orgs/#{org}" diff --git a/lib/octokit/preview.rb b/lib/octokit/preview.rb index f32d1b4cf..ae4638a6b 100644 --- a/lib/octokit/preview.rb +++ b/lib/octokit/preview.rb @@ -1,31 +1,31 @@ -module Octokit +# frozen_string_literal: true +module Octokit # Default setup options for preview features module Preview - PREVIEW_TYPES = { - :applications_api => 'application/vnd.github.doctor-strange-preview+json'.freeze, - :branch_protection => 'application/vnd.github.luke-cage-preview+json'.freeze, - :commit_search => 'application/vnd.github.cloak-preview+json'.freeze, - :commit_pulls => 'application/vnd.github.groot-preview+json'.freeze, - :commit_branches => 'application/vnd.github.groot-preview+json'.freeze, - :migrations => 'application/vnd.github.wyandotte-preview+json'.freeze, - :licenses => 'application/vnd.github.drax-preview+json'.freeze, - :source_imports => 'application/vnd.github.barred-rock-preview'.freeze, - :reactions => 'application/vnd.github.squirrel-girl-preview'.freeze, - :transfer_repository => 'application/vnd.github.nightshade-preview+json'.freeze, - :issue_timelines => 'application/vnd.github.mockingbird-preview+json'.freeze, - :nested_teams => 'application/vnd.github.hellcat-preview+json'.freeze, - :pages => 'application/vnd.github.mister-fantastic-preview+json'.freeze, - :projects => 'application/vnd.github.inertia-preview+json'.freeze, - :traffic => 'application/vnd.github.spiderman-preview'.freeze, - :topics => 'application/vnd.github.mercy-preview+json'.freeze, - :community_profile => 'application/vnd.github.black-panther-preview+json'.freeze, - :strict_validation => 'application/vnd.github.speedy-preview+json'.freeze, - :template_repositories => 'application/vnd.github.baptiste-preview+json'.freeze, - :project_card_events => 'application/vnd.github.starfox-preview+json'.freeze, - :vulnerability_alerts => 'application/vnd.github.dorian-preview+json'.freeze, - } + applications_api: 'application/vnd.github.doctor-strange-preview+json', + branch_protection: 'application/vnd.github.luke-cage-preview+json', + commit_search: 'application/vnd.github.cloak-preview+json', + commit_pulls: 'application/vnd.github.groot-preview+json', + commit_branches: 'application/vnd.github.groot-preview+json', + migrations: 'application/vnd.github.wyandotte-preview+json', + licenses: 'application/vnd.github.drax-preview+json', + source_imports: 'application/vnd.github.barred-rock-preview', + reactions: 'application/vnd.github.squirrel-girl-preview', + transfer_repository: 'application/vnd.github.nightshade-preview+json', + issue_timelines: 'application/vnd.github.mockingbird-preview+json', + nested_teams: 'application/vnd.github.hellcat-preview+json', + pages: 'application/vnd.github.mister-fantastic-preview+json', + projects: 'application/vnd.github.inertia-preview+json', + traffic: 'application/vnd.github.spiderman-preview', + topics: 'application/vnd.github.mercy-preview+json', + community_profile: 'application/vnd.github.black-panther-preview+json', + strict_validation: 'application/vnd.github.speedy-preview+json', + template_repositories: 'application/vnd.github.baptiste-preview+json', + project_card_events: 'application/vnd.github.starfox-preview+json', + vulnerability_alerts: 'application/vnd.github.dorian-preview+json' + }.freeze def ensure_api_media_type(type, options) if options[:accept].nil? @@ -36,11 +36,11 @@ def ensure_api_media_type(type, options) end def warn_preview(type) - octokit_warn <<-EOS -WARNING: The preview version of the #{type.to_s.capitalize} API is not yet suitable for production use. -You can avoid this message by supplying an appropriate media type in the 'Accept' request -header. -EOS + octokit_warn <<~EOS + WARNING: The preview version of the #{type.to_s.capitalize} API is not yet suitable for production use. + You can avoid this message by supplying an appropriate media type in the 'Accept' request + header. + EOS end end end diff --git a/lib/octokit/rate_limit.rb b/lib/octokit/rate_limit.rb index 201bc674c..21e0d4e77 100644 --- a/lib/octokit/rate_limit.rb +++ b/lib/octokit/rate_limit.rb @@ -1,5 +1,6 @@ -module Octokit +# frozen_string_literal: true +module Octokit # Class for API Rate Limit info # # @!attribute [w] limit @@ -13,14 +14,13 @@ module Octokit # # @see https://developer.github.com/v3/#rate-limiting class RateLimit < Struct.new(:limit, :remaining, :resets_at, :resets_in) - # Get rate limit info from HTTP response # # @param response [#headers] HTTP response # @return [RateLimit] def self.from_response(response) info = new - if response && response.respond_to?(:headers) && !response.headers.nil? + if response&.respond_to?(:headers) && !response.headers.nil? info.limit = (response.headers['X-RateLimit-Limit'] || 1).to_i info.remaining = (response.headers['X-RateLimit-Remaining'] || 1).to_i info.resets_at = Time.at((response.headers['X-RateLimit-Reset'] || Time.now).to_i) diff --git a/lib/octokit/repo_arguments.rb b/lib/octokit/repo_arguments.rb index 6adfee4db..9598fb261 100644 --- a/lib/octokit/repo_arguments.rb +++ b/lib/octokit/repo_arguments.rb @@ -1,9 +1,9 @@ -module Octokit +# frozen_string_literal: true +module Octokit # Class to extract options from Ruby arguments for # Repository-related methods class RepoArguments < Arguments - # !@attribute [r] repo # @return [Repository] attr_reader :repo @@ -14,6 +14,5 @@ def initialize(args) arguments end - end end diff --git a/lib/octokit/repository.rb b/lib/octokit/repository.rb index caa3c5b20..9d3217c41 100644 --- a/lib/octokit/repository.rb +++ b/lib/octokit/repository.rb @@ -1,19 +1,20 @@ -module Octokit +# frozen_string_literal: true +module Octokit # Class to parse GitHub repository owner and name from # URLs and to generate URLs class Repository attr_accessor :owner, :name, :id - NAME_WITH_OWNER_PATTERN = /\A[\w.-]+\/[\w.-]+\z/i + NAME_WITH_OWNER_PATTERN = %r{\A[\w.-]+/[\w.-]+\z}i.freeze # Instantiate from a GitHub repository URL # # @return [Repository] def self.from_url(url) - new URI.parse(url).path[1..-1]. - gsub(/^repos\//,''). - split('/', 3)[0..1]. - join('/') + new URI.parse(url).path[1..-1] + .gsub(%r{^repos/}, '') + .split('/', 3)[0..1] + .join('/') end # @raise [Octokit::InvalidRepository] if the repository @@ -23,7 +24,7 @@ def initialize(repo) when Integer @id = repo when NAME_WITH_OWNER_PATTERN - @owner, @name = repo.split("/") + @owner, @name = repo.split('/') when Repository @owner = repo.owner @name = repo.name @@ -33,9 +34,7 @@ def initialize(repo) else raise_invalid_repository!(repo) end - if @owner && @name - validate_owner_and_name!(repo) - end + validate_owner_and_name!(repo) if @owner && @name end # Repository owner/name @@ -43,7 +42,7 @@ def initialize(repo) def slug "#{@owner}/#{@name}" end - alias :to_s :slug + alias to_s slug # @return [String] Repository API path def path @@ -54,7 +53,7 @@ def path # Get the api path for a repo # @param repo [Integer, String, Hash, Repository] A GitHub repository. # @return [String] Api path. - def self.path repo + def self.path(repo) new(repo).path end @@ -74,22 +73,22 @@ def url "#{Octokit.web_endpoint}#{slug}" end - alias :user :owner - alias :username :owner - alias :repo :name + alias user owner + alias username owner + alias repo name private - def validate_owner_and_name!(repo) - if @owner.include?('/') || @name.include?('/') || !url.match(URI::ABS_URI) - raise_invalid_repository!(repo) - end + def validate_owner_and_name!(repo) + if @owner.include?('/') || @name.include?('/') || !url.match(URI::ABS_URI) + raise_invalid_repository!(repo) end + end - def raise_invalid_repository!(repo) - msg = "#{repo.inspect} is invalid as a repository identifier. " + - "Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." - raise Octokit::InvalidRepository, msg - end + def raise_invalid_repository!(repo) + msg = "#{repo.inspect} is invalid as a repository identifier. " \ + 'Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' + raise Octokit::InvalidRepository, msg + end end end diff --git a/lib/octokit/response/base_middleware.rb b/lib/octokit/response/base_middleware.rb index 42f6d7bab..ed971a205 100644 --- a/lib/octokit/response/base_middleware.rb +++ b/lib/octokit/response/base_middleware.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'faraday' module Octokit diff --git a/lib/octokit/response/feed_parser.rb b/lib/octokit/response/feed_parser.rb index 06247567c..3a73b0639 100644 --- a/lib/octokit/response/feed_parser.rb +++ b/lib/octokit/response/feed_parser.rb @@ -1,19 +1,17 @@ +# frozen_string_literal: true + require 'octokit/response/base_middleware' module Octokit - module Response - # Parses RSS and Atom feed responses. class FeedParser < BaseMiddleware - def on_complete(env) - if env[:response_headers]["content-type"] =~ /(\batom|\brss)/ + if env[:response_headers]['content-type'] =~ /(\batom|\brss)/ require 'rss' env[:body] = RSS::Parser.parse env[:body] end end - end end end diff --git a/lib/octokit/response/raise_error.rb b/lib/octokit/response/raise_error.rb index b025a142f..4b0fab0cb 100644 --- a/lib/octokit/response/raise_error.rb +++ b/lib/octokit/response/raise_error.rb @@ -1,14 +1,14 @@ +# frozen_string_literal: true + require 'octokit/response/base_middleware' require 'octokit/error' module Octokit # Faraday response middleware module Response - # This class raises an Octokit-flavored exception based # HTTP status codes returned by the API class RaiseError < BaseMiddleware - def on_complete(response) if error = Octokit::Error.from_response(response) raise error diff --git a/lib/octokit/user.rb b/lib/octokit/user.rb index d8f83f3ca..1adf3d083 100644 --- a/lib/octokit/user.rb +++ b/lib/octokit/user.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Octokit # GitHub user class to generate API path urls class User @@ -5,14 +7,14 @@ class User # # @param user [String, Integer] GitHub user login or id # @return [String] User Api path - def self.path user + def self.path(user) case user when String "users/#{user}" when Integer "user/#{user}" else - "user" + 'user' end end end diff --git a/lib/octokit/version.rb b/lib/octokit/version.rb index 06ceeb482..a5feaf218 100644 --- a/lib/octokit/version.rb +++ b/lib/octokit/version.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module Octokit # Current major release. # @return [Integer] diff --git a/lib/octokit/warnable.rb b/lib/octokit/warnable.rb index 3afd66df8..63551f641 100644 --- a/lib/octokit/warnable.rb +++ b/lib/octokit/warnable.rb @@ -1,8 +1,8 @@ -module Octokit +# frozen_string_literal: true +module Octokit # Allows warnings to be suppressed via environment variable. module Warnable - module_function # Wrapper around Kernel#warn to print warnings unless @@ -10,10 +10,7 @@ module Warnable # # @return [nil] def octokit_warn(*message) - unless ENV['OCTOKIT_SILENT'] - warn message - end + warn message unless ENV['OCTOKIT_SILENT'] end end end - diff --git a/octokit.gemspec b/octokit.gemspec index d12fe9d09..b30aadfc1 100644 --- a/octokit.gemspec +++ b/octokit.gemspec @@ -1,23 +1,24 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'octokit/version' Gem::Specification.new do |spec| spec.add_development_dependency 'bundler', '>= 1', '< 3' - spec.add_dependency 'sawyer', '~> 0.9' spec.add_dependency 'faraday', '>= 1', '< 3' - spec.authors = ["Wynn Netherland", "Erik Michaels-Ober", "Clint Shryock"] - spec.description = %q{Simple wrapper for the GitHub API} + spec.add_dependency 'sawyer', '~> 0.9' + spec.authors = ['Wynn Netherland', 'Erik Michaels-Ober', 'Clint Shryock'] + spec.description = 'Simple wrapper for the GitHub API' spec.email = ['wynn.netherland@gmail.com', 'sferik@gmail.com', 'clint@ctshryock.com'] - spec.files = %w(.document CONTRIBUTING.md LICENSE.md README.md Rakefile octokit.gemspec) - spec.files += Dir.glob("lib/**/*.rb") + spec.files = %w[.document CONTRIBUTING.md LICENSE.md README.md Rakefile octokit.gemspec] + spec.files += Dir.glob('lib/**/*.rb') spec.homepage = 'https://github.com/octokit/octokit.rb' spec.licenses = ['MIT'] spec.name = 'octokit' spec.require_paths = ['lib'] spec.required_ruby_version = '>= 2.0.0' spec.required_rubygems_version = '>= 1.3.5' - spec.summary = "Ruby toolkit for working with the GitHub API" + spec.summary = 'Ruby toolkit for working with the GitHub API' spec.version = Octokit::VERSION.dup end diff --git a/spec/helper.rb b/spec/helper.rb index c41399e8f..52333bf2d 100644 --- a/spec/helper.rb +++ b/spec/helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + if RUBY_ENGINE == 'ruby' require 'simplecov' SimpleCov.start @@ -13,9 +15,11 @@ if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('3.2.0') require 'pry-byebug' end -require 'faraday/multipart' if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0') +if Gem::Version.new(Faraday::VERSION) >= Gem::Version.new('2.0') + require 'faraday/multipart' +end -WebMock.disable_net_connect!() +WebMock.disable_net_connect! RSpec.configure do |config| config.raise_errors_for_deprecations! @@ -29,69 +33,69 @@ require 'vcr' VCR.configure do |c| c.configure_rspec_metadata! - c.filter_sensitive_data("") do + c.filter_sensitive_data('') do test_github_login end - c.filter_sensitive_data("") do + c.filter_sensitive_data('') do test_github_collaborator_login end - c.filter_sensitive_data("") do + c.filter_sensitive_data('') do test_github_team_slug end - c.filter_sensitive_data("") do + c.filter_sensitive_data('') do test_github_team_id end - c.filter_sensitive_data("") do + c.filter_sensitive_data('') do test_github_password end - c.filter_sensitive_data("<>") do + c.filter_sensitive_data('<>') do test_github_token end - c.filter_sensitive_data("") do + c.filter_sensitive_data('') do test_github_collaborator_token end - c.filter_sensitive_data("") do + c.filter_sensitive_data('') do test_github_client_id end - c.filter_sensitive_data("") do + c.filter_sensitive_data('') do test_github_client_secret end - c.filter_sensitive_data("<>") do + c.filter_sensitive_data('<>') do test_github_enterprise_login end - c.filter_sensitive_data("<>") do + c.filter_sensitive_data('<>') do test_github_enterprise_token end - c.filter_sensitive_data("<>") do + c.filter_sensitive_data('<>') do test_github_enterprise_management_console_password end - c.filter_sensitive_data("<>") do + c.filter_sensitive_data('<>') do test_github_enterprise_management_console_endpoint end - c.filter_sensitive_data("<>") do + c.filter_sensitive_data('<>') do test_github_enterprise_endpoint end - c.define_cassette_placeholder("") do + c.define_cassette_placeholder('') do test_github_repository end - c.define_cassette_placeholder("") do + c.define_cassette_placeholder('') do test_github_repository_id end - c.define_cassette_placeholder("") do + c.define_cassette_placeholder('') do test_github_org end - c.define_cassette_placeholder("") do - "10050505050000" + c.define_cassette_placeholder('') do + '10050505050000' end - c.define_cassette_placeholder("") do + c.define_cassette_placeholder('') do test_github_integration end - c.define_cassette_placeholder("") do + c.define_cassette_placeholder('') do test_github_integration_installation end # This MUST belong to the app used for test_github_client_id and # test_github_client_secret - c.define_cassette_placeholder("") do + c.define_cassette_placeholder('') do test_github_oauth_token end @@ -100,18 +104,18 @@ next unless request.uri.include? test_github_repository options = { - :headers => {'X-Vcr-Test-Repo-Setup' => 'true'}, - :auto_init => true + headers: { 'X-Vcr-Test-Repo-Setup' => 'true' }, + auto_init: true } test_repo = "#{test_github_login}/#{test_github_repository}" - if !oauth_client.repository?(test_repo, options) + unless oauth_client.repository?(test_repo, options) Octokit.octokit_warn "NOTICE: Creating #{test_repo} test repository." oauth_client.create_repository(test_github_repository, options) end test_org_repo = "#{test_github_org}/#{test_github_repository}" - if !oauth_client.repository?(test_org_repo, options) + unless oauth_client.repository?(test_org_repo, options) Octokit.octokit_warn "NOTICE: Creating #{test_org_repo} test repository." options[:organization] = test_github_org oauth_client.create_repository(test_github_repository, options) @@ -123,31 +127,28 @@ end record_mode = - case - when ENV['GITHUB_CI'] + if ENV['GITHUB_CI'] :none - when ENV['OCTOKIT_TEST_VCR_RECORD'] + elsif ENV['OCTOKIT_TEST_VCR_RECORD'] :all else :once end c.default_cassette_options = { - :serialize_with => :json, + serialize_with: :json, # TODO: Track down UTF-8 issue and remove - :preserve_exact_body_bytes => true, - :decode_compressed_response => true, - :record => record_mode + preserve_exact_body_bytes: true, + decode_compressed_response: true, + record: record_mode } c.cassette_library_dir = 'spec/cassettes' c.hook_into :webmock end def delete_test_repo - begin - oauth_client.delete_repository @test_repo - rescue Octokit::NotFound - end + oauth_client.delete_repository @test_repo +rescue Octokit::NotFound end def test_github_login @@ -163,7 +164,7 @@ def test_github_team_slug end def test_github_team_id - ENV.fetch 'OCTOKIT_TEST_GITHUB_TEAM_ID', 123456 + ENV.fetch 'OCTOKIT_TEST_GITHUB_TEAM_ID', 123_456 end def test_github_password @@ -259,7 +260,7 @@ def stub_put(url) end def fixture_path - File.expand_path("../fixtures", __FILE__) + File.expand_path('fixtures', __dir__) end def fixture(file) @@ -268,9 +269,9 @@ def fixture(file) def json_response(file) { - :body => fixture(file), - :headers => { - :content_type => 'application/json; charset=utf-8' + body: fixture(file), + headers: { + content_type: 'application/json; charset=utf-8' } } end @@ -280,7 +281,7 @@ def github_url(url) url = File.join(Octokit.api_endpoint, url) uri = Addressable::URI.parse(url) - uri.path.gsub!("v3//", "v3/") + uri.path.gsub!('v3//', 'v3/') uri.to_s end @@ -298,7 +299,7 @@ def basic_auth_client(login: test_github_login, password: test_github_password) end def oauth_client - Octokit::Client.new(:access_token => test_github_token) + Octokit::Client.new(access_token: test_github_token) end def enterprise_admin_client @@ -309,8 +310,8 @@ def enterprise_admin_client end client = Octokit::EnterpriseAdminClient.new \ - :access_token => test_github_enterprise_token, - :connection_options => { :ssl => { :verify => false } } + access_token: test_github_enterprise_token, + connection_options: { ssl: { verify: false } } client.configure do |c| c.api_endpoint = test_github_enterprise_endpoint @@ -327,9 +328,9 @@ def enterprise_management_console_client end client = Octokit::EnterpriseManagementConsoleClient.new \ - :management_console_endpoint => test_github_enterprise_management_console_endpoint, - :management_console_password => test_github_enterprise_management_console_password, - :connection_options => { :ssl => { :verify => false } } + management_console_endpoint: test_github_enterprise_management_console_endpoint, + management_console_password: test_github_enterprise_management_console_password, + connection_options: { ssl: { verify: false } } client.configure do |c| c.middleware = stack diff --git a/spec/octokit/client/actions_secrets_spec.rb b/spec/octokit/client/actions_secrets_spec.rb index 1520393c3..eaa24c1e7 100644 --- a/spec/octokit/client/actions_secrets_spec.rb +++ b/spec/octokit/client/actions_secrets_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'rbnacl' require 'base64' @@ -11,16 +13,15 @@ def create_box(public_key) end describe Octokit::Client::ActionsSecrets do - before do Octokit.reset! @client = oauth_client - @secret = {name: "secret_name", value: "secret_value"} + @secret = { name: 'secret_name', value: 'secret_value' } end - context "with a repo" do + context 'with a repo' do before(:each) do - @repo = @client.create_repository("secret-repo") + @repo = @client.create_repository('secret-repo') end after(:each) do @@ -30,17 +31,17 @@ def create_box(public_key) end end - describe ".get_public_key", :vcr do - it "get repo specific public key for secrets encryption" do + describe '.get_public_key', :vcr do + it 'get repo specific public key for secrets encryption' do box = create_box(@client.get_public_key(@repo.id)) expect(box[:key_id]).not_to be_empty end end # .get_public_key end - context "with a repo without secrets" do + context 'with a repo without secrets' do before(:each) do - @repo = @client.create_repository("secret-repo") + @repo = @client.create_repository('secret-repo') end after(:each) do @@ -50,16 +51,16 @@ def create_box(public_key) end end - describe ".list_secrets", :vcr do - it "returns empty list of secrets" do + describe '.list_secrets', :vcr do + it 'returns empty list of secrets' do secrets = @client.list_secrets(@repo.id) expect(secrets.total_count).to eq(0) expect(secrets.secrets).to be_empty end end # .list_secrets - describe ".create_or_update_secret", :vcr do - it "creating secret returns 204 (even though API docs claims it should be 201)" do + describe '.create_or_update_secret', :vcr do + it 'creating secret returns 204 (even though API docs claims it should be 201)' do box = create_box(@client.get_public_key(@repo.id)) encrypted = box[:box].encrypt(@secret[:value]) resp = @client.create_or_update_secret( @@ -71,10 +72,9 @@ def create_box(public_key) end # .create_or_update_secret end - - context "with a repository with a secret" do + context 'with a repository with a secret' do before(:each) do - @repo = @client.create_repository("secret-repo") + @repo = @client.create_repository('secret-repo') @box = create_box(@client.get_public_key(@repo.id)) encrypted = @box[:box].encrypt(@secret[:value]) @client.create_or_update_secret( @@ -90,25 +90,25 @@ def create_box(public_key) end end - describe ".list_secrets", :vcr do - it "returns list of one secret" do + describe '.list_secrets', :vcr do + it 'returns list of one secret' do secrets = @client.list_secrets(@repo.id) expect(secrets.total_count).to eq(1) expect(secrets.secrets[0].name).to eq(@secret[:name]) - end + end end # .list_secrets - describe ".get_secret", :vcr do - it "return timestamps related to one secret" do + describe '.get_secret', :vcr do + it 'return timestamps related to one secret' do received = @client.get_secret(@repo.id, @secret[:name]) expect(received.name).to eq(@secret[:name]) end end # .get_secret - describe ".create_or_update_secret", :vcr do - it "updating existing secret returns 204" do + describe '.create_or_update_secret', :vcr do + it 'updating existing secret returns 204' do box = create_box(@client.get_public_key(@repo.id)) - encrypted = box[:box].encrypt("new value") + encrypted = box[:box].encrypt('new value') resp = @client.create_or_update_secret( @repo.id, @secret[:name], key_id: box[:key_id], encrypted_value: Base64.strict_encode64(encrypted) @@ -117,8 +117,8 @@ def create_box(public_key) end end # .create_or_update_secret - describe ".delete_secret", :vcr do - it "delete existing secret" do + describe '.delete_secret', :vcr do + it 'delete existing secret' do resp = @client.delete_secret(@repo.id, @secret[:name]) expect(@client.last_response.status).to eq(204) end diff --git a/spec/octokit/client/actions_workflow_runs_spec.rb b/spec/octokit/client/actions_workflow_runs_spec.rb index 09448724d..9aa292095 100644 --- a/spec/octokit/client/actions_workflow_runs_spec.rb +++ b/spec/octokit/client/actions_workflow_runs_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::ActionsWorkflowRuns, :vcr do before do Octokit.reset! @client = oauth_client - @run_id = 96922843 + @run_id = 96_922_843 end after do diff --git a/spec/octokit/client/actions_workflows_spec.rb b/spec/octokit/client/actions_workflows_spec.rb index 4839ba83c..bff053b0b 100644 --- a/spec/octokit/client/actions_workflows_spec.rb +++ b/spec/octokit/client/actions_workflows_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::ActionsWorkflows do @@ -16,7 +18,7 @@ describe '.workflow', :vcr do it 'returns the repository workflows' do - workflow_file_name = "simple_workflow.yml" + workflow_file_name = 'simple_workflow.yml' request = stub_get("/repos/#{@test_repo}/actions/workflows/#{workflow_file_name}") @client.workflow(@test_repo, workflow_file_name) @@ -25,9 +27,9 @@ end end # .workflow - describe ".workflow_dispatch", :vcr do - it "creates a workflow dispatch event" do - workflow_file_name = "simple_workflow.yml" + describe '.workflow_dispatch', :vcr do + it 'creates a workflow dispatch event' do + workflow_file_name = 'simple_workflow.yml' request = stub_post("/repos/#{@test_repo}/actions/workflows/#{workflow_file_name}/dispatches") @client.workflow_dispatch(@test_repo, workflow_file_name, 'main') diff --git a/spec/octokit/client/apps_spec.rb b/spec/octokit/client/apps_spec.rb index 615af41ab..31e5d1ba0 100644 --- a/spec/octokit/client/apps_spec.rb +++ b/spec/octokit/client/apps_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Apps do before(:each) do Octokit.reset! @client = oauth_client - @jwt_client = Octokit::Client.new(:bearer_token => new_jwt_token) + @jwt_client = Octokit::Client.new(bearer_token: new_jwt_token) use_vcr_placeholder_for(@jwt_client.bearer_token, '') end @@ -12,76 +14,76 @@ Octokit.reset! end - describe ".app", :vcr do - it "returns current App" do - response = @jwt_client.app() + describe '.app', :vcr do + it 'returns current App' do + response = @jwt_client.app expect(response.id).not_to be_nil - assert_requested :get, github_url("/app") + assert_requested :get, github_url('/app') end - it "works for GitHub Enterprise installs" do + it 'works for GitHub Enterprise installs' do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: "https://ghe.local/api/v3" + api_endpoint: 'https://ghe.local/api/v3' - request = stub_get("https://ghe.local/api/v3/app") - response = client.app() + request = stub_get('https://ghe.local/api/v3/app') + response = client.app assert_requested request end end - describe ".find_integration_installations", :vcr do - it "returns installations for an integration" do + describe '.find_integration_installations', :vcr do + it 'returns installations for an integration' do allow(@jwt_client).to receive(:octokit_warn) installations = @jwt_client.find_integration_installations expect(installations).to be_kind_of Array - assert_requested :get, github_url("/app/installations") + assert_requested :get, github_url('/app/installations') expect(@jwt_client).to have_received(:octokit_warn).with(/Deprecated/) end end # .find_integration_installations - describe ".find_app_installations", :vcr do - it "returns installations for an app" do - installations = @jwt_client.find_app_installations() + describe '.find_app_installations', :vcr do + it 'returns installations for an app' do + installations = @jwt_client.find_app_installations expect(installations).to be_kind_of Array - assert_requested :get, github_url("/app/installations") + assert_requested :get, github_url('/app/installations') end - it "works for GitHub Enterprise installs" do + it 'works for GitHub Enterprise installs' do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: "https://ghe.local/api/v3" + api_endpoint: 'https://ghe.local/api/v3' - request = stub_get("https://ghe.local/api/v3/app/installations") - response = client.find_app_installations() + request = stub_get('https://ghe.local/api/v3/app/installations') + response = client.find_app_installations assert_requested request end end # .find_app_installations - describe ".find_user_installations", :vcr do - it "returns installations for a user" do - response = @client.find_user_installations() + describe '.find_user_installations', :vcr do + it 'returns installations for a user' do + response = @client.find_user_installations expect(response.total_count).not_to be_nil expect(response.installations).to be_kind_of(Array) - assert_requested :get, github_url("/user/installations") + assert_requested :get, github_url('/user/installations') end - it "works for GitHub Enterprise installs" do + it 'works for GitHub Enterprise installs' do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: "https://ghe.local/api/v3" + api_endpoint: 'https://ghe.local/api/v3' - request = stub_get("https://ghe.local/api/v3/user/installations") - response = client.find_user_installations() + request = stub_get('https://ghe.local/api/v3/user/installations') + response = client.find_user_installations assert_requested request end - it "allows auto_pagination", :vcr do + it 'allows auto_pagination', :vcr do @client.auto_paginate = true response = @client.find_user_installations(per_page: 1) @@ -91,71 +93,70 @@ end end # .find_user_installations - describe ".find_organization_installation", :vcr do + describe '.find_organization_installation', :vcr do let(:organization) { test_github_org } - it "returns installation for an organization" do + it 'returns installation for an organization' do response = @jwt_client.find_organization_installation(organization) expect(response.id).not_to be_nil - expect(response.target_type).to eq("Organization") + expect(response.target_type).to eq('Organization') assert_requested :get, github_url("/orgs/#{organization}/installation") end - it "works for GitHub Enterprise installs" do + it 'works for GitHub Enterprise installs' do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: "https://ghe.local/api/v3" + api_endpoint: 'https://ghe.local/api/v3' - request = stub_get("https://ghe.local/api/v3/organizations/1234/installation") + request = stub_get('https://ghe.local/api/v3/organizations/1234/installation') response = client.find_organization_installation(1234) assert_requested request end - it "allows auto_pagination" do + it 'allows auto_pagination' do @jwt_client.auto_paginate = true response = @jwt_client.find_organization_installation(organization, per_page: 1) expect(response.id).not_to be_nil - expect(response.target_type).to eq("Organization") + expect(response.target_type).to eq('Organization') end end # .find_organization_installation - describe ".find_repository_installation", :vcr do - - it "returns installation for an repository" do + describe '.find_repository_installation', :vcr do + it 'returns installation for an repository' do response = @jwt_client.find_repository_installation(@test_org_repo) expect(response.id).not_to be_nil - expect(response.target_type).to eq("Organization") + expect(response.target_type).to eq('Organization') assert_requested :get, github_url("/repos/#{@test_org_repo}/installation") end - it "works for GitHub Enterprise installs" do + it 'works for GitHub Enterprise installs' do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: "https://ghe.local/api/v3" + api_endpoint: 'https://ghe.local/api/v3' - request = stub_get("https://ghe.local/api/v3/repos/testing/1234/installation") + request = stub_get('https://ghe.local/api/v3/repos/testing/1234/installation') response = client.find_repository_installation('testing/1234') assert_requested request end - it "allows auto_pagination" do + it 'allows auto_pagination' do @jwt_client.auto_paginate = true response = @jwt_client.find_repository_installation(@test_org_repo, per_page: 1) expect(response.id).not_to be_nil - expect(response.target_type).to eq("Organization") + expect(response.target_type).to eq('Organization') end end # .find_repository_installation - describe ".find_user_installation", :vcr do + describe '.find_user_installation', :vcr do let(:user) { test_github_login } - it "returns installation for a user" do + it 'returns installation for a user' do response = @jwt_client.find_user_installation(user) expect(response.id).not_to be_nil @@ -163,18 +164,18 @@ assert_requested :get, github_url("/users/#{user}/installation") end - it "works for GitHub Enterprise installs" do + it 'works for GitHub Enterprise installs' do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: "https://ghe.local/api/v3" + api_endpoint: 'https://ghe.local/api/v3' - request = stub_get("https://ghe.local/api/v3/users/1234/installation") + request = stub_get('https://ghe.local/api/v3/users/1234/installation') response = client.find_user_installation('1234') assert_requested request end - it "allows auto_pagination" do + it 'allows auto_pagination' do @jwt_client.auto_paginate = true response = @jwt_client.find_user_installation(user, per_page: 1) @@ -183,48 +184,48 @@ end end # .find_user_installation - context "with app installation", :vcr do + context 'with app installation', :vcr do let(:installation) { test_github_integration_installation } - describe ".installation" do - it "returns the installation" do + describe '.installation' do + it 'returns the installation' do response = @jwt_client.installation(installation) expect(response).to be_kind_of Sawyer::Resource assert_requested :get, github_url("/app/installations/#{installation}") end - it "works for GitHub Enterprise installs" do + it 'works for GitHub Enterprise installs' do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: "https://ghe.local/api/v3" + api_endpoint: 'https://ghe.local/api/v3' - request = stub_get("https://ghe.local/api/v3/app/installations/1234") + request = stub_get('https://ghe.local/api/v3/app/installations/1234') response = client.installation(1234) assert_requested request end end # .installation - describe ".find_installation_repositories_for_user" do - it "returns repositories for a user" do + describe '.find_installation_repositories_for_user' do + it 'returns repositories for a user' do response = @client.find_installation_repositories_for_user(installation) expect(response.total_count).not_to be_nil expect(response.repositories).to be_kind_of(Array) assert_requested :get, github_url("/user/installations/#{installation}/repositories") end - it "works for GitHub Enterprise installs" do + it 'works for GitHub Enterprise installs' do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: "https://ghe.local/api/v3" + api_endpoint: 'https://ghe.local/api/v3' - request = stub_get("https://ghe.local/api/v3/user/installations/1234/repositories") + request = stub_get('https://ghe.local/api/v3/user/installations/1234/repositories') response = client.find_installation_repositories_for_user(1234) assert_requested request end - it "allows auto_pagination", :vcr do + it 'allows auto_pagination', :vcr do @client.auto_paginate = true response = @client.find_installation_repositories_for_user(installation, per_page: 1) @@ -234,8 +235,8 @@ end end # .find_installation_repositories_for_user - describe ".create_integration_installation_access_token" do - it "creates an access token for the installation" do + describe '.create_integration_installation_access_token' do + it 'creates an access token for the installation' do allow(@jwt_client).to receive(:octokit_warn) response = @jwt_client.create_integration_installation_access_token(installation) @@ -248,8 +249,8 @@ end end # .create_integration_installation_access_token - describe ".create_app_installation_access_token" do - it "creates an access token for the installation" do + describe '.create_app_installation_access_token' do + it 'creates an access token for the installation' do response = @jwt_client.create_app_installation_access_token(installation) expect(response).to be_kind_of(Sawyer::Resource) @@ -259,12 +260,12 @@ assert_requested :post, github_url("/app/installations/#{installation}/access_tokens") end - it "works for GitHub Enterprise installs" do + it 'works for GitHub Enterprise installs' do client = Octokit::Client.new \ bearer_token: new_jwt_token, - api_endpoint: "https://ghe.local/api/v3" + api_endpoint: 'https://ghe.local/api/v3' - path = "app/installations/1234/access_tokens" + path = 'app/installations/1234/access_tokens' request = stub_post("https://ghe.local/api/v3/#{path}") response = client.create_app_installation_access_token(1234) @@ -272,51 +273,51 @@ end end # .create_app_installation_access_token - describe ".delete_installation" do - it "deletes an installation" do + describe '.delete_installation' do + it 'deletes an installation' do response = @jwt_client.delete_installation(installation) expect(response).to be_truthy end end # .delete_installation - context "with app installation access token" do + context 'with app installation access token' do let(:installation_client) do token = @jwt_client.create_app_installation_access_token(installation).token use_vcr_placeholder_for(token, '') - Octokit::Client.new(:access_token => token) + Octokit::Client.new(access_token: token) end let(:ghe_installation_client) do Octokit::Client.new \ - access_token: "v1.1f699f1069f60xxx", - api_endpoint: "https://ghe.local/api/v3" + access_token: 'v1.1f699f1069f60xxx', + api_endpoint: 'https://ghe.local/api/v3' end - describe ".list_integration_installation_repositories" do - it "lists the installations repositories" do + describe '.list_integration_installation_repositories' do + it 'lists the installations repositories' do allow(installation_client).to receive(:octokit_warn) - response = installation_client.list_integration_installation_repositories() + response = installation_client.list_integration_installation_repositories expect(response.total_count).not_to be_nil expect(response.repositories).to be_kind_of(Array) expect(installation_client).to have_received(:octokit_warn).with(/Deprecated/) end end # .list_integration_installation_repositories - describe ".list_app_installation_repositories" do - it "lists the installations repositories" do - response = installation_client.list_app_installation_repositories() + describe '.list_app_installation_repositories' do + it 'lists the installations repositories' do + response = installation_client.list_app_installation_repositories expect(response.total_count).not_to be_nil expect(response.repositories).to be_kind_of(Array) end - it "works for GitHub Enterprise installs" do - request = stub_get("https://ghe.local/api/v3/installation/repositories") - response = ghe_installation_client.list_app_installation_repositories() + it 'works for GitHub Enterprise installs' do + request = stub_get('https://ghe.local/api/v3/installation/repositories') + response = ghe_installation_client.list_app_installation_repositories assert_requested request end - it "allows auto_pagination", :vcr do + it 'allows auto_pagination', :vcr do installation_client.auto_paginate = true - response = installation_client.list_app_installation_repositories({per_page: 1}) + response = installation_client.list_app_installation_repositories({ per_page: 1 }) expect(response.total_count).to eq 2 expect(response.repositories.count).to eq 2 @@ -325,13 +326,13 @@ end # .list_app_installation_repositories end # with app installation access token - context "with repository" do + context 'with repository' do let(:repository) { test_org_repo } before(:each) do @repo = @client.create_repository( "#{test_github_repository}_#{Time.now.to_f}", - :organization => test_github_org + organization: test_github_org ) end @@ -339,8 +340,8 @@ @client.delete_repository(@repo.full_name) end - describe ".add_repository_to_integration_installation" do - it "adds the repository to the installation" do + describe '.add_repository_to_integration_installation' do + it 'adds the repository to the installation' do allow(@client).to receive(:octokit_warn) response = @client.add_repository_to_integration_installation(installation, @repo.id) expect(response).to be_truthy @@ -348,8 +349,8 @@ end end # .add_repository_to_integration_installation - describe ".add_repository_to_app_installation" do - it "adds the repository to the installation" do + describe '.add_repository_to_app_installation' do + it 'adds the repository to the installation' do response = @client.add_repository_to_app_installation(installation, @repo.id) expect(response).to be_truthy end @@ -360,8 +361,8 @@ @client.add_repository_to_app_installation(installation, @repo.id) end - describe ".remove_repository_from_integration_installation" do - it "removes the repository from the installation" do + describe '.remove_repository_from_integration_installation' do + it 'removes the repository from the installation' do allow(@client).to receive(:octokit_warn) response = @client.remove_repository_from_integration_installation(installation, @repo.id) expect(response).to be_truthy @@ -369,8 +370,8 @@ end end # .remove_repository_from_integration_installation - describe ".remove_repository_from_app_installation" do - it "removes the repository from the installation" do + describe '.remove_repository_from_app_installation' do + it 'removes the repository from the installation' do response = @client.remove_repository_from_app_installation(installation, @repo.id) expect(response).to be_truthy end @@ -378,24 +379,24 @@ end # with installed repository on installation end # with repository - context "with repository on GitHub Enterprise" do + context 'with repository on GitHub Enterprise' do let(:ghe_client) do Octokit::Client.new \ - access_token: "x" * 40, - api_endpoint: "https://ghe.local/api/v3" + access_token: 'x' * 40, + api_endpoint: 'https://ghe.local/api/v3' end - describe ".add_repository_to_app_installation" do - it "works for GitHub Enterprise installs" do - request = stub_put("https://ghe.local/api/v3/user/installations/1234/repositories/1234") + describe '.add_repository_to_app_installation' do + it 'works for GitHub Enterprise installs' do + request = stub_put('https://ghe.local/api/v3/user/installations/1234/repositories/1234') response = ghe_client.add_repository_to_app_installation(1234, 1234) assert_requested request end end # .add_repository_to_app_installation - describe ".remove_repository_from_app_installation" do - it "works for GitHub Enterprise installs" do - request = stub_delete("https://ghe.local/api/v3/user/installations/1234/repositories/1234") + describe '.remove_repository_from_app_installation' do + it 'works for GitHub Enterprise installs' do + request = stub_delete('https://ghe.local/api/v3/user/installations/1234/repositories/1234') response = ghe_client.remove_repository_from_app_installation(1234, 1234) assert_requested request end diff --git a/spec/octokit/client/authorizations_spec.rb b/spec/octokit/client/authorizations_spec.rb index a4bddc591..24805c0d7 100644 --- a/spec/octokit/client/authorizations_spec.rb +++ b/spec/octokit/client/authorizations_spec.rb @@ -1,15 +1,16 @@ +# frozen_string_literal: true + require 'helper' require 'securerandom' describe Octokit::Client::Authorizations do - before do Octokit.reset! @client = basic_auth_client @app_client = Octokit::Client.new \ - :client_id => test_github_client_id, - :client_secret => test_github_client_secret + client_id: test_github_client_id, + client_secret: test_github_client_secret end after do @@ -20,12 +21,12 @@ def note "Note #{SecureRandom.hex(20)}" end - describe ".create_authorization", :vcr do + describe '.create_authorization', :vcr do context 'without :idempotent => true' do - it "creates an API authorization" do + it 'creates an API authorization' do authorization = @client.create_authorization(note: note) expect(authorization.app.name).not_to be_nil - expect(WebMock).to have_requested(:post, github_url("/authorizations")).with( + expect(WebMock).to have_requested(:post, github_url('/authorizations')).with( basic_auth: [ test_github_login, test_github_password @@ -33,20 +34,20 @@ def note ) end - it "creates a new API authorization each time" do + it 'creates a new API authorization each time' do first_authorization = @client.create_authorization(note: note) second_authorization = @client.create_authorization(note: note) expect(first_authorization.id).not_to eq(second_authorization.id) end - it "creates a new authorization with options" do + it 'creates a new authorization with options' do info = { - note: note, - scope: ["gist"], + note: note, + scope: ['gist'] } authorization = @client.create_authorization info expect(authorization.scopes).to be_kind_of Array - expect(WebMock).to have_requested(:post, github_url("/authorizations")).with( + expect(WebMock).to have_requested(:post, github_url('/authorizations')).with( basic_auth: [ test_github_login, test_github_password @@ -56,12 +57,12 @@ def note end context 'with :idempotent => true' do - it "creates a new authorization with options" do + it 'creates a new authorization with options' do authorization = @client.create_authorization( - idempotent: true, - client_id: test_github_client_id, + idempotent: true, + client_id: test_github_client_id, client_secret: test_github_client_secret, - scopes: %w(gist) + scopes: %w[gist] ) expect(authorization.scopes).to be_kind_of Array @@ -73,15 +74,15 @@ def note ) end - it "creates a new authorization with fingerprint" do + it 'creates a new authorization with fingerprint' do path = "/authorizations/clients/#{test_github_client_id}/jklmnop12345678" @client.create_authorization( - idempotent: true, - client_id: test_github_client_id, + idempotent: true, + client_id: test_github_client_id, client_secret: test_github_client_secret, - scopes: %w(gist), - fingerprint: "jklmnop12345678" + scopes: %w[gist], + fingerprint: 'jklmnop12345678' ) expect(WebMock).to have_requested(:put, github_url(path)).with( @@ -94,8 +95,8 @@ def note it 'returns an existing API authorization if one already exists' do options = { - idempotent: true, - client_id: test_github_client_id, + idempotent: true, + client_id: test_github_client_id, client_secret: test_github_client_secret } @@ -107,11 +108,11 @@ def note end end # .create_authorization - describe ".authorizations", :vcr do - it "lists existing authorizations" do + describe '.authorizations', :vcr do + it 'lists existing authorizations' do authorizations = @client.authorizations expect(authorizations).to be_kind_of Array - expect(WebMock).to have_requested(:get, github_url("/authorizations")).with( + expect(WebMock).to have_requested(:get, github_url('/authorizations')).with( basic_auth: [ test_github_login, test_github_password @@ -120,8 +121,8 @@ def note end end # .authorizations - describe ".authorization", :vcr do - it "returns a single authorization" do + describe '.authorization', :vcr do + it 'returns a single authorization' do authorization = @client.create_authorization(note: note) @client.authorization(authorization['id']) @@ -134,8 +135,8 @@ def note end end # .authorization - describe ".update_authorization", :vcr do - it "updates and existing authorization" do + describe '.update_authorization', :vcr do + it 'updates and existing authorization' do authorization = @client.create_authorization(note: note) updated = @client.update_authorization(authorization.id, add_scopes: ['repo:status']) @@ -149,30 +150,30 @@ def note end end # .update_authorization - describe ".scopes", :vcr do - it "checks the scopes on the current token" do + describe '.scopes', :vcr do + it 'checks the scopes on the current token' do authorization = @client.create_authorization(note: note) - use_vcr_placeholder_for(authorization.token, "SCOPE_AUTHORIZATION_TOKEN") + use_vcr_placeholder_for(authorization.token, 'SCOPE_AUTHORIZATION_TOKEN') token_client = Octokit::Client.new(access_token: authorization.token) expect(token_client.scopes).to be_kind_of Array - assert_requested :get, github_url("/user") + assert_requested :get, github_url('/user') end - it "checks the scopes on a one-off token" do + it 'checks the scopes on a one-off token' do authorization = @client.create_authorization(note: note) - use_vcr_placeholder_for(authorization.token, "ONE_OFF_SCOPE_AUTHORIZATION_TOKEN") + use_vcr_placeholder_for(authorization.token, 'ONE_OFF_SCOPE_AUTHORIZATION_TOKEN') Octokit.reset! expect(Octokit.scopes(authorization.token)).to be_kind_of Array - assert_requested :get, github_url("/user") + assert_requested :get, github_url('/user') end end # .scopes - describe ".delete_authorization", :vcr do - it "deletes an existing authorization" do + describe '.delete_authorization', :vcr do + it 'deletes an existing authorization' do authorization = @client.create_authorization(note: note) result = @client.delete_authorization(authorization.id) @@ -186,9 +187,9 @@ def note end end # .delete_authorization - describe ".authorize_url" do - context "with preconfigured client credentials" do - it "returns the authorize_url" do + describe '.authorize_url' do + context 'with preconfigured client credentials' do + it 'returns the authorize_url' do Octokit.configure do |c| c.client_id = 'id_here' c.client_secret = 'secret_here' @@ -199,24 +200,24 @@ def note end end - context "with passed client credentials" do - it "returns the authorize_url" do + context 'with passed client credentials' do + it 'returns the authorize_url' do url = Octokit.authorize_url('id_here') expect(url).to eq('https://github.com/login/oauth/authorize?client_id=id_here') end end - it "requires client_id and client_secret" do + it 'requires client_id and client_secret' do Octokit.reset! - expect { + expect do Octokit.authorize_url - }.to raise_error Octokit::ApplicationCredentialsRequired + end.to raise_error Octokit::ApplicationCredentialsRequired end - context "with passed options hash" do - it "appends options hash as query params" do + context 'with passed options hash' do + it 'appends options hash as query params' do url = Octokit.authorize_url('id_here', redirect_uri: 'git.io', scope: 'user') expect(url).to eq('https://github.com/login/oauth/authorize?client_id=id_here&redirect_uri=git.io&scope=user') end - it "escapes values before adding to query params" do + it 'escapes values before adding to query params' do uri = Octokit.authorize_url('id_here', redirect_uri: 'http://git.io') expect(uri).to eq('https://github.com/login/oauth/authorize?client_id=id_here&redirect_uri=http%3A%2F%2Fgit.io') scope = Octokit.authorize_url('id_here', scope: 'repo:status') @@ -225,12 +226,12 @@ def note end end # .authorize_url - describe ".revoke_all_application_authorizations" do + describe '.revoke_all_application_authorizations' do before do allow(@app_client).to receive(:octokit_warn) end - it "returns false" do + it 'returns false' do path = "/applications/#{test_github_client_id}/tokens" stub_request(:delete, github_url(path)).with( diff --git a/spec/octokit/client/checks_spec.rb b/spec/octokit/client/checks_spec.rb index 28ca657f2..b42d528a4 100644 --- a/spec/octokit/client/checks_spec.rb +++ b/spec/octokit/client/checks_spec.rb @@ -1,99 +1,101 @@ -require "helper" +# frozen_string_literal: true + +require 'helper' describe Octokit::Client::Checks, :vcr do before do Octokit.reset! @client = oauth_client - @path = "README.md" - @commit = "e1db7418a77db065d1900e579c82ef0aad1da2b1" - @branch = "master" # Equivalent to @commit - @tag = "v1.0" # Equivalent to @commit - @check_suite_id = 50440400 - @check_name = "octokit-test-check" - @check_run_id = 51295429 + @path = 'README.md' + @commit = 'e1db7418a77db065d1900e579c82ef0aad1da2b1' + @branch = 'master' # Equivalent to @commit + @tag = 'v1.0' # Equivalent to @commit + @check_suite_id = 50_440_400 + @check_name = 'octokit-test-check' + @check_run_id = 51_295_429 end - describe ".create_check_run" do - it "creates a check run" do + describe '.create_check_run' do + it 'creates a check run' do @client.create_check_run( @test_repo, @check_name, - @commit, + @commit ) - assert_requested :post, repo_url("check-runs") + assert_requested :post, repo_url('check-runs') end - it "returns the check run" do + it 'returns the check run' do check_run = @client.create_check_run( @test_repo, @check_name, - @commit, + @commit ) expect(check_run.name).to eq(@check_name) expect(check_run.head_sha).to eq(@commit) - expect(check_run.status).to eq("queued") + expect(check_run.status).to eq('queued') end end - describe ".update_check_run" do - it "updates the check run" do + describe '.update_check_run' do + it 'updates the check run' do @client.update_check_run( @test_repo, @check_run_id, - completed_at: "2019-01-17T14:52:51Z", - conclusion: "success", + completed_at: '2019-01-17T14:52:51Z', + conclusion: 'success', output: { annotations: [ { - annotation_level: "notice", + annotation_level: 'notice', end_line: 1, - message: "Looks good!", + message: 'Looks good!', path: @path, - start_line: 1, - }, + start_line: 1 + } ], - summary: "Everything checks out.", - title: "Octokit Check", - }, + summary: 'Everything checks out.', + title: 'Octokit Check' + } ) assert_requested :patch, repo_url("check-runs/#{@check_run_id}") end - it "returns the check run" do + it 'returns the check run' do check_run = @client.update_check_run( @test_repo, @check_run_id, - completed_at: "2019-01-17T14:52:51Z", - conclusion: "success", + completed_at: '2019-01-17T14:52:51Z', + conclusion: 'success', output: { annotations: [ { - annotation_level: "notice", + annotation_level: 'notice', end_line: 1, - message: "Looks good!", + message: 'Looks good!', path: @path, - start_line: 1, - }, + start_line: 1 + } ], - summary: "Everything checks out.", - title: "Octokit Check", - }, + summary: 'Everything checks out.', + title: 'Octokit Check' + } ) expect(check_run.id).to eq(@check_run_id) - expect(check_run.status).to eq("completed") + expect(check_run.status).to eq('completed') end end - describe ".check_runs_for_ref" do - it "returns check runs for a commit" do + describe '.check_runs_for_ref' do + it 'returns check runs for a commit' do result = @client.check_runs_for_ref( @test_repo, - @commit, + @commit ) expect(result.total_count).to eq(1) @@ -102,10 +104,10 @@ expect(result.check_runs[0].id).to eq(@check_run_id) end - it "returns check runs for a branch" do + it 'returns check runs for a branch' do result = @client.check_runs_for_ref( @test_repo, - @branch, + @branch ) expect(result.total_count).to eq(1) @@ -114,10 +116,10 @@ expect(result.check_runs[0].id).to eq(@check_run_id) end - it "returns check runs for a tag" do + it 'returns check runs for a tag' do result = @client.check_runs_for_ref( @test_repo, - @tag, + @tag ) expect(result.total_count).to eq(1) @@ -126,11 +128,11 @@ expect(result.check_runs[0].id).to eq(@check_run_id) end - it "filters by status" do + it 'filters by status' do result = @client.check_runs_for_ref( @test_repo, @commit, - status: "completed", + status: 'completed' ) expect(result.total_count).to eq(0) @@ -140,7 +142,7 @@ result = @client.check_runs_for_ref( @test_repo, @commit, - status: "queued", + status: 'queued' ) expect(result.total_count).to eq(1) @@ -149,12 +151,12 @@ expect(result.check_runs[0].id).to eq(@check_run_id) end - it "paginates the results" do + it 'paginates the results' do @client.per_page = 1 allow(@client).to receive(:paginate).and_call_original result = @client.check_runs_for_ref( @test_repo, - @commit, + @commit ) expect(@client).to have_received(:paginate) @@ -162,13 +164,13 @@ expect(result.check_runs.count).to eq(1) end - it "auto-paginates the results" do + it 'auto-paginates the results' do @client.auto_paginate = true @client.per_page = 1 allow(@client).to receive(:paginate).and_call_original result = @client.check_runs_for_ref( @test_repo, - @commit, + @commit ) expect(@client).to have_received(:paginate) @@ -177,12 +179,12 @@ end end - describe ".check_runs_for_check_suite" do - it "returns check runs for a check suite" do + describe '.check_runs_for_check_suite' do + it 'returns check runs for a check suite' do result = @client.check_runs_for_check_suite( @test_repo, - @check_suite_id, - ) + @check_suite_id + ) expect(result.total_count).to eq(1) expect(result.check_runs).to be_a(Array) @@ -190,11 +192,11 @@ expect(result.check_runs[0].id).to eq(@check_run_id) end - it "filters by status" do + it 'filters by status' do result = @client.check_runs_for_check_suite( @test_repo, @check_suite_id, - status: "completed", + status: 'completed' ) expect(result.total_count).to eq(0) @@ -204,7 +206,7 @@ result = @client.check_runs_for_check_suite( @test_repo, @check_suite_id, - status: "queued", + status: 'queued' ) expect(result.total_count).to eq(1) @@ -213,27 +215,27 @@ expect(result.check_runs[0].id).to eq(@check_run_id) end - it "paginates the results" do + it 'paginates the results' do @client.per_page = 1 allow(@client).to receive(:paginate).and_call_original result = @client.check_runs_for_check_suite( @test_repo, - @check_suite_id, - ) + @check_suite_id + ) expect(@client).to have_received(:paginate) expect(result.total_count).to eq(1) expect(result.check_runs.count).to eq(1) end - it "auto-paginates the results" do + it 'auto-paginates the results' do @client.auto_paginate = true @client.per_page = 1 allow(@client).to receive(:paginate).and_call_original result = @client.check_runs_for_check_suite( @test_repo, - @check_suite_id, - ) + @check_suite_id + ) expect(@client).to have_received(:paginate) expect(result.total_count).to eq(2) @@ -241,11 +243,11 @@ end end - describe ".check_run" do - it "returns the check run" do + describe '.check_run' do + it 'returns the check run' do check_run = @client.check_run( @test_repo, - @check_run_id, + @check_run_id ) expect(check_run.id).to eq(@check_run_id) @@ -254,11 +256,11 @@ end end - describe ".check_run_annotations" do - it "returns annotations for the check run" do + describe '.check_run_annotations' do + it 'returns annotations for the check run' do annotations = @client.check_run_annotations( @test_repo, - @check_run_id, + @check_run_id ) expect(annotations).to be_a(Array) @@ -266,12 +268,12 @@ expect(annotations[0].path).to eq(@path) end - it "paginates the results" do + it 'paginates the results' do @client.per_page = 1 allow(@client).to receive(:paginate).and_call_original annotations = @client.check_run_annotations( @test_repo, - @check_run_id, + @check_run_id ) expect(@client).to have_received(:paginate) @@ -279,13 +281,13 @@ expect(annotations.count).to eq(1) end - it "auto-paginates the results" do + it 'auto-paginates the results' do @client.auto_paginate = true @client.per_page = 1 allow(@client).to receive(:paginate).and_call_original annotations = @client.check_run_annotations( @test_repo, - @check_run_id, + @check_run_id ) expect(@client).to have_received(:paginate) @@ -294,11 +296,11 @@ end end - describe ".check_suite" do - it "returns the check suite" do + describe '.check_suite' do + it 'returns the check suite' do check_suite = @client.check_suite( @test_repo, - @check_suite_id, + @check_suite_id ) expect(check_suite.id).to eq(@check_suite_id) @@ -306,11 +308,11 @@ end end - describe ".check_suites_for_ref" do - it "returns check suites for a commit" do + describe '.check_suites_for_ref' do + it 'returns check suites for a commit' do result = @client.check_suites_for_ref( @test_repo, - @commit, + @commit ) expect(result.total_count).to eq(1) @@ -319,10 +321,10 @@ expect(result.check_suites[0].id).to eq(@check_suite_id) end - it "returns check suites for a branch" do + it 'returns check suites for a branch' do result = @client.check_suites_for_ref( @test_repo, - @branch, + @branch ) expect(result.total_count).to eq(1) @@ -331,10 +333,10 @@ expect(result.check_suites[0].id).to eq(@check_suite_id) end - it "returns check suites for a tag" do + it 'returns check suites for a tag' do result = @client.check_suites_for_ref( @test_repo, - @tag, + @tag ) expect(result.total_count).to eq(1) @@ -343,11 +345,11 @@ expect(result.check_suites[0].id).to eq(@check_suite_id) end - it "filters by check name" do + it 'filters by check name' do result = @client.check_suites_for_ref( @test_repo, @commit, - check_name: "bogus-check-name", + check_name: 'bogus-check-name' ) expect(result.total_count).to eq(0) @@ -357,7 +359,7 @@ result = @client.check_suites_for_ref( @test_repo, @commit, - check_name: @check_name, + check_name: @check_name ) expect(result.total_count).to eq(1) @@ -366,12 +368,12 @@ expect(result.check_suites[0].id).to eq(@check_suite_id) end - it "paginates the results" do + it 'paginates the results' do @client.per_page = 1 allow(@client).to receive(:paginate).and_call_original result = @client.check_suites_for_ref( @test_repo, - @commit, + @commit ) expect(@client).to have_received(:paginate) @@ -379,13 +381,13 @@ expect(result.check_suites.count).to eq(1) end - it "auto-paginates the results" do + it 'auto-paginates the results' do @client.auto_paginate = true @client.per_page = 1 allow(@client).to receive(:paginate).and_call_original result = @client.check_suites_for_ref( @test_repo, - @commit, + @commit ) expect(@client).to have_received(:paginate) @@ -394,48 +396,48 @@ end end - describe ".set_check_suite_preferences" do - it "sets check suite preferences" do + describe '.set_check_suite_preferences' do + it 'sets check suite preferences' do @client.set_check_suite_preferences( @test_repo, auto_trigger_checks: [ { app_id: test_github_integration, - setting: false, - }, - ], + setting: false + } + ] ) - assert_requested :patch, repo_url("check-suites/preferences") + assert_requested :patch, repo_url('check-suites/preferences') end end - describe ".create_check_suite" do - it "creates a check suite" do + describe '.create_check_suite' do + it 'creates a check suite' do @client.create_check_suite( @test_repo, - @commit, + @commit ) - assert_requested :post, repo_url("check-suites") + assert_requested :post, repo_url('check-suites') end - it "returns the check suite" do + it 'returns the check suite' do check_suite = @client.create_check_suite( @test_repo, - @commit, + @commit ) expect(check_suite.head_sha).to eq(@commit) - expect(check_suite.status).to eq("queued") + expect(check_suite.status).to eq('queued') end end - describe ".rerequest_check_suite" do - it "requests the check suite again" do + describe '.rerequest_check_suite' do + it 'requests the check suite again' do @client.rerequest_check_suite( @test_repo, - @check_suite_id, + @check_suite_id ) assert_requested :post, repo_url("check-suites/#{@check_suite_id}/rerequest") @@ -445,6 +447,6 @@ private def repo_url(repo_path) - github_url(["repos", @test_repo, repo_path].join("/")) + github_url(['repos', @test_repo, repo_path].join('/')) end end diff --git a/spec/octokit/client/commit_branches_spec.rb b/spec/octokit/client/commit_branches_spec.rb index 8fcd5ebf5..e09bf5688 100644 --- a/spec/octokit/client/commit_branches_spec.rb +++ b/spec/octokit/client/commit_branches_spec.rb @@ -1,21 +1,22 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::CommitBranches do - before do Octokit.reset! @client = Octokit::Client.new end - describe ".commit_branches", :vcr do - it "returns a list of all branches associated with a commit" do + describe '.commit_branches', :vcr do + it 'returns a list of all branches associated with a commit' do branches = @client.commit_branches( - "sferik/rails_admin", - "77571f28ef686e5b3fac853e5f29037ff4591a08", + 'sferik/rails_admin', + '77571f28ef686e5b3fac853e5f29037ff4591a08', accept: preview_header ) expect(branches.first.name).to eq('master') - assert_requested :get, github_url("/repos/sferik/rails_admin/commits/77571f28ef686e5b3fac853e5f29037ff4591a08/branches-where-head") + assert_requested :get, github_url('/repos/sferik/rails_admin/commits/77571f28ef686e5b3fac853e5f29037ff4591a08/branches-where-head') end end # .commit branches diff --git a/spec/octokit/client/commit_comments_spec.rb b/spec/octokit/client/commit_comments_spec.rb index 6699f9c0c..bfa50967a 100644 --- a/spec/octokit/client/commit_comments_spec.rb +++ b/spec/octokit/client/commit_comments_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::CommitComments do @@ -5,31 +7,31 @@ @client = oauth_client end - describe ".list_commit_comments", :vcr do - it "returns a list of all commit comments" do - commit_comments = @client.list_commit_comments("sferik/rails_admin") - expect(commit_comments.first.user.login).to eq("sferik") - assert_requested :get, github_url("/repos/sferik/rails_admin/comments") + describe '.list_commit_comments', :vcr do + it 'returns a list of all commit comments' do + commit_comments = @client.list_commit_comments('sferik/rails_admin') + expect(commit_comments.first.user.login).to eq('sferik') + assert_requested :get, github_url('/repos/sferik/rails_admin/comments') end end # .list_commit_comments - describe ".commit_comments", :vcr do - it "returns a list of comments for a specific commit" do - commit_comments = @client.commit_comments("sferik/rails_admin", "629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3") - expect(commit_comments.first.user.login).to eq("bbenezech") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits/629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3/comments") + describe '.commit_comments', :vcr do + it 'returns a list of comments for a specific commit' do + commit_comments = @client.commit_comments('sferik/rails_admin', '629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3') + expect(commit_comments.first.user.login).to eq('bbenezech') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits/629e9fd9d4df25528e84d31afdc8ebeb0f56fbb3/comments') end end # .commit_comments - describe ".commit_comment", :vcr do - it "returns a single commit comment" do - commit = @client.commit_comment("sferik/rails_admin", "861907") - expect(commit.user.login).to eq("bbenezech") - assert_requested :get, github_url("/repos/sferik/rails_admin/comments/861907") + describe '.commit_comment', :vcr do + it 'returns a single commit comment' do + commit = @client.commit_comment('sferik/rails_admin', '861907') + expect(commit.user.login).to eq('bbenezech') + assert_requested :get, github_url('/repos/sferik/rails_admin/comments/861907') end end # .commit_comment - context "with commit comment", :vcr do + context 'with commit comment', :vcr do before do @commit = @client.commits(@test_repo).last.rels[:self].get.data @commit_comment = @client.create_commit_comment \ @@ -42,23 +44,23 @@ @client.delete_commit_comment @test_repo, @commit_comment.id end - describe ".create_commit_comment" do - it "creates a commit comment" do + describe '.create_commit_comment' do + it 'creates a commit comment' do expect(@commit_comment.user.login).to eq(test_github_login) assert_requested :post, github_url("/repos/#{@test_repo}/commits/#{@commit.sha}/comments") end end # .create_commit_comment - describe ".update_commit_comment" do - it "updates a commit comment" do - updated_comment = @client.update_commit_comment(@test_repo, @commit_comment.id, ":penguin:") - expect(updated_comment.body).to eq(":penguin:") + describe '.update_commit_comment' do + it 'updates a commit comment' do + updated_comment = @client.update_commit_comment(@test_repo, @commit_comment.id, ':penguin:') + expect(updated_comment.body).to eq(':penguin:') assert_requested :patch, github_url("/repos/#{@test_repo}/comments/#{@commit_comment.id}") end end # .update_commit_comment - describe ".delete_commit_comment" do - it "deletes a commit comment" do + describe '.delete_commit_comment' do + it 'deletes a commit comment' do result = @client.delete_commit_comment(@test_repo, @commit_comment.id) expect(result).to be true assert_requested :delete, github_url("/repos/#{@test_repo}/comments/#{@commit_comment.id}") diff --git a/spec/octokit/client/commit_pulls_spec.rb b/spec/octokit/client/commit_pulls_spec.rb index 704df0e9d..e35e39cd0 100644 --- a/spec/octokit/client/commit_pulls_spec.rb +++ b/spec/octokit/client/commit_pulls_spec.rb @@ -1,21 +1,22 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::CommitPulls do - before do Octokit.reset! @client = Octokit::Client.new end - describe ".commit_pulls", :vcr do - it "returns a list of all pull requests associated with a commit" do + describe '.commit_pulls', :vcr do + it 'returns a list of all pull requests associated with a commit' do pulls = @client.commit_pulls( - "sferik/rails_admin", - "eddb53155d9bc4db70a0669627e3154e250b2b9a", + 'sferik/rails_admin', + 'eddb53155d9bc4db70a0669627e3154e250b2b9a', accept: preview_header ) expect(pulls.first.head.sha).not_to be_nil - assert_requested :get, github_url("/repos/sferik/rails_admin/commits/eddb53155d9bc4db70a0669627e3154e250b2b9a/pulls") + assert_requested :get, github_url('/repos/sferik/rails_admin/commits/eddb53155d9bc4db70a0669627e3154e250b2b9a/pulls') end end # .commit pulls diff --git a/spec/octokit/client/commits_spec.rb b/spec/octokit/client/commits_spec.rb index 0d4616720..22094eea4 100644 --- a/spec/octokit/client/commits_spec.rb +++ b/spec/octokit/client/commits_spec.rb @@ -1,156 +1,157 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Commits do - before do Octokit.reset! @client = oauth_client end - describe ".commits", :vcr do - it "returns all commits" do - commits = @client.commits("sferik/rails_admin") + describe '.commits', :vcr do + it 'returns all commits' do + commits = @client.commits('sferik/rails_admin') expect(commits.first.author).not_to be_nil - assert_requested :get, github_url("/repos/sferik/rails_admin/commits") + assert_requested :get, github_url('/repos/sferik/rails_admin/commits') end - it "handles branch or sha argument" do - @client.commits("sferik/rails_admin", "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master") + it 'handles branch or sha argument' do + @client.commits('sferik/rails_admin', 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master') end - it "handles the sha option" do - @client.commits("sferik/rails_admin", :sha => "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master") + it 'handles the sha option' do + @client.commits('sferik/rails_admin', sha: 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master') end end # .commits - describe ".commits_on", :vcr do - it "returns all commits on the specified date" do - commits = @client.commits_on("sferik/rails_admin", "2011-01-20") + describe '.commits_on', :vcr do + it 'returns all commits on the specified date' do + commits = @client.commits_on('sferik/rails_admin', '2011-01-20') expect(commits).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?since=2011-01-20T00:00:00%2B00:00&until=2011-01-21T00:00:00%2B00:00") + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?since=2011-01-20T00:00:00%2B00:00&until=2011-01-21T00:00:00%2B00:00') end - it "errors if the date is invalid" do - expect { @client.commits_on "sferik/rails_admin", "A pear" }.to raise_error ArgumentError + it 'errors if the date is invalid' do + expect { @client.commits_on 'sferik/rails_admin', 'A pear' }.to raise_error ArgumentError end - it "handles branch or sha argument" do - @client.commits_on("sferik/rails_admin", "2011-01-15", "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master&since=2011-01-15T00:00:00%2B00:00&until=2011-01-16T00:00:00%2B00:00") + it 'handles branch or sha argument' do + @client.commits_on('sferik/rails_admin', '2011-01-15', 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master&since=2011-01-15T00:00:00%2B00:00&until=2011-01-16T00:00:00%2B00:00') end - it "handles the sha option" do - @client.commits_on("sferik/rails_admin", "2011-01-15", :sha => "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master&since=2011-01-15T00:00:00%2B00:00&until=2011-01-16T00:00:00%2B00:00") + it 'handles the sha option' do + @client.commits_on('sferik/rails_admin', '2011-01-15', sha: 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master&since=2011-01-15T00:00:00%2B00:00&until=2011-01-16T00:00:00%2B00:00') end end # .commits_on - describe ".commits_since", :vcr do - it "returns all commits since the specified date" do - commits = @client.commits_since("sferik/rails_admin", "2011-01-20") + describe '.commits_since', :vcr do + it 'returns all commits since the specified date' do + commits = @client.commits_since('sferik/rails_admin', '2011-01-20') expect(commits).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?since=2011-01-20T00:00:00%2B00:00") + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?since=2011-01-20T00:00:00%2B00:00') end - it "errors if the date is invalid" do - expect { @client.commits_since "sferik/rails_admin", "A pear" }.to raise_error ArgumentError + it 'errors if the date is invalid' do + expect { @client.commits_since 'sferik/rails_admin', 'A pear' }.to raise_error ArgumentError end - it "handles branch or sha argument" do - @client.commits_since("sferik/rails_admin", "2011-01-15", "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master&since=2011-01-15T00:00:00%2B00:00") + it 'handles branch or sha argument' do + @client.commits_since('sferik/rails_admin', '2011-01-15', 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master&since=2011-01-15T00:00:00%2B00:00') end - it "handles the sha option" do - @client.commits_since("sferik/rails_admin", "2011-01-15", :sha => "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master&since=2011-01-15T00:00:00%2B00:00") + it 'handles the sha option' do + @client.commits_since('sferik/rails_admin', '2011-01-15', sha: 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master&since=2011-01-15T00:00:00%2B00:00') end end # .commits_since - describe ".commits_before", :vcr do - it "returns all commits until the specified date" do - commits = @client.commits_before("sferik/rails_admin", "2011-01-20") + describe '.commits_before', :vcr do + it 'returns all commits until the specified date' do + commits = @client.commits_before('sferik/rails_admin', '2011-01-20') expect(commits).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?until=2011-01-20T00:00:00%2B00:00") + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?until=2011-01-20T00:00:00%2B00:00') end - it "errors if the date is invalid" do - expect { @client.commits_before "sferik/rails_admin", "A pear" }.to raise_error ArgumentError + it 'errors if the date is invalid' do + expect { @client.commits_before 'sferik/rails_admin', 'A pear' }.to raise_error ArgumentError end - it "handles branch or sha argument" do - @client.commits_before("sferik/rails_admin", "2011-01-15", "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master&until=2011-01-15T00:00:00%2B00:00") + it 'handles branch or sha argument' do + @client.commits_before('sferik/rails_admin', '2011-01-15', 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master&until=2011-01-15T00:00:00%2B00:00') end - it "handles the sha option" do - @client.commits_before("sferik/rails_admin", "2011-01-15", :sha => "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master&until=2011-01-15T00:00:00%2B00:00") + it 'handles the sha option' do + @client.commits_before('sferik/rails_admin', '2011-01-15', sha: 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master&until=2011-01-15T00:00:00%2B00:00') end end # .commits_before - describe ".commits_between", :vcr do - it "returns all commits until the specified date" do - commits = @client.commits_between("sferik/rails_admin", "2011-01-20", "2013-01-20") + describe '.commits_between', :vcr do + it 'returns all commits until the specified date' do + commits = @client.commits_between('sferik/rails_admin', '2011-01-20', '2013-01-20') expect(commits).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?since=2011-01-20T00:00:00%2B00:00&until=2013-01-20T00:00:00%2B00:00") + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?since=2011-01-20T00:00:00%2B00:00&until=2013-01-20T00:00:00%2B00:00') end - it "errors if the date is invalid" do - expect { @client.commits_between "sferik/rails_admin", "A pear" }.to raise_error ArgumentError + it 'errors if the date is invalid' do + expect { @client.commits_between 'sferik/rails_admin', 'A pear' }.to raise_error ArgumentError end - it "handles branch or sha argument" do - @client.commits_between("sferik/rails_admin", "2011-01-20", "2013-01-20", "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master&since=2011-01-20T00:00:00%2B00:00&until=2013-01-20T00:00:00%2B00:00") + it 'handles branch or sha argument' do + @client.commits_between('sferik/rails_admin', '2011-01-20', '2013-01-20', 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master&since=2011-01-20T00:00:00%2B00:00&until=2013-01-20T00:00:00%2B00:00') end - it "handles the sha option" do - @client.commits_between("sferik/rails_admin", "2011-01-20", "2013-01-20", :sha => "master") - assert_requested :get, github_url("/repos/sferik/rails_admin/commits?sha=master&since=2011-01-20T00:00:00%2B00:00&until=2013-01-20T00:00:00%2B00:00") + it 'handles the sha option' do + @client.commits_between('sferik/rails_admin', '2011-01-20', '2013-01-20', sha: 'master') + assert_requested :get, github_url('/repos/sferik/rails_admin/commits?sha=master&since=2011-01-20T00:00:00%2B00:00&until=2013-01-20T00:00:00%2B00:00') end end # .commits_between - describe ".commit", :vcr do - it "returns a commit" do - commit = @client.commit("sferik/rails_admin", "3cdfabd973bc3caac209cba903cfdb3bf6636bcd") + describe '.commit', :vcr do + it 'returns a commit' do + commit = @client.commit('sferik/rails_admin', '3cdfabd973bc3caac209cba903cfdb3bf6636bcd') expect(commit.author.login).to eq('caboteria') - assert_requested :get, github_url("/repos/sferik/rails_admin/commits/3cdfabd973bc3caac209cba903cfdb3bf6636bcd") + assert_requested :get, github_url('/repos/sferik/rails_admin/commits/3cdfabd973bc3caac209cba903cfdb3bf6636bcd') end end # .commit - describe ".git_commit", :vcr do - it "returns a detailed git commit" do - commit = @client.git_commit("octokit/octokit.rb", "2bfca14ed8ebc3dad75082ff175e6703aed7ccc0") + describe '.git_commit', :vcr do + it 'returns a detailed git commit' do + commit = @client.git_commit('octokit/octokit.rb', '2bfca14ed8ebc3dad75082ff175e6703aed7ccc0') expect(commit.author.name).to eq('Joey Wendt') - assert_requested :get, github_url("/repos/octokit/octokit.rb/git/commits/2bfca14ed8ebc3dad75082ff175e6703aed7ccc0") + assert_requested :get, github_url('/repos/octokit/octokit.rb/git/commits/2bfca14ed8ebc3dad75082ff175e6703aed7ccc0') end end # .git_commit - describe ".create_commit", :vcr do - it "creates a commit" do + describe '.create_commit', :vcr do + it 'creates a commit' do last_commit = @client.commits(@test_repo).last - @client.create_commit(@test_repo, "My commit message", last_commit.commit.tree.sha, last_commit.sha) + @client.create_commit(@test_repo, 'My commit message', last_commit.commit.tree.sha, last_commit.sha) assert_requested :post, github_url("/repos/#{@test_repo}/git/commits") end end # .create_commit - describe ".merge", :vcr do - it "merges a branch into another" do + describe '.merge', :vcr do + it 'merges a branch into another' do begin - @client.delete_ref(@test_repo, "heads/branch-to-merge") + @client.delete_ref(@test_repo, 'heads/branch-to-merge') rescue Octokit::UnprocessableEntity end last_commit = @client.commits(@test_repo).last - @client.create_ref(@test_repo, "heads/branch-to-merge", last_commit.sha) - @client.merge(@test_repo, "master", "branch-to-merge", :commit_message => "Testing the merge API") + @client.create_ref(@test_repo, 'heads/branch-to-merge', last_commit.sha) + @client.merge(@test_repo, 'master', 'branch-to-merge', commit_message: 'Testing the merge API') assert_requested :post, github_url("/repos/#{@test_repo}/merges") end end # .merge - describe ".compare", :vcr do - it "returns a comparison" do - comparison = @client.compare("gvaughn/octokit", '0e0d7ae299514da692eb1cab741562c253d44188', 'b7b37f75a80b8e84061cd45b246232ad958158f5') + describe '.compare', :vcr do + it 'returns a comparison' do + comparison = @client.compare('gvaughn/octokit', '0e0d7ae299514da692eb1cab741562c253d44188', 'b7b37f75a80b8e84061cd45b246232ad958158f5') expect(comparison.base_commit.sha).to eq('0e0d7ae299514da692eb1cab741562c253d44188') expect(comparison.merge_base_commit.sha).to eq('b7b37f75a80b8e84061cd45b246232ad958158f5') - assert_requested :get, github_url("/repos/gvaughn/octokit/compare/0e0d7ae299514da692eb1cab741562c253d44188...b7b37f75a80b8e84061cd45b246232ad958158f5") + assert_requested :get, github_url('/repos/gvaughn/octokit/compare/0e0d7ae299514da692eb1cab741562c253d44188...b7b37f75a80b8e84061cd45b246232ad958158f5') end - it "utilizes auto_pagination", :vcr do + it 'utilizes auto_pagination', :vcr do @client.auto_paginate = true - comparison = @client.compare("mrpinsky/octokit.rb", 'b7b37f75a80b8e84061cd45b246232ad958158f5', '0e0d7ae299514da692eb1cab741562c253d44188', per_page: 1) + comparison = @client.compare('mrpinsky/octokit.rb', 'b7b37f75a80b8e84061cd45b246232ad958158f5', '0e0d7ae299514da692eb1cab741562c253d44188', per_page: 1) expect(comparison.commits.length).to eq(2) - assert_requested :get, github_url("/repos/mrpinsky/octokit.rb/compare/b7b37f75a80b8e84061cd45b246232ad958158f5...0e0d7ae299514da692eb1cab741562c253d44188?per_page=1") - assert_requested :get, github_url("/repositories/387936585/compare/b7b37f75a80b8e84061cd45b246232ad958158f5...0e0d7ae299514da692eb1cab741562c253d44188?page=2&per_page=1") + assert_requested :get, github_url('/repos/mrpinsky/octokit.rb/compare/b7b37f75a80b8e84061cd45b246232ad958158f5...0e0d7ae299514da692eb1cab741562c253d44188?per_page=1') + assert_requested :get, github_url('/repositories/387936585/compare/b7b37f75a80b8e84061cd45b246232ad958158f5...0e0d7ae299514da692eb1cab741562c253d44188?page=2&per_page=1') end end # .compare end diff --git a/spec/octokit/client/community_profile_spec.rb b/spec/octokit/client/community_profile_spec.rb index a7fb21435..861e95c33 100644 --- a/spec/octokit/client/community_profile_spec.rb +++ b/spec/octokit/client/community_profile_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::CommunityProfile do @@ -7,7 +9,7 @@ end describe '.community_profile', :vcr do - it "returns community profile metrics for a repository" do + it 'returns community profile metrics for a repository' do community_profile = @client.community_profile('octokit/octokit.rb', accept: preview_header) expect(community_profile.health_percentage).not_to be_nil assert_requested :get, github_url('/repos/octokit/octokit.rb/community/profile') diff --git a/spec/octokit/client/contents_spec.rb b/spec/octokit/client/contents_spec.rb index 7fdb679db..5b4cfb0c0 100644 --- a/spec/octokit/client/contents_spec.rb +++ b/spec/octokit/client/contents_spec.rb @@ -1,150 +1,149 @@ +# frozen_string_literal: true + require 'helper' require 'tempfile' describe Octokit::Client::Contents do - before do Octokit.reset! @client = oauth_client end - describe ".readme", :vcr do - it "returns the default readme" do + describe '.readme', :vcr do + it 'returns the default readme' do readme = @client.readme('octokit/octokit.rb') - expect(readme.encoding).to eq("base64") - expect(readme.type).to eq("file") - assert_requested :get, github_url("/repos/octokit/octokit.rb/readme") + expect(readme.encoding).to eq('base64') + expect(readme.type).to eq('file') + assert_requested :get, github_url('/repos/octokit/octokit.rb/readme') end end # .readme - describe ".contents", :vcr do - it "returns the contents of a file" do - contents = @client.contents('octokit/octokit.rb', :path => "lib/octokit.rb") - expect(contents.encoding).to eq("base64") - expect(contents.type).to eq("file") - assert_requested :get, github_url("/repos/octokit/octokit.rb/contents/lib/octokit.rb") + describe '.contents', :vcr do + it 'returns the contents of a file' do + contents = @client.contents('octokit/octokit.rb', path: 'lib/octokit.rb') + expect(contents.encoding).to eq('base64') + expect(contents.type).to eq('file') + assert_requested :get, github_url('/repos/octokit/octokit.rb/contents/lib/octokit.rb') end end # .contents - describe ".archive_link", :vcr do - it "returns the headers of the request" do - archive_link = @client.archive_link('octokit/octokit.rb', :ref => "master") + describe '.archive_link', :vcr do + it 'returns the headers of the request' do + archive_link = @client.archive_link('octokit/octokit.rb', ref: 'master') expect(archive_link).to eq('https://codeload.github.com/octokit/octokit.rb/legacy.tar.gz/master') - assert_requested :head, github_url("/repos/octokit/octokit.rb/tarball/master") + assert_requested :head, github_url('/repos/octokit/octokit.rb/tarball/master') end - it "does not raise for ref with unicode" do - request = stub_head("repos/octokit/octokit.rb/tarball/%F0%9F%90%99%F0%9F%90%B1") - @client.archive_link("octokit/octokit.rb", :ref => "🐙🐱") + it 'does not raise for ref with unicode' do + request = stub_head('repos/octokit/octokit.rb/tarball/%F0%9F%90%99%F0%9F%90%B1') + @client.archive_link('octokit/octokit.rb', ref: '🐙🐱') assert_requested request end end # .archive_link # TODO: Make the following specs idempotent - describe ".create_contents", :vcr do - it "creates repository contents at a path", :vcr do + describe '.create_contents', :vcr do + it 'creates repository contents at a path', :vcr do response = @client.create_contents(@test_repo, - "test_create.txt", - "I am commit-ing", + 'test_create.txt', + 'I am commit-ing', "Here be the content\n") expect(response.commit.sha).to match(/[a-z0-9]{40}/) assert_requested(:put, github_url("/repos/#{@test_repo}/contents/test_create.txt")) end - it "creates contents from file path", :vcr do + it 'creates contents from file path', :vcr do response = @client.create_contents(@test_repo, - "test_create_path.txt", - "I am commit-ing", - :file => "spec/fixtures/new_file.txt") + 'test_create_path.txt', + 'I am commit-ing', + file: 'spec/fixtures/new_file.txt') expect(response.commit.sha).to match(/[a-z0-9]{40}/) assert_requested(:put, github_url("/repos/#{@test_repo}/contents/test_create_path.txt")) end - it "creates contents from File object", :vcr do - file = File.new("spec/fixtures/new_file.txt", "r") + it 'creates contents from File object', :vcr do + file = File.new('spec/fixtures/new_file.txt', 'r') response = @client.create_contents(@test_repo, - "test_create_file.txt", - "I am commit-ing", - :file => file) + 'test_create_file.txt', + 'I am commit-ing', + file: file) expect(response.commit.sha).to match(/[a-z0-9]{40}/) assert_requested(:put, github_url("/repos/#{@test_repo}/contents/test_create_file.txt")) end - it "creates contents from Tempfile object", :vcr do - tempfile = Tempfile.new("uploaded_file") - file = File.new("spec/fixtures/new_file.txt", "r") + it 'creates contents from Tempfile object', :vcr do + tempfile = Tempfile.new('uploaded_file') + file = File.new('spec/fixtures/new_file.txt', 'r') tempfile.write(file.read) response = @client.create_contents(@test_repo, - "test_create_file.txt", - "I am commit-ing", - :file => tempfile) + 'test_create_file.txt', + 'I am commit-ing', + file: tempfile) expect(response.commit.sha).to match(/[a-z0-9]{40}/) assert_requested(:put, github_url("/repos/#{@test_repo}/contents/test_create_file.txt")) tempfile.unlink end - it "does not add new lines", :vcr do - file = File.new("spec/fixtures/large_file.txt", "r") + it 'does not add new lines', :vcr do + file = File.new('spec/fixtures/large_file.txt', 'r') response = @client.create_contents(@test_repo, - "test_create_without_newlines.txt", - "I am commit-ing", - :file => file) + 'test_create_without_newlines.txt', + 'I am commit-ing', + file: file) assert_requested(:put, github_url("/repos/#{@test_repo}/contents/test_create_without_newlines.txt")) content = response.content.rels[:self].get \ - :headers => {:accept => "application/vnd.github.raw" } - expect(content.data).to eq(File.read("spec/fixtures/large_file.txt")) + headers: { accept: 'application/vnd.github.raw' } + expect(content.data).to eq(File.read('spec/fixtures/large_file.txt')) end end # .create_contents - describe ".update_contents", :vcr do - it "updates repository contents at a path" do + describe '.update_contents', :vcr do + it 'updates repository contents at a path' do content = @client.create_contents(@test_repo, - "test_update.txt", - "I am commit-ing", - :file => "spec/fixtures/new_file.txt") + 'test_update.txt', + 'I am commit-ing', + file: 'spec/fixtures/new_file.txt') response = @client.update_contents(@test_repo, - "test_update.txt", - "I am commit-ing", + 'test_update.txt', + 'I am commit-ing', content.content.sha, - "Here be moar content") + 'Here be moar content') expect(response.commit.sha).to match(/[a-z0-9]{40}/) assert_requested :put, - github_url("/repos/#{@test_repo}/contents/test_update.txt"), - :times => 2 - + github_url("/repos/#{@test_repo}/contents/test_update.txt"), + times: 2 end - it "does not add new lines", :vcr do + it 'does not add new lines', :vcr do content = @client.create_contents(@test_repo, - "test_update_without_newlines.txt", - "I am commit-ing", - :file => "spec/fixtures/new_file.txt") + 'test_update_without_newlines.txt', + 'I am commit-ing', + file: 'spec/fixtures/new_file.txt') response = @client.update_contents(@test_repo, - "test_update_without_newlines.txt", - "I am commit-ing", + 'test_update_without_newlines.txt', + 'I am commit-ing', content.content.sha, - :file => "spec/fixtures/large_file.txt") + file: 'spec/fixtures/large_file.txt') assert_requested :put, - github_url("/repos/#{@test_repo}/contents/test_update_without_newlines.txt"), - :times => 2 + github_url("/repos/#{@test_repo}/contents/test_update_without_newlines.txt"), + times: 2 content = response.content.rels[:self].get \ - :headers => {:accept => "application/vnd.github.raw" } - expect(content.data).to eq(File.read("spec/fixtures/large_file.txt")) + headers: { accept: 'application/vnd.github.raw' } + expect(content.data).to eq(File.read('spec/fixtures/large_file.txt')) end end # .update_contents - describe ".delete_contents", :vcr do - it "deletes repository contents at a path" do + describe '.delete_contents', :vcr do + it 'deletes repository contents at a path' do content = @client.create_contents(@test_repo, - "test_delete.txt", - "I am commit-ing", - "You DELETE me") + 'test_delete.txt', + 'I am commit-ing', + 'You DELETE me') response = @client.delete_contents(@test_repo, - "test_delete.txt", - "I am rm-ing", + 'test_delete.txt', + 'I am rm-ing', content.content.sha) expect(response.commit.sha).to match(/[a-z0-9]{40}/) assert_requested :delete, - github_url("/repos/#{@test_repo}/contents/test_delete.txt") + github_url("/repos/#{@test_repo}/contents/test_delete.txt") end end # .delete_contents - end diff --git a/spec/octokit/client/deployments_spec.rb b/spec/octokit/client/deployments_spec.rb index b8ec9c2c9..67f5df0ae 100644 --- a/spec/octokit/client/deployments_spec.rb +++ b/spec/octokit/client/deployments_spec.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Deployments do - before do Octokit.reset! @client = oauth_client @@ -11,20 +12,20 @@ Octokit.reset! end - describe ".deployments", :vcr do - it "lists deployments" do + describe '.deployments', :vcr do + it 'lists deployments' do deployments = @client.deployments(@test_repo) expect(deployments).to be_kind_of Array assert_requested :get, github_url("/repos/#{@test_repo}/deployments") end end # .deployments - context "with ref", :vcr do + context 'with ref', :vcr do before(:each) do commits = @client.commits(@test_repo) @first_sha = commits.first.sha - @branch_name = "testing/deployment" + @branch_name = 'testing/deployment' @ref = @client.create_ref(@test_repo, "heads/#{@branch_name}", @first_sha) end @@ -35,16 +36,16 @@ end end - describe ".create_deployment" do - it "creates a deployment" do + describe '.create_deployment' do + it 'creates a deployment' do deployment = @client.create_deployment(@test_repo, @branch_name) expect(deployment.sha).to eq(@ref.object.sha) expect(deployment.creator.login).to eq(test_github_login) assert_requested :post, github_url("/repos/#{@test_repo}/deployments") end - it "creates a deployment with a payload" do - opts = {:payload => {:environment => "production"}} + it 'creates a deployment with a payload' do + opts = { payload: { environment: 'production' } } deployment = @client.create_deployment(@test_repo, @branch_name, opts) expect(deployment.sha).to eq(@ref.object.sha) expect(deployment.creator.login).to eq(test_github_login) @@ -53,30 +54,30 @@ end end # .create_deployment - context "with deployment" do + context 'with deployment' do before(:each) do @deployment = @client.create_deployment(@test_repo, @branch_name) @deployment_url = "https://api.github.com/repos/#{@test_repo}/deployments/#{@deployment.id}" end - describe ".deployment" do - it "gets a single deployment" do + describe '.deployment' do + it 'gets a single deployment' do deployment = @client.deployment(@test_repo, @deployment.id) expect(deployment).to be_kind_of Sawyer::Resource assert_requested :get, github_url("/repos/#{@test_repo}/deployments/#{@deployment.id}") end end # .deployment - describe ".delete_deployment" do - it "deletes a single deployment" do + describe '.delete_deployment' do + it 'deletes a single deployment' do response = @client.delete_deployment(@test_repo, @deployment.id) expect(response.empty?).to be true assert_requested :delete, github_url("/repos/#{@test_repo}/deployments/#{@deployment.id}") end end # .delete_deployment - describe ".deployment_statuses" do - it "lists deployment statuses" do + describe '.deployment_statuses' do + it 'lists deployment statuses' do statuses = @client.deployment_statuses(@deployment_url) expect(statuses).to be_kind_of Array assert_requested :get, github_url(@deployment_url) @@ -84,12 +85,12 @@ end end # .deployment_statuses - describe ".create_deployment_status" do - it "creates a deployment status" do - status = @client.create_deployment_status(@deployment_url, "SUCCESS", :target_url => "http://wynn.fm") + describe '.create_deployment_status' do + it 'creates a deployment status' do + status = @client.create_deployment_status(@deployment_url, 'SUCCESS', target_url: 'http://wynn.fm') expect(status.creator.login).to eq(test_github_login) - expect(status.state).to eq("success") - expect(status.rels[:target].href).to eq("http://wynn.fm") + expect(status.state).to eq('success') + expect(status.rels[:target].href).to eq('http://wynn.fm') assert_requested :get, github_url(@deployment_url) assert_requested :post, github_url("#{@deployment_url}/statuses") end diff --git a/spec/octokit/client/downloads_spec.rb b/spec/octokit/client/downloads_spec.rb index 6138e7819..f0915b7bb 100644 --- a/spec/octokit/client/downloads_spec.rb +++ b/spec/octokit/client/downloads_spec.rb @@ -1,34 +1,34 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Downloads do - before do Octokit.reset! @client = oauth_client end - describe ".downloads", :vcr do - it "lists available downloads" do - downloads = @client.downloads("github/hubot") - expect(downloads.last.description).to eq("Version 1.0.0 of the Hubot Campfire Bot") - assert_requested :get, github_url("/repos/github/hubot/downloads") + describe '.downloads', :vcr do + it 'lists available downloads' do + downloads = @client.downloads('github/hubot') + expect(downloads.last.description).to eq('Version 1.0.0 of the Hubot Campfire Bot') + assert_requested :get, github_url('/repos/github/hubot/downloads') end end # .downloads - describe ".download", :vcr do - it "gets a single download" do - download = @client.download("github/hubot", 165347) - expect(download.name).to eq("hubot-2.1.0.tar.gz") - assert_requested :get, github_url("/repos/github/hubot/downloads/165347") + describe '.download', :vcr do + it 'gets a single download' do + download = @client.download('github/hubot', 165_347) + expect(download.name).to eq('hubot-2.1.0.tar.gz') + assert_requested :get, github_url('/repos/github/hubot/downloads/165347') end end # .download - describe ".delete_download" do - it "deletes a download" do - request = stub_delete(github_url("/repos/api-playground/api-sandbox/downloads/12345")) + describe '.delete_download' do + it 'deletes a download' do + request = stub_delete(github_url('/repos/api-playground/api-sandbox/downloads/12345')) @client.delete_download 'api-playground/api-sandbox', '12345' assert_requested request end end # .delete_download - end diff --git a/spec/octokit/client/emojis_spec.rb b/spec/octokit/client/emojis_spec.rb index 3fdc5b938..4d2fce4ad 100644 --- a/spec/octokit/client/emojis_spec.rb +++ b/spec/octokit/client/emojis_spec.rb @@ -1,9 +1,10 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Emojis do - - describe ".emojis", :vcr do - it "returns all github emojis" do + describe '.emojis', :vcr do + it 'returns all github emojis' do client = oauth_client emojis = client.emojis expect(emojis[:metal]).to match(/metal/) diff --git a/spec/octokit/client/events_spec.rb b/spec/octokit/client/events_spec.rb index a44aab6fd..e0311142f 100644 --- a/spec/octokit/client/events_spec.rb +++ b/spec/octokit/client/events_spec.rb @@ -1,106 +1,107 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Events do - before do Octokit.reset! @client = oauth_client end - describe ".public_events", :vcr do - it "returns all public events" do + describe '.public_events', :vcr do + it 'returns all public events' do public_events = @client.public_events expect(public_events).to be_kind_of Array - assert_requested :get, github_url("/events") + assert_requested :get, github_url('/events') end end # .public_events - describe ".user_events", :vcr do - it "returns all user events" do + describe '.user_events', :vcr do + it 'returns all user events' do user_events = @client.user_events('sferik') expect(user_events).to be_kind_of Array - assert_requested :get, github_url("/users/sferik/events") + assert_requested :get, github_url('/users/sferik/events') end end # .user_events - describe ".user_public_events", :vcr do - it "returns public events performed by a user" do - user_public_events = @client.user_public_events("sferik") + describe '.user_public_events', :vcr do + it 'returns public events performed by a user' do + user_public_events = @client.user_public_events('sferik') expect(user_public_events).to be_kind_of Array - assert_requested :get, github_url("/users/sferik/events/public") + assert_requested :get, github_url('/users/sferik/events/public') end end # .user_public_events - describe ".received_events", :vcr do - it "returns all user received events" do - received_events = @client.received_events("api-padawan") + describe '.received_events', :vcr do + it 'returns all user received events' do + received_events = @client.received_events('api-padawan') expect(received_events).to be_kind_of Array - assert_requested :get, github_url("/users/api-padawan/received_events") + assert_requested :get, github_url('/users/api-padawan/received_events') end end # .received_events - describe ".received_public_events", :vcr do - it "returns public user received events" do - received_public_events = @client.received_public_events("api-padawan") + describe '.received_public_events', :vcr do + it 'returns public user received events' do + received_public_events = @client.received_public_events('api-padawan') expect(received_public_events).to be_kind_of Array - assert_requested :get, github_url("/users/api-padawan/received_events/public") + assert_requested :get, github_url('/users/api-padawan/received_events/public') end end # .received_public_events - describe ".repository_events", :vcr do - it "returns events for a repository" do - repo_events = @client.repository_events("sferik/rails_admin") + describe '.repository_events', :vcr do + it 'returns events for a repository' do + repo_events = @client.repository_events('sferik/rails_admin') expect(repo_events).to be_kind_of Array assert_requested :get, github_url('/repos/sferik/rails_admin/events') end end # .repository_events - describe ".repository_network_events", :vcr do + describe '.repository_network_events', :vcr do it "returns events for a repository's network" do - repo_network_events = @client.repository_network_events("sferik/rails_admin") + repo_network_events = @client.repository_network_events('sferik/rails_admin') expect(repo_network_events).to be_kind_of Array assert_requested :get, github_url('/networks/sferik/rails_admin/events') end end # .repository_network_events - describe ".organization_events", :vcr do - it "returns all events for an organization" do + describe '.organization_events', :vcr do + it 'returns all events for an organization' do client = oauth_client - org_events = client.organization_events("github") + org_events = client.organization_events('github') expect(org_events).to be_kind_of Array assert_requested :get, github_url("/users/#{test_github_login}/events/orgs/github") end end # .organization_events - describe ".organization_public_events", :vcr do + describe '.organization_public_events', :vcr do it "returns an organization's public events" do - org_public_events = @client.organization_public_events("github") + org_public_events = @client.organization_public_events('github') expect(org_public_events).to be_kind_of Array - assert_requested :get, github_url("/orgs/github/events") + assert_requested :get, github_url('/orgs/github/events') end end # .organization_public_events - describe ".repo_issue_events", :vcr do - it "lists issue events for a repository" do - issue_events = @client.repo_issue_events("octokit/octokit.rb") + describe '.repo_issue_events', :vcr do + it 'lists issue events for a repository' do + issue_events = @client.repo_issue_events('octokit/octokit.rb') expect(issue_events).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/issues/events") + assert_requested :get, github_url('/repos/octokit/octokit.rb/issues/events') end end # .repo_issue_events - describe ".issue_events", :vcr do - it "lists issue events for a repository" do - issue_events = @client.issue_events("octokit/octokit.rb", 4, accept: preview_header) + describe '.issue_events', :vcr do + it 'lists issue events for a repository' do + issue_events = @client.issue_events('octokit/octokit.rb', 4, accept: preview_header) expect(issue_events).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/issues/4/events") + assert_requested :get, github_url('/repos/octokit/octokit.rb/issues/4/events') end end # .issue_events - describe ".issue_event", :vcr do - it "lists issue events for a repository" do + describe '.issue_event', :vcr do + it 'lists issue events for a repository' do # TODO: Remove and use hypermedia - @client.issue_event("octokit/octokit.rb", 37786228) - assert_requested :get, github_url("/repos/octokit/octokit.rb/issues/events/37786228") + @client.issue_event('octokit/octokit.rb', 37_786_228) + assert_requested :get, github_url('/repos/octokit/octokit.rb/issues/events/37786228') end end # .issue_events diff --git a/spec/octokit/client/feeds_spec.rb b/spec/octokit/client/feeds_spec.rb index 045178453..9584af046 100644 --- a/spec/octokit/client/feeds_spec.rb +++ b/spec/octokit/client/feeds_spec.rb @@ -1,14 +1,15 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Feeds do - before do Octokit.reset! end - describe ".feeds", :vcr do - context "when unauthenticated" do - it "returns the public feeds list" do + describe '.feeds', :vcr do + context 'when unauthenticated' do + it 'returns the public feeds list' do feeds = Octokit.feeds expect(Octokit.user_authenticated?).to be false expect(feeds.rels[:timeline].href).to be @@ -16,16 +17,16 @@ end end - context "when authenticated with oauth token" do - it "returns the authenticated users feeds" do + context 'when authenticated with oauth token' do + it 'returns the authenticated users feeds' do feeds = oauth_client.feeds expect(oauth_client.user_authenticated?).to be true expect(feeds.rels[:current_user_public].href).to be end end - context "when authenticated with basic auth" do - it "returns private feeds" do + context 'when authenticated with basic auth' do + it 'returns private feeds' do feeds = basic_auth_client.feeds expect(basic_auth_client.user_authenticated?).to be true expect(feeds.rels[:current_user].href).to be @@ -37,11 +38,10 @@ end end # .feeds - describe ".feed", :vcr do - it "returns parsed feed data" do + describe '.feed', :vcr do + it 'returns parsed feed data' do feed = Octokit.feed(:timeline) - expect(feed.title.content).to eq("GitHub Public Timeline Feed") + expect(feed.title.content).to eq('GitHub Public Timeline Feed') end end # .feed - end diff --git a/spec/octokit/client/gists_spec.rb b/spec/octokit/client/gists_spec.rb index 6868e8b1e..8e836be96 100644 --- a/spec/octokit/client/gists_spec.rb +++ b/spec/octokit/client/gists_spec.rb @@ -1,156 +1,150 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Gists do - before do Octokit.reset! end - describe "unauthenticated", :vcr do - - describe ".public_gists" do - it "returns public gists" do + describe 'unauthenticated', :vcr do + describe '.public_gists' do + it 'returns public gists' do gists = Octokit.client.public_gists expect(gists).not_to be_empty assert_requested :get, github_url('/gists/public') end end # .public_gists - describe ".gists" do - describe "with username passed" do - it "returns a list of gists" do + describe '.gists' do + describe 'with username passed' do + it 'returns a list of gists' do gists = Octokit.client.gists('defunkt') expect(gists).not_to be_empty - assert_requested :get, github_url("/users/defunkt/gists") + assert_requested :get, github_url('/users/defunkt/gists') end end - describe "without a username passed" do - it "returns a list of gists" do + describe 'without a username passed' do + it 'returns a list of gists' do gists = Octokit.client.gists expect(gists).not_to be_empty - assert_requested :get, github_url("/gists") + assert_requested :get, github_url('/gists') end end - end # .gists - describe ".gist" do - it "returns the gist by ID" do - gist = Octokit.client.gist(790381) + describe '.gist' do + it 'returns the gist by ID' do + gist = Octokit.client.gist(790_381) expect(gist.owner.login).to eq('jmccartie') - assert_requested :get, github_url("/gists/790381") + assert_requested :get, github_url('/gists/790381') end - it "returns a gist at a specific revision" do - gist = Octokit.client.gist(790381, sha: "12e53275c298ab759fa38a1f4980a4aa0556593f") + it 'returns a gist at a specific revision' do + gist = Octokit.client.gist(790_381, sha: '12e53275c298ab759fa38a1f4980a4aa0556593f') expect(gist).to be_kind_of Sawyer::Resource - assert_requested :get, github_url("/gists/790381/12e53275c298ab759fa38a1f4980a4aa0556593f") + assert_requested :get, github_url('/gists/790381/12e53275c298ab759fa38a1f4980a4aa0556593f') end end - end # unauthenticated - describe "when authenticated", :vcr do - + describe 'when authenticated', :vcr do before do @client = oauth_client new_gist = { - :description => "A gist from Octokit", - :public => true, - :files => { - "zen.text" => { :content => "Keep it logically awesome." } + description: 'A gist from Octokit', + public: true, + files: { + 'zen.text' => { content: 'Keep it logically awesome.' } } } @gist = @client.create_gist(new_gist) - @gist_comment = @client.create_gist_comment(5421307, ":metal:") + @gist_comment = @client.create_gist_comment(5_421_307, ':metal:') end after do @client.delete_gist @gist.id end - describe ".gists" do - it "returns a list of gists" do + describe '.gists' do + it 'returns a list of gists' do gists = @client.gists expect(gists).not_to be_empty - assert_requested :get, github_url("/gists") + assert_requested :get, github_url('/gists') end end # .gists - - describe ".starred_gists" do + describe '.starred_gists' do it "returns the user's starred gists" do gists = @client.starred_gists expect(gists).to be_kind_of Array - assert_requested :get, github_url("/gists/starred") + assert_requested :get, github_url('/gists/starred') end end # .starred_gists - describe ".create_gist" do - it "creates a new gist" do + describe '.create_gist' do + it 'creates a new gist' do expect(@gist.owner.login).to eq(test_github_login) expect(@gist.files.fields.first.to_s).to match(/zen/) - assert_requested :post, github_url("/gists") + assert_requested :post, github_url('/gists') end end # .create_gist - describe ".edit_gist" do - it "edit an existing gist" do - @client.edit_gist(@gist.id, :description => "GitHub Zen") + describe '.edit_gist' do + it 'edit an existing gist' do + @client.edit_gist(@gist.id, description: 'GitHub Zen') assert_requested :patch, github_url("/gists/#{@gist.id}") end end # .edit_gist - describe ".gist_commits" do - it "lists a gists commits" do + describe '.gist_commits' do + it 'lists a gists commits' do @client.gist_commits(@gist.id) assert_requested :get, github_url("/gists/#{@gist.id}/commits") end end # .gist_commits - describe ".star_gist" do - it "stars an existing gist" do + describe '.star_gist' do + it 'stars an existing gist' do @client.star_gist(@gist.id) assert_requested :put, github_url("/gists/#{@gist.id}/star") expect(@client.last_response.status).to eq(204) end end # .star - describe ".unstar_gist" do - it "unstars an existing gist" do + describe '.unstar_gist' do + it 'unstars an existing gist' do @client.unstar_gist(@gist.id) assert_requested :delete, github_url("/gists/#{@gist.id}/star") expect(@client.last_response.status).to eq(204) end end # .unstar_gist - describe ".gist_starred?" do - - it "is not starred" do - starred = @client.gist_starred?(5421308) - assert_requested :get, github_url("/gists/5421308/star") + describe '.gist_starred?' do + it 'is not starred' do + starred = @client.gist_starred?(5_421_308) + assert_requested :get, github_url('/gists/5421308/star') expect(starred).to be false end - context "with starred gist" do + context 'with starred gist' do before do - @client.star_gist(5421307) + @client.star_gist(5_421_307) end - it "is starred" do - starred = @client.gist_starred?(5421307) - assert_requested :get, github_url("/gists/5421307/star") + it 'is starred' do + starred = @client.gist_starred?(5_421_307) + assert_requested :get, github_url('/gists/5421307/star') expect(starred).to be true end end - end # .gist_starred? - describe ".fork_gist" do - it "forks an existing gist" do - latest = Octokit.gist(5506606) + describe '.fork_gist' do + it 'forks an existing gist' do + latest = Octokit.gist(5_506_606) gist = @client.fork_gist(latest.id) expect(gist.description).to eq(latest.description) assert_requested :post, github_url("/gists/#{latest.id}/forks") @@ -160,58 +154,56 @@ end end # .fork_gist - describe ".gist_forks" do - it "lists a gists forks" do + describe '.gist_forks' do + it 'lists a gists forks' do forks = @client.gist_forks(@gist.id) expect(forks).to be_kind_of Array assert_requested :get, github_url("/gists/#{@gist.id}/forks") end end # .gist_forks - describe ".gist_comments" do - it "returns the list of gist comments" do - comments = @client.gist_comments(5421307) + describe '.gist_comments' do + it 'returns the list of gist comments' do + comments = @client.gist_comments(5_421_307) expect(comments).to be_kind_of Array - assert_requested :get, github_url("/gists/5421307/comments") + assert_requested :get, github_url('/gists/5421307/comments') end end # .gist_comments - describe ".gist_comment" do - it "returns a gist comment" do - comment = @client.gist_comment("5421307", 818334) - expect(comment.body).to eq(":sparkles:") - assert_requested :get, github_url("/gists/5421307/comments/818334") + describe '.gist_comment' do + it 'returns a gist comment' do + comment = @client.gist_comment('5421307', 818_334) + expect(comment.body).to eq(':sparkles:') + assert_requested :get, github_url('/gists/5421307/comments/818334') end end # .gist_comment - describe ".create_gist_comment" do - it "creates a gist comment" do - assert_requested :post, github_url("/gists/5421307/comments") + describe '.create_gist_comment' do + it 'creates a gist comment' do + assert_requested :post, github_url('/gists/5421307/comments') end end # .create_gist_comment - describe ".update_gist_comment" do - it "updates a gist comment" do - @client.update_gist_comment(5421307, @gist_comment.id, ":heart:") + describe '.update_gist_comment' do + it 'updates a gist comment' do + @client.update_gist_comment(5_421_307, @gist_comment.id, ':heart:') assert_requested :patch, github_url("/gists/5421307/comments/#{@gist_comment.id}") end end # .update_gist_comment - describe ".delete_gist_comment" do - it "deletes a gist comment" do - @client.create_gist_comment(5421307, ":metal:") - @client.delete_gist_comment(5421307, @gist_comment.id) + describe '.delete_gist_comment' do + it 'deletes a gist comment' do + @client.create_gist_comment(5_421_307, ':metal:') + @client.delete_gist_comment(5_421_307, @gist_comment.id) assert_requested :delete, github_url("/gists/5421307/comments/#{@gist_comment.id}") end end # .delete_gist_comment - describe ".delete_gist" do - it "deletes an existing gist" do + describe '.delete_gist' do + it 'deletes an existing gist' do @client.delete_gist(@gist.id) assert_requested :delete, github_url("/gists/#{@gist.id}") end end # .delete_gist - end # authenticated - end diff --git a/spec/octokit/client/gitignore_spec.rb b/spec/octokit/client/gitignore_spec.rb index 9caabb618..c0570752b 100644 --- a/spec/octokit/client/gitignore_spec.rb +++ b/spec/octokit/client/gitignore_spec.rb @@ -1,26 +1,26 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Gitignore do - before do @client = oauth_client end - describe ".gitignore_templates", :vcr do - it "returns all gitignore templates" do + describe '.gitignore_templates', :vcr do + it 'returns all gitignore templates' do templates = @client.gitignore_templates expect(templates).to be_kind_of Array - assert_requested :get, github_url("/gitignore/templates") + assert_requested :get, github_url('/gitignore/templates') end end # .gitignore_templates - describe ".gitignore_template", :vcr do - it "returns the ruby gitignore template" do - template = @client.gitignore_template("Ruby") - expect(template.name).to eq("Ruby") + describe '.gitignore_template', :vcr do + it 'returns the ruby gitignore template' do + template = @client.gitignore_template('Ruby') + expect(template.name).to eq('Ruby') expect(template.source).to include("*.gem\n") - assert_requested :get, github_url("/gitignore/templates/Ruby") + assert_requested :get, github_url('/gitignore/templates/Ruby') end end # .gitignore_template - end diff --git a/spec/octokit/client/hooks_spec.rb b/spec/octokit/client/hooks_spec.rb index 29849e09b..846c67683 100644 --- a/spec/octokit/client/hooks_spec.rb +++ b/spec/octokit/client/hooks_spec.rb @@ -1,22 +1,23 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Hooks do - before do Octokit.reset! @client = oauth_client end - describe ".available_hooks", :vcr do - it "returns all the hooks supported by GitHub with their parameters" do + describe '.available_hooks', :vcr do + it 'returns all the hooks supported by GitHub with their parameters' do hooks = @client.available_hooks - expect(hooks.first.name).to eq("activecollab") + expect(hooks.first.name).to eq('activecollab') end end - context "with repository" do + context 'with repository' do before(:each) do - @repo = @client.create_repository("an-repo") + @repo = @client.create_repository('an-repo') end after(:each) do @@ -26,7 +27,7 @@ end end - describe ".hooks", :vcr do + describe '.hooks', :vcr do it "returns a repository's hooks" do hooks = @client.hooks(@repo.full_name) expect(hooks).to be_kind_of Array @@ -34,53 +35,53 @@ end end - context "with hook" do + context 'with hook' do before(:each) do - @hook = @client.create_hook(@repo.full_name, "railsbp", {:railsbp_url => "http://railsbp.com", :token => "xAAQZtJhYHGagsed1kYR"}) + @hook = @client.create_hook(@repo.full_name, 'railsbp', { railsbp_url: 'http://railsbp.com', token: 'xAAQZtJhYHGagsed1kYR' }) end after(:each) do @client.remove_hook(@repo.full_name, @hook.id) end - describe ".create_hook", :vcr do - it "creates a hook" do + describe '.create_hook', :vcr do + it 'creates a hook' do assert_requested :post, github_url("/repos/#{@repo.full_name}/hooks") end end # .create_hook - describe ".hook", :vcr do + describe '.hook', :vcr do it "returns a repository's single hook" do @client.hook(@repo.full_name, @hook.id) assert_requested :get, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}") end end # .hook - describe ".edit_hook", :vcr do - it "edits a hook" do - @client.edit_hook(@repo.full_name, @hook.id, "railsbp", {:railsbp_url => "https://railsbp.com", :token => "xAAQZtJhYHGagsed1kYR"}) + describe '.edit_hook', :vcr do + it 'edits a hook' do + @client.edit_hook(@repo.full_name, @hook.id, 'railsbp', { railsbp_url: 'https://railsbp.com', token: 'xAAQZtJhYHGagsed1kYR' }) assert_requested :patch, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}") end end # .edit_hook - describe ".test_hook", :vcr do - it "tests a hook" do - @client.create_hook(@repo.full_name, "railsbp", {:railsbp_url => "http://railsbp.com", :token => "xAAQZtJhYHGagsed1kYR"}) + describe '.test_hook', :vcr do + it 'tests a hook' do + @client.create_hook(@repo.full_name, 'railsbp', { railsbp_url: 'http://railsbp.com', token: 'xAAQZtJhYHGagsed1kYR' }) @client.test_hook(@repo.full_name, @hook.id) assert_requested :post, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}/tests") end end # .test_hook - describe ".ping_hook", :vcr do - it "pings a hook" do - @client.create_hook(@repo.full_name, "railsbp", {:railsbp_url => "http://railsbp.com", :token => "xAAQZtJhYHGagsed1kYR"}) + describe '.ping_hook', :vcr do + it 'pings a hook' do + @client.create_hook(@repo.full_name, 'railsbp', { railsbp_url: 'http://railsbp.com', token: 'xAAQZtJhYHGagsed1kYR' }) @client.ping_hook(@repo.full_name, @hook.id) assert_requested :post, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}/pings") end end # .ping_hook - describe ".remove_hook", :vcr do - it "removes a hook" do + describe '.remove_hook', :vcr do + it 'removes a hook' do @client.remove_hook(@repo.full_name, @hook.id) assert_requested :delete, github_url("/repos/#{@repo.full_name}/hooks/#{@hook.id}") end @@ -88,81 +89,81 @@ end # with hook end # with repository - describe ".org_hooks", :vcr do + describe '.org_hooks', :vcr do it "returns an organization's hooks" do hooks = @client.org_hooks(test_github_org) expect(hooks).to be_kind_of Array assert_requested :get, github_url("/orgs/#{test_github_org}/hooks") end it "returns an organization's hooks by ID" do - request = stub_get("/organizations/1/hooks") + request = stub_get('/organizations/1/hooks') @client.org_hooks(1) assert_requested request end end - context "with org hook" do + context 'with org hook' do before(:each) do - @org_hook = @client.create_org_hook(test_github_org, {:url => "http://railsbp.com", :content_type => "json"}) + @org_hook = @client.create_org_hook(test_github_org, { url: 'http://railsbp.com', content_type: 'json' }) end after(:each) do @client.remove_org_hook(test_github_org, @org_hook.id) end - describe ".create_org_hook", :vcr do - it "creates an org hook" do + describe '.create_org_hook', :vcr do + it 'creates an org hook' do assert_requested :post, github_url("/orgs/#{test_github_org}/hooks") end - it "creates an org hook for by ID" do - request = stub_post("/organizations/1/hooks") - org_hook = @client.create_org_hook(1, {:url => "http://railsbp.com", :content_type => "json"}) + it 'creates an org hook for by ID' do + request = stub_post('/organizations/1/hooks') + org_hook = @client.create_org_hook(1, { url: 'http://railsbp.com', content_type: 'json' }) assert_requested request end end # .create_org_hook - describe ".org_hook", :vcr do - it "returns a single org hook" do + describe '.org_hook', :vcr do + it 'returns a single org hook' do @client.org_hook(test_github_org, @org_hook.id) assert_requested :get, github_url("/orgs/#{test_github_org}/hooks/#{@org_hook.id}") end - it "returns a single org hook by ID" do + it 'returns a single org hook by ID' do request = stub_get(github_url("/organizations/1/hooks/#{@org_hook.id}")) @client.org_hook(1, @org_hook.id) assert_requested request end end # .org_hook - describe ".edit_org_hook", :vcr do - it "edits an org hook" do - @client.edit_org_hook(test_github_org, @org_hook.id, {:url => "https://railsbp.com", :content_type => "application/json"}) + describe '.edit_org_hook', :vcr do + it 'edits an org hook' do + @client.edit_org_hook(test_github_org, @org_hook.id, { url: 'https://railsbp.com', content_type: 'application/json' }) assert_requested :patch, github_url("/orgs/#{test_github_org}/hooks/#{@org_hook.id}") end - it "edits an org hook by ID" do + it 'edits an org hook by ID' do request = stub_patch("/organizations/1/hooks/#{@org_hook.id}") - @client.edit_org_hook(1, @org_hook.id, {:url => "https://railsbp.com", :content_type => "application/json"}) + @client.edit_org_hook(1, @org_hook.id, { url: 'https://railsbp.com', content_type: 'application/json' }) assert_requested request end end # .edit_org_hook - describe ".ping_org_hook", :vcr do - it "pings an org hook" do + describe '.ping_org_hook', :vcr do + it 'pings an org hook' do @client.ping_org_hook(test_github_org, @org_hook.id) assert_requested :post, github_url("/orgs/#{test_github_org}/hooks/#{@org_hook.id}/pings") end - it "pings an org hook by ID" do + it 'pings an org hook by ID' do request = stub_post("/organizations/1/hooks/#{@org_hook.id}/pings") @client.ping_org_hook(1, @org_hook.id) assert_requested request end end # .ping_org_hook - describe ".remove_org_hook", :vcr do - it "removes an org hook" do + describe '.remove_org_hook', :vcr do + it 'removes an org hook' do @client.remove_org_hook(test_github_org, @org_hook.id) assert_requested :delete, github_url("/orgs/#{test_github_org}/hooks/#{@org_hook.id}") end - it "removes an org hook by ID" do + it 'removes an org hook by ID' do request = stub_delete("/organizations/1/hooks/#{@org_hook.id}") @client.remove_org_hook(1, @org_hook.id) assert_requested request @@ -170,12 +171,12 @@ end # .remove_org_hook end # with org hook - describe ".parse_payload", :vcr do - it "parses payload string" do + describe '.parse_payload', :vcr do + it 'parses payload string' do test_json = fixture('create_payload.json').read result = @client.parse_payload test_json - expect(result[:ref]).to eq("0.0.1") - expect(result[:repository][:name]).to eq("public-repo") + expect(result[:ref]).to eq('0.0.1') + expect(result[:repository][:name]).to eq('public-repo') expect(result[:repository][:owner][:site_admin]).to eq(false) end end # .parse_payload diff --git a/spec/octokit/client/issues_spec.rb b/spec/octokit/client/issues_spec.rb index e402be121..1a2d70e6c 100644 --- a/spec/octokit/client/issues_spec.rb +++ b/spec/octokit/client/issues_spec.rb @@ -1,7 +1,8 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Issues do - before do Octokit.reset! @client = oauth_client @@ -11,44 +12,44 @@ Octokit.reset! end - describe ".list_issues", :vcr do - it "returns issues for a repository" do - issues = @client.issues("sferik/rails_admin") + describe '.list_issues', :vcr do + it 'returns issues for a repository' do + issues = @client.issues('sferik/rails_admin') expect(issues).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/issues") + assert_requested :get, github_url('/repos/sferik/rails_admin/issues') end - it "returns dashboard issues for the authenticated user" do + it 'returns dashboard issues for the authenticated user' do issues = @client.issues expect(issues).to be_kind_of Array - assert_requested :get, github_url("/issues") + assert_requested :get, github_url('/issues') end end # .list_issues - describe ".user_issues", :vcr do - it "returns issues for the authenticated user for owned and member repos" do + describe '.user_issues', :vcr do + it 'returns issues for the authenticated user for owned and member repos' do issues = @client.user_issues expect(issues).to be_kind_of Array - assert_requested :get, github_url("/user/issues") + assert_requested :get, github_url('/user/issues') end end # .user_issues - describe ".org_issues", :vcr do - it "returns issues for the organization for the authenticated user" do + describe '.org_issues', :vcr do + it 'returns issues for the organization for the authenticated user' do issues = @client.org_issues(test_github_org) expect(issues).to be_kind_of Array assert_requested :get, github_url("/orgs/#{test_github_org}/issues") end end # .org_issues - describe ".list_assignees", :vcr do - it "returns available assignees for a repository" do - users = @client.list_assignees("octokit/octokit.rb") + describe '.list_assignees', :vcr do + it 'returns available assignees for a repository' do + users = @client.list_assignees('octokit/octokit.rb') expect(users).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/assignees") + assert_requested :get, github_url('/repos/octokit/octokit.rb/assignees') end end - context "with repository" do + context 'with repository' do before(:each) do @repo = @client.create_repository("#{test_github_repository}_#{Time.now.to_f}") end @@ -60,206 +61,206 @@ end end - describe ".create_issue", :vcr do - it "creates an issue" do + describe '.create_issue', :vcr do + it 'creates an issue' do issue = @client.create_issue \ @repo.full_name, - "Migrate issues to v3", - "Move all Issues calls to v3 of the API" + 'Migrate issues to v3', + 'Move all Issues calls to v3 of the API' expect(issue.title).to match(/Migrate/) assert_requested :post, github_url("/repos/#{@repo.full_name}/issues") end - it "creates an issue with delimited labels" do + it 'creates an issue with delimited labels' do issue = @client.create_issue \ @repo.full_name, - "New issue with delimited labels", - "Testing", - :labels => "bug, feature" + 'New issue with delimited labels', + 'Testing', + labels: 'bug, feature' expect(issue.title).to match(/delimited/) - expect(issue.labels.map(&:name)).to include("feature") + expect(issue.labels.map(&:name)).to include('feature') assert_requested :post, github_url("/repos/#{@repo.full_name}/issues") end - it "creates an issue with labels array" do + it 'creates an issue with labels array' do issue = @client.create_issue \ @repo.full_name, - "New issue with labels array", - "Testing", - :labels => %w(bug feature) + 'New issue with labels array', + 'Testing', + labels: %w[bug feature] expect(issue.title).to match(/array/) - expect(issue.labels.map(&:name)).to include("feature") + expect(issue.labels.map(&:name)).to include('feature') assert_requested :post, github_url("/repos/#{@repo.full_name}/issues") end - it "creates an issue without body argument" do - issue = @client.create_issue(@repo.full_name, "New issue without body argument") + it 'creates an issue without body argument' do + issue = @client.create_issue(@repo.full_name, 'New issue without body argument') expect(issue.body).to be_nil assert_requested :post, github_url("/repos/#{@repo.full_name}/issues") end end # .create_issue - context "with issue" do + context 'with issue' do before(:each) do - @issue = @client.create_issue(@repo.full_name, "Migrate issues to v3", "Move all Issues calls to v3 of the API") + @issue = @client.create_issue(@repo.full_name, 'Migrate issues to v3', 'Move all Issues calls to v3 of the API') end - describe ".issue", :vcr do - it "returns an issue" do + describe '.issue', :vcr do + it 'returns an issue' do issue = @client.issue(@repo.full_name, @issue.number) assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}") expect(issue.number).to eq(@issue.number) end - it "returns a full issue" do - issue = @client.issue(@repo.full_name, @issue.number, :accept => 'application/vnd.github.full+json') + it 'returns a full issue' do + issue = @client.issue(@repo.full_name, @issue.number, accept: 'application/vnd.github.full+json') assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}") expect(issue.body_html).to include('

Move all') expect(issue.body_text).to include('Move all') end end # .issue - describe ".close_issue", :vcr do - it "closes an issue" do + describe '.close_issue', :vcr do + it 'closes an issue' do issue = @client.close_issue(@repo.full_name, @issue.number) - expect(issue.state).to eq "closed" + expect(issue.state).to eq 'closed' expect(issue.number).to eq(@issue.number) assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}") end end # .close_issue - context "with closed issue" do + context 'with closed issue' do before(:each) do @client.close_issue(@repo.full_name, @issue.number) end - describe ".reopen_issue", :vcr do - it "reopens an issue" do + describe '.reopen_issue', :vcr do + it 'reopens an issue' do issue = @client.reopen_issue(@repo.full_name, @issue.number) - expect(issue.state).to eq "open" + expect(issue.state).to eq 'open' expect(issue.number).to eq(@issue.number) - assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}"), :times => 2 + assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}"), times: 2 end end # .reopen_issue end # with closed issue - describe ".lock_issue", :vcr do - it "locks an issue" do + describe '.lock_issue', :vcr do + it 'locks an issue' do @client.lock_issue(@repo.full_name, @issue.number) assert_requested :put, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/lock") end end # .lock_issue - context "with locked issue" do + context 'with locked issue' do before(:each) do @client.lock_issue(@repo.full_name, @issue.number) end - describe ".unlock_issue", :vcr do - it "unlocks an issue" do + describe '.unlock_issue', :vcr do + it 'unlocks an issue' do @client.unlock_issue(@repo.full_name, @issue.number) assert_requested :delete, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/lock") end end # .unlock_issue end # with locked issue - describe ".update_issue", :vcr do - it "updates an issue" do - issue = @client.update_issue(@repo.full_name, @issue.number, "Use all the v3 api!", "") + describe '.update_issue', :vcr do + it 'updates an issue' do + issue = @client.update_issue(@repo.full_name, @issue.number, 'Use all the v3 api!', '') expect(issue.number).to eq(@issue.number) assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}") end - it "updates an issue without positional args" do - issue = @client.update_issue(@repo.full_name, @issue.number, :title => "Use all the v3 api!", :body => "") + it 'updates an issue without positional args' do + issue = @client.update_issue(@repo.full_name, @issue.number, title: 'Use all the v3 api!', body: '') expect(issue.number).to eq(@issue.number) assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}") end end # .update_issue - describe ".add_comment", :vcr do - it "adds a comment" do - comment = @client.add_comment(@repo.full_name, @issue.number, "A test comment") + describe '.add_comment', :vcr do + it 'adds a comment' do + comment = @client.add_comment(@repo.full_name, @issue.number, 'A test comment') expect(comment.user.login).to eq(test_github_login) assert_requested :post, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/comments") end end # .add_comment - context "with issue comment" do + context 'with issue comment' do before(:each) do - @issue_comment = @client.add_comment(@repo.full_name, @issue.number, "Another test comment") + @issue_comment = @client.add_comment(@repo.full_name, @issue.number, 'Another test comment') end - describe ".update_comment", :vcr do - it "updates an existing comment" do - @client.update_comment(@repo.full_name, @issue_comment.id, "A test comment update") + describe '.update_comment', :vcr do + it 'updates an existing comment' do + @client.update_comment(@repo.full_name, @issue_comment.id, 'A test comment update') assert_requested :patch, github_url("/repos/#{@repo.full_name}/issues/comments/#{@issue_comment.id}") end end # .update_comment - describe ".delete_comment", :vcr do - it "deletes an existing comment" do + describe '.delete_comment', :vcr do + it 'deletes an existing comment' do @client.delete_comment(@repo.full_name, @issue_comment.id) assert_requested :delete, github_url("/repos/#{@repo.full_name}/issues/comments/#{@issue_comment.id}") end end # .delete_comment end # with issue comment - describe ".issue_timeline", :vcr do - it "returns an issue timeline" do + describe '.issue_timeline', :vcr do + it 'returns an issue timeline' do timeline = @client.issue_timeline(@repo.full_name, @issue.number, accept: Octokit::Preview::PREVIEW_TYPES[:issue_timelines]) expect(timeline).to be_kind_of Array assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/timeline") end end # .issue_timeline - context "with assignees" do - before(:each) do - issue = @client.add_assignees(@repo.full_name, @issue.number, ["api-padawan"]) - expect(issue.assignees.count).not_to be_zero - end + context 'with assignees' do + before(:each) do + issue = @client.add_assignees(@repo.full_name, @issue.number, ['api-padawan']) + expect(issue.assignees.count).not_to be_zero + end - describe ".remove_assignees", :vcr do - it "removes assignees" do - issue = @client.remove_assignees( - @repo.full_name, @issue.number, ["api-padawan"] - ) - expect(issue.assignees.count).to be_zero - assert_requested :post, github_url("repos/#{@repo.full_name}/issues/#{@issue.number}/assignees") - end - end # .remove_assignees - end # with assignees + describe '.remove_assignees', :vcr do + it 'removes assignees' do + issue = @client.remove_assignees( + @repo.full_name, @issue.number, ['api-padawan'] + ) + expect(issue.assignees.count).to be_zero + assert_requested :post, github_url("repos/#{@repo.full_name}/issues/#{@issue.number}/assignees") + end + end # .remove_assignees + end # with assignees end # with issue end # with repo - describe ".repository_issues_comments", :vcr do - it "returns comments for all issues in a repository" do - comments = @client.issues_comments("octokit/octokit.rb") + describe '.repository_issues_comments', :vcr do + it 'returns comments for all issues in a repository' do + comments = @client.issues_comments('octokit/octokit.rb') expect(comments).to be_kind_of Array assert_requested :get, github_url('/repos/octokit/octokit.rb/issues/comments') end end # .repository_issues_comments - describe ".issue_comments", :vcr do - it "returns comments for an issue" do - comments = @client.issue_comments("octokit/octokit.rb", 25) + describe '.issue_comments', :vcr do + it 'returns comments for an issue' do + comments = @client.issue_comments('octokit/octokit.rb', 25) expect(comments).to be_kind_of Array assert_requested :get, github_url('/repos/octokit/octokit.rb/issues/25/comments') end end # .issue_comments - describe ".issue_comment", :vcr do - it "returns a single comment for an issue" do - comment = @client.issue_comment("octokit/octokit.rb", 1194690) - expect(comment.rels[:self].href).to eq("https://api.github.com/repos/octokit/octokit.rb/issues/comments/1194690") + describe '.issue_comment', :vcr do + it 'returns a single comment for an issue' do + comment = @client.issue_comment('octokit/octokit.rb', 1_194_690) + expect(comment.rels[:self].href).to eq('https://api.github.com/repos/octokit/octokit.rb/issues/comments/1194690') assert_requested :get, github_url('/repos/octokit/octokit.rb/issues/comments/1194690') end end # .issue_comment - describe ".add_assignees", :vcr do - it "adds assignees" do - issue = @client.add_assignees('tomb0y/wheelbarrow', 10, ["tomb0y"]) + describe '.add_assignees', :vcr do + it 'adds assignees' do + issue = @client.add_assignees('tomb0y/wheelbarrow', 10, ['tomb0y']) expect(issue.assignees.count).not_to be_zero - assert_requested :post, github_url("repos/tomb0y/wheelbarrow/issues/10/assignees") + assert_requested :post, github_url('repos/tomb0y/wheelbarrow/issues/10/assignees') end end # .add_assignees end diff --git a/spec/octokit/client/labels_spec.rb b/spec/octokit/client/labels_spec.rb index 82af07207..a38bb31c6 100644 --- a/spec/octokit/client/labels_spec.rb +++ b/spec/octokit/client/labels_spec.rb @@ -1,94 +1,95 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Labels do - before do Octokit.reset! @client = oauth_client end - describe ".labels", :vcr do - it "returns labels" do - labels = @client.labels("octokit/octokit.rb") + describe '.labels', :vcr do + it 'returns labels' do + labels = @client.labels('octokit/octokit.rb') expect(labels).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/labels") + assert_requested :get, github_url('/repos/octokit/octokit.rb/labels') end end # .labels - describe ".label", :vcr do - it "returns a single label" do - label = @client.label("octokit/octokit.rb", "V3 Addition") - expect(label.name).to eq("v3 addition") - assert_requested :get, github_url("/repos/octokit/octokit.rb/labels/V3%20Addition") + describe '.label', :vcr do + it 'returns a single label' do + label = @client.label('octokit/octokit.rb', 'V3 Addition') + expect(label.name).to eq('v3 addition') + assert_requested :get, github_url('/repos/octokit/octokit.rb/labels/V3%20Addition') end - it "returns a single label with URL characters" do + it 'returns a single label with URL characters' do @client.delete_label!(@test_repo, 'url-chars?') @client.add_label(@test_repo, 'url-chars?') label = @client.label(@test_repo, 'url-chars?') - expect(label.name).to eq("url-chars?") + expect(label.name).to eq('url-chars?') assert_requested :get, github_url("/repos/#{@test_repo}/labels/url-chars%3F") end end # .label - describe ".add_label", :vcr do - it "adds a label with a color" do + describe '.add_label', :vcr do + it 'adds a label with a color' do @client.delete_label!(@test_repo, 'test-label') - label = @client.add_label(@test_repo, "test-label", 'ededed') - expect(label.color).to eq("ededed") + label = @client.add_label(@test_repo, 'test-label', 'ededed') + expect(label.color).to eq('ededed') assert_requested :post, github_url("/repos/#{@test_repo}/labels") end - it "adds a label with default color" do + it 'adds a label with default color' do @client.delete_label!(@test_repo, 'test-label') - @client.add_label(@test_repo, "test-label") + @client.add_label(@test_repo, 'test-label') assert_requested :post, github_url("/repos/#{@test_repo}/labels") end end # .add_label - describe ".update_label", :vcr do - it "updates a label with a new color" do + describe '.update_label', :vcr do + it 'updates a label with a new color' do @client.delete_label!(@test_repo, 'test-label') label = @client.add_label(@test_repo, 'test-label', 'ededed') - @client.update_label(@test_repo, label.name, {:color => 'ffdd33'}) + @client.update_label(@test_repo, label.name, { color: 'ffdd33' }) assert_requested :patch, github_url("/repos/#{@test_repo}/labels/test-label") end - it "updates a label with URL characters with a new color" do + it 'updates a label with URL characters with a new color' do @client.delete_label!(@test_repo, 'url-chars?') label = @client.add_label(@test_repo, 'url-chars?', 'ededed') - @client.update_label(@test_repo, label.name, {:color => 'ffdd33'}) + @client.update_label(@test_repo, label.name, { color: 'ffdd33' }) assert_requested :patch, github_url("/repos/#{@test_repo}/labels/url-chars%3F") end end # .update_label - context "with issue" do + context 'with issue' do before do - @issue = @client.create_issue(@test_repo, "Issue for label test", "The body") + @issue = @client.create_issue(@test_repo, 'Issue for label test', 'The body') end - describe ".add_labels_to_an_issue", :vcr do - it "adds labels to a given issue" do + describe '.add_labels_to_an_issue', :vcr do + it 'adds labels to a given issue' do @client.add_labels_to_an_issue(@test_repo, @issue.number, ['bug']) assert_requested :post, github_url("/repos/#{@test_repo}/issues/#{@issue.number}/labels") end end # .add_labels_to_an_issue - describe ".labels_for_issue", :vcr do - it "returns all labels for a given issue" do + describe '.labels_for_issue', :vcr do + it 'returns all labels for a given issue' do labels = @client.labels_for_issue(@test_repo, @issue.number) expect(labels).to be_kind_of Array assert_requested :get, github_url("/repos/#{@test_repo}/issues/#{@issue.number}/labels") end end # .labels_for_issue - describe ".remove_label", :vcr do - it "removes a label from the specified issue" do + describe '.remove_label', :vcr do + it 'removes a label from the specified issue' do @client.add_labels_to_an_issue(@test_repo, @issue.number, ['bug']) @client.remove_label(@test_repo, @issue.number, 'bug') assert_requested :delete, github_url("/repos/#{@test_repo}/issues/#{@issue.number}/labels/bug") end - it "removes a label with URL characters from the specified issue" do + it 'removes a label with URL characters from the specified issue' do @client.delete_label!(@test_repo, 'url-chars?') label = @client.add_label(@test_repo, 'url-chars?') @client.add_labels_to_an_issue(@test_repo, @issue.number, ['url-chars?']) @@ -98,47 +99,47 @@ end end # .remove_label - describe ".remove_all_labels", :vcr do - it "removes all labels from the specified issue" do + describe '.remove_all_labels', :vcr do + it 'removes all labels from the specified issue' do @client.remove_all_labels(@test_repo, @issue.number) assert_requested :delete, github_url("/repos/#{@test_repo}/issues/#{@issue.number}/labels") end end # .remove_all_labels - describe ".replace_all_labels", :vcr do - it "replaces all labels for an issue" do - @client.replace_all_labels(@test_repo, @issue.number, ['bug', 'pdi']) + describe '.replace_all_labels', :vcr do + it 'replaces all labels for an issue' do + @client.replace_all_labels(@test_repo, @issue.number, %w[bug pdi]) assert_requested :put, github_url("/repos/#{@test_repo}/issues/#{@issue.number}/labels") end end # .replace_all_labels end # with issue - describe ".labels_for_milestone", :vcr do - it "returns all labels for a repository" do + describe '.labels_for_milestone', :vcr do + it 'returns all labels for a repository' do labels = @client.labels_for_milestone('octokit/octokit.rb', 2) expect(labels).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/milestones/2/labels") + assert_requested :get, github_url('/repos/octokit/octokit.rb/milestones/2/labels') end end # .labels_for_milestone - describe ".delete_label!", :vcr do - context "with label with spaces" do + describe '.delete_label!', :vcr do + context 'with label with spaces' do before do - @label = @client.label(@test_repo, "good first issue") + @label = @client.label(@test_repo, 'good first issue') end after do @client.add_label(@test_repo, @label.name, @label.color) end - it "deletes a label from the repository" do + it 'deletes a label from the repository' do @client.delete_label!(@test_repo, @label.name) assert_requested :delete, github_url("/repos/#{@test_repo}/labels/good%20first%20issue") end end - it "deletes a label with URL characters from the repository" do - @client.delete_label!(@test_repo, "url-chars?") + it 'deletes a label with URL characters from the repository' do + @client.delete_label!(@test_repo, 'url-chars?') assert_requested :delete, github_url("/repos/#{@test_repo}/labels/url-chars%3F") end end # .delete_label! diff --git a/spec/octokit/client/legacy_search_spec.rb b/spec/octokit/client/legacy_search_spec.rb index b48ef0155..caab8d92d 100644 --- a/spec/octokit/client/legacy_search_spec.rb +++ b/spec/octokit/client/legacy_search_spec.rb @@ -1,40 +1,40 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::LegacySearch do - before do Octokit.reset! @client = oauth_client end - describe ".legacy_search_issues", :vcr do - it "returns matching issues" do - issues = @client.legacy_search_issues("sferik/rails_admin", "activerecord") + describe '.legacy_search_issues', :vcr do + it 'returns matching issues' do + issues = @client.legacy_search_issues('sferik/rails_admin', 'activerecord') expect(issues).not_to be_empty - assert_requested :get, github_url("/legacy/issues/search/sferik/rails_admin/open/activerecord") + assert_requested :get, github_url('/legacy/issues/search/sferik/rails_admin/open/activerecord') end end # .legacy_search_issues - describe ".legacy_search_repos", :vcr do - it "returns matching repositories" do - repositories = @client.legacy_search_repositories("One40Proof") + describe '.legacy_search_repos', :vcr do + it 'returns matching repositories' do + repositories = @client.legacy_search_repositories('One40Proof') expect(repositories).not_to be_empty - assert_requested :get, github_url("/legacy/repos/search/One40Proof") + assert_requested :get, github_url('/legacy/repos/search/One40Proof') end end # .legacy_search_repos - describe ".legacy_search_users" do - it "returns matching username", :vcr do - users = @client.legacy_search_users("sferik") - expect(users.first.username).to eq("sferik") - assert_requested :get, github_url("/legacy/user/search/sferik") + describe '.legacy_search_users' do + it 'returns matching username', :vcr do + users = @client.legacy_search_users('sferik') + expect(users.first.username).to eq('sferik') + assert_requested :get, github_url('/legacy/user/search/sferik') end - it "should not raise URI::InvalidURIError and returns success" do - stub_get("https://api.github.com/legacy/user/search/followers:>0") - expect { @client.legacy_search_users("followers:>0") }.not_to raise_error - assert_requested :get, github_url("/legacy/user/search/followers:%3E0") + it 'should not raise URI::InvalidURIError and returns success' do + stub_get('https://api.github.com/legacy/user/search/followers:>0') + expect { @client.legacy_search_users('followers:>0') }.not_to raise_error + assert_requested :get, github_url('/legacy/user/search/followers:%3E0') end end # .legacy_searcy_users - end diff --git a/spec/octokit/client/licenses_spec.rb b/spec/octokit/client/licenses_spec.rb index c926a154e..fc82770c5 100644 --- a/spec/octokit/client/licenses_spec.rb +++ b/spec/octokit/client/licenses_spec.rb @@ -1,26 +1,27 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Licenses do - - describe ".licenses", :vcr do - it "returns all licenses" do - licenses = Octokit.licenses :accept => "application/vnd.github.drax-preview+json" + describe '.licenses', :vcr do + it 'returns all licenses' do + licenses = Octokit.licenses accept: 'application/vnd.github.drax-preview+json' expect(licenses).to be_kind_of Array end end - describe ".license", :vcr do - it "returns a particular license" do - license = Octokit.license 'mit', :accept => "application/vnd.github.drax-preview+json" - expect(license.name).to eq("MIT License") + describe '.license', :vcr do + it 'returns a particular license' do + license = Octokit.license 'mit', accept: 'application/vnd.github.drax-preview+json' + expect(license.name).to eq('MIT License') end end - describe ".repository_license_contents", :vcr do + describe '.repository_license_contents', :vcr do it "returns a repository's license file" do - options = { :accept => "application/vnd.github.drax-preview+json" } + options = { accept: 'application/vnd.github.drax-preview+json' } response = Octokit.repository_license_contents 'benbalter/licensee', options - expect(response.license.key).to eql("mit") + expect(response.license.key).to eql('mit') content = Base64.decode64 response.content expect(content).to match(/MIT/) end diff --git a/spec/octokit/client/markdown_spec.rb b/spec/octokit/client/markdown_spec.rb index c166110f5..2e99ddfe1 100644 --- a/spec/octokit/client/markdown_spec.rb +++ b/spec/octokit/client/markdown_spec.rb @@ -1,20 +1,20 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Markdown do - before do Octokit.reset! @client = oauth_client end - describe ".markdown", :vcr do - it "renders markdown" do - text = "This is for #111" - markdown = @client.markdown(text, :context => 'octokit/octokit.rb', :mode => 'gfm') + describe '.markdown', :vcr do + it 'renders markdown' do + text = 'This is for #111' + markdown = @client.markdown(text, context: 'octokit/octokit.rb', mode: 'gfm') expect(markdown).to include('https://github.com/octokit/octokit.rb/issues/111') assert_requested :post, github_url('/markdown') end end # .markdown - end diff --git a/spec/octokit/client/marketplace_spec.rb b/spec/octokit/client/marketplace_spec.rb index 392cb9f96..7eabc3edd 100644 --- a/spec/octokit/client/marketplace_spec.rb +++ b/spec/octokit/client/marketplace_spec.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Marketplace do before(:each) do Octokit.reset! @client = oauth_client - @jwt_client = Octokit::Client.new(:bearer_token => new_jwt_token) + @jwt_client = Octokit::Client.new(bearer_token: new_jwt_token) use_vcr_placeholder_for(@jwt_client.bearer_token, '') end @@ -12,35 +14,35 @@ Octokit.reset! end - describe ".list_plans", :vcr do - it "returns plans for a marketplace listing" do + describe '.list_plans', :vcr do + it 'returns plans for a marketplace listing' do plans = @jwt_client.list_plans expect(plans).to be_kind_of Array - assert_requested :get, github_url("/marketplace_listing/plans") + assert_requested :get, github_url('/marketplace_listing/plans') end end # .list_plans - describe ".list_accounts_for_plan", :vcr do - it "returns accounts for a given plan" do + describe '.list_accounts_for_plan', :vcr do + it 'returns accounts for a given plan' do plans = @jwt_client.list_accounts_for_plan(7) expect(plans).to be_kind_of Array - assert_requested :get, github_url("/marketplace_listing/plans/7/accounts") + assert_requested :get, github_url('/marketplace_listing/plans/7/accounts') end end # .list_accounts_for_plan - describe ".plan_for_account", :vcr do - it "returns the plan for a given account" do + describe '.plan_for_account', :vcr do + it 'returns the plan for a given account' do plans = @jwt_client.plan_for_account(1) expect(plans).to be_kind_of Sawyer::Resource - assert_requested :get, github_url("/marketplace_listing/accounts/1") + assert_requested :get, github_url('/marketplace_listing/accounts/1') end end # .plan_for_account - describe ".marketplace_purchases", :vcr do - it "returns marketplace purchases for user" do + describe '.marketplace_purchases', :vcr do + it 'returns marketplace purchases for user' do plans = @client.marketplace_purchases expect(plans).to be_kind_of Array - assert_requested :get, github_url("/user/marketplace_purchases") + assert_requested :get, github_url('/user/marketplace_purchases') end end # .marketplace_purchases end diff --git a/spec/octokit/client/meta_spec.rb b/spec/octokit/client/meta_spec.rb index 4bfff5fbd..e250a988b 100644 --- a/spec/octokit/client/meta_spec.rb +++ b/spec/octokit/client/meta_spec.rb @@ -1,13 +1,13 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Meta do - - describe ".github_meta", :vcr do - it "returns meta information about github" do + describe '.github_meta', :vcr do + it 'returns meta information about github' do github_meta = oauth_client.github_meta expect(github_meta.git).to be - assert_requested :get, github_url("/meta") + assert_requested :get, github_url('/meta') end end # .github_meta - end diff --git a/spec/octokit/client/milestones_spec.rb b/spec/octokit/client/milestones_spec.rb index 844eda2c1..302cfe367 100644 --- a/spec/octokit/client/milestones_spec.rb +++ b/spec/octokit/client/milestones_spec.rb @@ -1,27 +1,28 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Milestones do - before do Octokit.reset! @client = oauth_client end - describe ".list_milestones", :vcr do - it "lists milestones belonging to repository" do + describe '.list_milestones', :vcr do + it 'lists milestones belonging to repository' do milestones = @client.list_milestones(@test_repo) expect(milestones).to be_kind_of Array assert_requested :get, github_url("/repos/#{@test_repo}/milestones") end - it "lists milestones belonging to repository using id of repository" do + it 'lists milestones belonging to repository using id of repository' do milestones = @client.list_milestones(@test_repo_id) expect(milestones).to be_kind_of Array assert_requested :get, github_url("/repositories/#{@test_repo_id}/milestones") end end # .list_milestones - context "with milestone" do + context 'with milestone' do before(:each) do name = "Test Milestone #{Time.now.to_i}" @milestone = @client.create_milestone(@test_repo, name) @@ -31,29 +32,29 @@ @client.delete_milestone @test_repo, @milestone.number end - describe ".milestone", :vcr do - it "gets a single milestone belonging to repository" do + describe '.milestone', :vcr do + it 'gets a single milestone belonging to repository' do @client.milestone @test_repo, @milestone.number assert_requested :get, github_url("/repos/#{@test_repo}/milestones/#{@milestone.number}") end end # .milestone - describe ".create_milestone", :vcr do - it "creates a milestone" do + describe '.create_milestone', :vcr do + it 'creates a milestone' do expect(@milestone.title).not_to be_nil assert_requested :post, github_url("/repos/#{@test_repo}/milestones") end end # .create_milestone - describe ".update_milestone", :vcr do - it "updates a milestone" do - @client.update_milestone(@test_repo, @milestone.number, {:description => "Add support for API v3"}) + describe '.update_milestone', :vcr do + it 'updates a milestone' do + @client.update_milestone(@test_repo, @milestone.number, { description: 'Add support for API v3' }) assert_requested :patch, github_url("/repos/#{@test_repo}/milestones/#{@milestone.number}") end end # .update_milestone - describe ".delete_milestone", :vcr do - it "deletes a milestone from a repository" do + describe '.delete_milestone', :vcr do + it 'deletes a milestone from a repository' do @client.delete_milestone(@test_repo, @milestone.number) assert_requested :delete, github_url("/repos/#{@test_repo}/milestones/#{@milestone.number}") end diff --git a/spec/octokit/client/notifications_spec.rb b/spec/octokit/client/notifications_spec.rb index 16f226727..a2dc9a647 100644 --- a/spec/octokit/client/notifications_spec.rb +++ b/spec/octokit/client/notifications_spec.rb @@ -1,83 +1,84 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Notifications do - before do Octokit.reset! @client = oauth_client end - describe ".notifications", :vcr do - it "lists the notifications for the current user" do + describe '.notifications', :vcr do + it 'lists the notifications for the current user' do notifications = @client.notifications expect(notifications).to be_kind_of Array - assert_requested :get, github_url("/notifications") + assert_requested :get, github_url('/notifications') end end # .notifications - describe ".repository_notifications", :vcr do - it "lists all notifications for a repository" do + describe '.repository_notifications', :vcr do + it 'lists all notifications for a repository' do notifications = @client.repository_notifications(@test_repo) expect(notifications).to be_kind_of Array assert_requested :get, github_url("/repos/#{@test_repo}/notifications") end end # .repository_notifications - describe ".mark_notifications_as_read", :vcr do - it "returns true when notifications are marked as read" do + describe '.mark_notifications_as_read', :vcr do + it 'returns true when notifications are marked as read' do result = @client.mark_notifications_as_read expect(result).to be true - assert_requested :put, github_url("/notifications") + assert_requested :put, github_url('/notifications') end end # .mark_notifications_as_read - describe ".mark_repository_notifications_as_read", :vcr do - it "returns true when notifications for a repo are marked as read" do + describe '.mark_repository_notifications_as_read', :vcr do + it 'returns true when notifications for a repo are marked as read' do result = @client.mark_repository_notifications_as_read(@test_repo) expect(result).to be true assert_requested :put, github_url("/repos/#{@test_repo}/notifications") end end # .mark_repository_notifications_as_read - context "with thread" do + context 'with thread' do before(:each) do - @thread_id = @client.repository_notifications(@test_repo, :all => true).last.id + @thread_id = @client.repository_notifications(@test_repo, all: true).last.id end - describe ".thread_notifications", :vcr do - it "returns notifications for a specific thread" do + describe '.thread_notifications', :vcr do + it 'returns notifications for a specific thread' do @client.thread_notifications(@thread_id) assert_requested :get, github_url("/notifications/threads/#{@thread_id}") end end # .thread_notifications - describe ".mark_thread_as_read", :vcr do - it "marks a thread as read" do + describe '.mark_thread_as_read', :vcr do + it 'marks a thread as read' do @client.mark_thread_as_read(@thread_id) assert_requested :patch, github_url("/notifications/threads/#{@thread_id}") end end # .mark_thread_as_read - context "with subscription", :vcr do + context 'with subscription', :vcr do before do - @client.update_thread_subscription(@thread_id, :subscribed => true) + @client.update_thread_subscription(@thread_id, subscribed: true) end - describe ".thread_subscription" do - it "returns a thread subscription" do + describe '.thread_subscription' do + it 'returns a thread subscription' do @client.thread_subscription(@thread_id) assert_requested :get, github_url("/notifications/threads/#{@thread_id}/subscription") end end # .thread_subscription - describe ".update_thread_subscription" do - it "updates a thread subscription" do + describe '.update_thread_subscription' do + it 'updates a thread subscription' do assert_requested :put, github_url("/notifications/threads/#{@thread_id}/subscription") end end # .update_thread_subscription - describe ".delete_thread_subscription" do - it "returns true with successful thread deletion" do + describe '.delete_thread_subscription' do + it 'returns true with successful thread deletion' do @client.delete_thread_subscription(@thread_id) assert_requested :delete, github_url("/notifications/threads/#{@thread_id}/subscription") end diff --git a/spec/octokit/client/oauth_applications_spec.rb b/spec/octokit/client/oauth_applications_spec.rb index 771c070f5..3777491ef 100644 --- a/spec/octokit/client/oauth_applications_spec.rb +++ b/spec/octokit/client/oauth_applications_spec.rb @@ -29,7 +29,7 @@ path = "/applications/#{test_github_client_id}/token" expect(WebMock).to have_requested(:post, github_url(path)).with( - basic_auth: [test_github_client_id, test_github_client_secret], + basic_auth: [test_github_client_id, test_github_client_secret] ) end @@ -38,22 +38,22 @@ path = "/applications/#{test_github_client_id}/token" expect(WebMock).to have_requested(:post, github_url(path)).with( - basic_auth: [test_github_client_id, test_github_client_secret], + basic_auth: [test_github_client_id, test_github_client_secret] ) end - it "works in Enterprise mode" do - api_endpoint = "https://gh-enterprise.com/api/v3" - client_id = "abcde12345fghij67890" - client_secret = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" - token = "25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8" + it 'works in Enterprise mode' do + api_endpoint = 'https://gh-enterprise.com/api/v3' + client_id = 'abcde12345fghij67890' + client_secret = 'abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd' + token = '25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8' path = File.join(api_endpoint, "/applications/#{client_id}/token") client = Octokit::Client.new( - client_id: client_id, + client_id: client_id, client_secret: client_secret, - api_endpoint: api_endpoint + api_endpoint: api_endpoint ) request = stub_request(:post, path).with(basic_auth: [client_id, client_secret]) @@ -69,7 +69,7 @@ path = "/applications/#{test_github_client_id}/token" expect(WebMock).to have_requested(:patch, github_url(path)).with( - basic_auth: [test_github_client_id, test_github_client_secret], + basic_auth: [test_github_client_id, test_github_client_secret] ) end @@ -78,22 +78,22 @@ path = "/applications/#{test_github_client_id}/token" expect(WebMock).to have_requested(:patch, github_url(path)).with( - basic_auth: [test_github_client_id, test_github_client_secret], + basic_auth: [test_github_client_id, test_github_client_secret] ) end - it "works in Enterprise mode" do - api_endpoint = "https://gh-enterprise.com/api/v3" - client_id = "abcde12345fghij67890" - client_secret = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" - token = "25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8" + it 'works in Enterprise mode' do + api_endpoint = 'https://gh-enterprise.com/api/v3' + client_id = 'abcde12345fghij67890' + client_secret = 'abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd' + token = '25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8' path = File.join(api_endpoint, "/applications/#{client_id}/token") client = Octokit::Client.new( - client_id: client_id, + client_id: client_id, client_secret: client_secret, - api_endpoint: api_endpoint + api_endpoint: api_endpoint ) request = stub_request(:patch, path).with(basic_auth: [client_id, client_secret]) @@ -109,7 +109,7 @@ path = "/applications/#{test_github_client_id}/token" expect(WebMock).to have_requested(:delete, github_url(path)).with( - basic_auth: [test_github_client_id, test_github_client_secret], + basic_auth: [test_github_client_id, test_github_client_secret] ) end @@ -118,7 +118,7 @@ path = "/applications/#{test_github_client_id}/token" expect(WebMock).to have_requested(:delete, github_url(path)).with( - basic_auth: [test_github_client_id, test_github_client_secret], + basic_auth: [test_github_client_id, test_github_client_secret] ) end @@ -127,22 +127,22 @@ path = "/applications/#{test_github_client_id}/token" expect(WebMock).to have_requested(:delete, github_url(path)).with( - basic_auth: [test_github_client_id, test_github_client_secret], + basic_auth: [test_github_client_id, test_github_client_secret] ) end - it "works in Enterprise mode" do - api_endpoint = "https://gh-enterprise.com/api/v3" - client_id = "abcde12345fghij67890" - client_secret = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd" - token = "25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8" + it 'works in Enterprise mode' do + api_endpoint = 'https://gh-enterprise.com/api/v3' + client_id = 'abcde12345fghij67890' + client_secret = 'abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd' + token = '25f94a2a5c7fbaf499c665bc73d67c1c87e496da8985131633ee0a95819db2e8' path = File.join(api_endpoint, "/applications/#{client_id}/token") client = Octokit::Client.new( - client_id: client_id, + client_id: client_id, client_secret: client_secret, - api_endpoint: api_endpoint + api_endpoint: api_endpoint ) request = stub_request(:delete, path).with(basic_auth: [client_id, client_secret]) @@ -158,7 +158,7 @@ path = "/applications/#{test_github_client_id}/grant" expect(WebMock).to have_requested(:delete, github_url(path)).with( - basic_auth: [test_github_client_id, test_github_client_secret], + basic_auth: [test_github_client_id, test_github_client_secret] ) end end diff --git a/spec/octokit/client/objects_spec.rb b/spec/octokit/client/objects_spec.rb index b2dbfa9ea..e41a574af 100644 --- a/spec/octokit/client/objects_spec.rb +++ b/spec/octokit/client/objects_spec.rb @@ -1,72 +1,72 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Objects do - before do Octokit.reset! @client = oauth_client end - describe ".tree", :vcr do - it "gets a tree" do - result = @client.tree("sferik/rails_admin", "3cdfabd973bc3caac209cba903cfdb3bf6636bcd") - expect(result.sha).to eq("3cdfabd973bc3caac209cba903cfdb3bf6636bcd") - expect(result.tree.first.path).to eq(".gitignore") - assert_requested :get, github_url("/repos/sferik/rails_admin/git/trees/3cdfabd973bc3caac209cba903cfdb3bf6636bcd") + describe '.tree', :vcr do + it 'gets a tree' do + result = @client.tree('sferik/rails_admin', '3cdfabd973bc3caac209cba903cfdb3bf6636bcd') + expect(result.sha).to eq('3cdfabd973bc3caac209cba903cfdb3bf6636bcd') + expect(result.tree.first.path).to eq('.gitignore') + assert_requested :get, github_url('/repos/sferik/rails_admin/git/trees/3cdfabd973bc3caac209cba903cfdb3bf6636bcd') end - it "gets a tree recursively" do - result = @client.tree("sferik/rails_admin", "3cdfabd973bc3caac209cba903cfdb3bf6636bcd", :recursive => true) - expect(result.sha).to eq("3cdfabd973bc3caac209cba903cfdb3bf6636bcd") - expect(result.tree.first.path).to eq(".gitignore") - assert_requested :get, github_url("/repos/sferik/rails_admin/git/trees/3cdfabd973bc3caac209cba903cfdb3bf6636bcd?recursive=true") + it 'gets a tree recursively' do + result = @client.tree('sferik/rails_admin', '3cdfabd973bc3caac209cba903cfdb3bf6636bcd', recursive: true) + expect(result.sha).to eq('3cdfabd973bc3caac209cba903cfdb3bf6636bcd') + expect(result.tree.first.path).to eq('.gitignore') + assert_requested :get, github_url('/repos/sferik/rails_admin/git/trees/3cdfabd973bc3caac209cba903cfdb3bf6636bcd?recursive=true') end end # .tree - describe ".create_tree", :vcr do - it "creates a tree" do - @client.create_tree(@test_repo, [ { "path" => "wynning.rb", "mode" => "100644", "type" => "blob", :content => "require 'fun'"} ]) + describe '.create_tree', :vcr do + it 'creates a tree' do + @client.create_tree(@test_repo, [{ 'path' => 'wynning.rb', 'mode' => '100644', 'type' => 'blob', :content => "require 'fun'" }]) assert_requested :post, github_url("/repos/#{@test_repo}/git/trees") end end # .create_tree - describe ".blob", :vcr do - it "returns a blob" do - blob = @client.blob("sferik/rails_admin", "94616fa57520ac8147522c7cf9f03d555595c5ea") - expect(blob.sha).to eq("94616fa57520ac8147522c7cf9f03d555595c5ea") - assert_requested :get, github_url("/repos/sferik/rails_admin/git/blobs/94616fa57520ac8147522c7cf9f03d555595c5ea") + describe '.blob', :vcr do + it 'returns a blob' do + blob = @client.blob('sferik/rails_admin', '94616fa57520ac8147522c7cf9f03d555595c5ea') + expect(blob.sha).to eq('94616fa57520ac8147522c7cf9f03d555595c5ea') + assert_requested :get, github_url('/repos/sferik/rails_admin/git/blobs/94616fa57520ac8147522c7cf9f03d555595c5ea') end end # .blob - describe ".create_blob", :vcr do - it "creates a blob" do - @client.create_blob(@test_repo, "content") + describe '.create_blob', :vcr do + it 'creates a blob' do + @client.create_blob(@test_repo, 'content') assert_requested :post, github_url("/repos/#{@test_repo}/git/blobs") end end # .create_blob - describe ".tag", :vcr do - it "returns a tag" do - @client.tag("octokit/octokit.rb", "23aad20633f4d2981b1c7209a800db3014774e96") - assert_requested :get, github_url("/repos/octokit/octokit.rb/git/tags/23aad20633f4d2981b1c7209a800db3014774e96") + describe '.tag', :vcr do + it 'returns a tag' do + @client.tag('octokit/octokit.rb', '23aad20633f4d2981b1c7209a800db3014774e96') + assert_requested :get, github_url('/repos/octokit/octokit.rb/git/tags/23aad20633f4d2981b1c7209a800db3014774e96') end end # .tag - describe ".create_tag", :vcr do - it "creates a tag" do + describe '.create_tag', :vcr do + it 'creates a tag' do sha = @client.commits(@test_repo).last.sha tag = @client.create_tag( @test_repo, - "v9000.0.0", + 'v9000.0.0', "Version 9000\n", sha, - "commit", - "Wynn Netherland", - "wynn.netherland@gmail.com", - "2012-06-03T17:03:11-07:00" + 'commit', + 'Wynn Netherland', + 'wynn.netherland@gmail.com', + '2012-06-03T17:03:11-07:00' ) - expect(tag.tag).to eq("v9000.0.0") + expect(tag.tag).to eq('v9000.0.0') assert_requested :post, github_url("/repos/#{@test_repo}/git/tags") end end # .create_tag - end diff --git a/spec/octokit/client/organizations_spec.rb b/spec/octokit/client/organizations_spec.rb index fd881d14a..286fcb3c7 100644 --- a/spec/octokit/client/organizations_spec.rb +++ b/spec/octokit/client/organizations_spec.rb @@ -1,258 +1,259 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Organizations do - before do Octokit.reset! @client = oauth_client end - describe ".organization", :vcr do - it "returns an organization" do - organization = @client.organization("codeforamerica") - expect(organization.name).to eq("Code for America") - assert_requested :get, github_url("/orgs/codeforamerica") + describe '.organization', :vcr do + it 'returns an organization' do + organization = @client.organization('codeforamerica') + expect(organization.name).to eq('Code for America') + assert_requested :get, github_url('/orgs/codeforamerica') end end # .organization - describe ".update_organization", :vcr do - it "updates an organization" do - organization = @client.update_organization(test_github_org, {:name => "API Playground"}) + describe '.update_organization', :vcr do + it 'updates an organization' do + organization = @client.update_organization(test_github_org, { name: 'API Playground' }) expect(organization.login).to eq test_github_org assert_requested :patch, github_url("/orgs/#{test_github_org}") end end # .update_organization - describe ".organizations", :vcr do - it "returns all organizations for a user" do + describe '.organizations', :vcr do + it 'returns all organizations for a user' do organizations = @client.organizations(test_github_login) expect(organizations).to be_kind_of Array assert_requested :get, github_url("/users/#{test_github_login}/orgs") end - it "returns all organizations for the authenticated user" do + it 'returns all organizations for the authenticated user' do organizations = @client.organizations expect(organizations).to be_kind_of Array - assert_requested :get, github_url("/user/orgs") + assert_requested :get, github_url('/user/orgs') end end # .organizations - describe ".all_organizations", :vcr do - it "paginates organizations on GitHub" do + describe '.all_organizations', :vcr do + it 'paginates organizations on GitHub' do orgs = Octokit.all_organizations expect(orgs).to be_kind_of Array - assert_requested :get, github_url("organizations") + assert_requested :get, github_url('organizations') end end # .all_organizations - describe ".organization_repositories", :vcr do - it "returns all public repositories for an organization" do - repositories = @client.organization_repositories("codeforamerica") + describe '.organization_repositories', :vcr do + it 'returns all public repositories for an organization' do + repositories = @client.organization_repositories('codeforamerica') expect(repositories).to be_kind_of Array - assert_requested :get, github_url("/orgs/codeforamerica/repos") + assert_requested :get, github_url('/orgs/codeforamerica/repos') end end # .organization_repositories - describe ".organization_members", :vcr do - it "returns all public members of an organization" do - users = @client.organization_members("codeforamerica") + describe '.organization_members', :vcr do + it 'returns all public members of an organization' do + users = @client.organization_members('codeforamerica') expect(users).to be_kind_of Array - assert_requested :get, github_url("/orgs/codeforamerica/members") + assert_requested :get, github_url('/orgs/codeforamerica/members') end end # .organization_members - describe ".organization_member?", :vcr do - it "checks organization membership" do + describe '.organization_member?', :vcr do + it 'checks organization membership' do is_member = @client.organization_member?(test_github_org, test_github_login) assert_requested :get, github_url("/orgs/#{test_github_org}/members/#{test_github_login}") expect(is_member).to be true end end # .organization_member? - describe ".organization_public_members", :vcr do - it "lists public members" do - users = @client.organization_public_members("codeforamerica") + describe '.organization_public_members', :vcr do + it 'lists public members' do + users = @client.organization_public_members('codeforamerica') expect(users).to be_kind_of Array - assert_requested :get, github_url("/orgs/codeforamerica/public_members") + assert_requested :get, github_url('/orgs/codeforamerica/public_members') end end - describe ".organization_invitations", :vcr do - it "lists pending organization invitations" do + describe '.organization_invitations', :vcr do + it 'lists pending organization invitations' do @client.organization_invitations(test_github_org) assert_requested :get, github_url("/orgs/#{test_github_org}/invitations") end end # .organization_invitations - describe ".outside_collaborators", :vcr do - it "lists outside collaborators for an organization" do + describe '.outside_collaborators', :vcr do + it 'lists outside collaborators for an organization' do @client.outside_collaborators(test_github_org) assert_requested :get, github_url("/orgs/#{test_github_org}/outside_collaborators") end end # .outside_collaborators - describe ".remove_outside_collaborator", :vcr do - it "removes the outside collaborator from an organization" do + describe '.remove_outside_collaborator', :vcr do + it 'removes the outside collaborator from an organization' do stub_delete github_url("/orgs/#{test_github_org}/outside_collaborators/#{test_github_login}") @client.remove_outside_collaborator(test_github_org, test_github_login) assert_requested :delete, github_url("/orgs/#{test_github_org}/outside_collaborators/#{test_github_login}") end end # .remove_outside_collaborator - describe ".convert_to_outside_collaborator", :vcr do - it "converts an organization member to an outside collaborator" do + describe '.convert_to_outside_collaborator', :vcr do + it 'converts an organization member to an outside collaborator' do stub_put github_url("orgs/#{test_github_org}/outside_collaborators/#{test_github_login}") @client.convert_to_outside_collaborator(test_github_org, test_github_login) assert_requested :put, github_url("orgs/#{test_github_org}/outside_collaborators/#{test_github_login}") end end # .convert_to_outside_collaborator - describe ".organization_teams", :vcr do - it "returns all teams for an organization" do + describe '.organization_teams', :vcr do + it 'returns all teams for an organization' do teams = @client.organization_teams(test_github_org) expect(teams).to be_kind_of Array assert_requested :get, github_url("/orgs/#{test_github_org}/teams") end end # .organization_teams - describe ".child_teams", :vcr do - it "returns all child teams for the team" do + describe '.child_teams', :vcr do + it 'returns all child teams for the team' do child_teams = @client.child_teams(test_github_team_id, accept: Octokit::Preview::PREVIEW_TYPES[:nested_teams]) expect(child_teams).to be_kind_of Array assert_requested :get, github_url("/teams/#{test_github_team_id}/teams") end end # .child_teams - context "with team", :order => :defined do + context 'with team', order: :defined do before(:each) do @team_name = "Test Team #{Time.now.to_i}" - @team = @client.create_team(test_github_org, {:name => @team_name}) - use_vcr_placeholder_for(@team.id, "") + @team = @client.create_team(test_github_org, { name: @team_name }) + use_vcr_placeholder_for(@team.id, '') end after(:each) do @client.delete_team(@team.id) end - describe ".create_team", :vcr do - it "creates a team" do + describe '.create_team', :vcr do + it 'creates a team' do assert_requested :post, github_url("/orgs/#{test_github_org}/teams") end end # .create_team - describe ".team", :vcr do - it "returns a team" do + describe '.team', :vcr do + it 'returns a team' do team = @client.team(@team.id) expect(team.id).to eq(@team.id) assert_requested :get, github_url("/teams/#{@team.id}") end end # .team - describe ".team_by_name", :vcr do - it "returns a team found by name" do + describe '.team_by_name', :vcr do + it 'returns a team found by name' do team = @client.team_by_name(test_github_org, @team.slug) expect(team.id).to eq(@team.id) assert_requested :get, github_url("/orgs/#{test_github_org}/teams/#{@team.slug}") end end # .team_by_name - describe ".update_team", :vcr do - it "updates a team" do - @client.update_team(@team.id, :name => "API Jedi") + describe '.update_team', :vcr do + it 'updates a team' do + @client.update_team(@team.id, name: 'API Jedi') assert_requested :patch, github_url("/teams/#{@team.id}") end end # .update_team - describe ".team_members", :vcr do - it "returns team members" do + describe '.team_members', :vcr do + it 'returns team members' do users = @client.team_members(@team.id) expect(users).to be_kind_of Array assert_requested :get, github_url("/teams/#{@team.id}/members") end end # .team_members - describe ".add_team_member", :vcr do - it "adds a team member" do + describe '.add_team_member', :vcr do + it 'adds a team member' do @client.add_team_member(@team.id, test_github_repository) assert_requested :put, github_url("/teams/#{@team.id}/members/#{test_github_repository}") end end # .add_team_member - describe ".remove_team_member", :vcr do - it "removes a team member" do - @client.remove_team_member(@team.id, "api-padawan") + describe '.remove_team_member', :vcr do + it 'removes a team member' do + @client.remove_team_member(@team.id, 'api-padawan') assert_requested :delete, github_url("/teams/#{@team.id}/members/api-padawan") end end # .remove_team_member - describe ".team_member?", :vcr do - it "checks if a user is member of a team" do + describe '.team_member?', :vcr do + it 'checks if a user is member of a team' do @client.team_member?(@team.id, 'api-padawan') assert_requested :get, github_url("/teams/#{@team.id}/members/api-padawan") end end # .team_member? - describe ".team_invitations", :vcr do - it "lists pending team invitations" do + describe '.team_invitations', :vcr do + it 'lists pending team invitations' do @client.team_invitations(@team.id) assert_requested :get, github_url("/teams/#{@team.id}/invitations") end end # .team_invitations - describe ".team_repositories", :vcr do - it "returns team repositories" do + describe '.team_repositories', :vcr do + it 'returns team repositories' do repositories = @client.team_repositories(@team.id) expect(repositories).to be_kind_of Array assert_requested :get, github_url("/teams/#{@team.id}/repos") end end # .team_repositories - describe ".add_team_repository", :vcr do - it "adds a team repository" do + describe '.add_team_repository', :vcr do + it 'adds a team repository' do @client.add_team_repository(@team.id, @test_org_repo) assert_requested :put, github_url("/teams/#{@team.id}/repos/#{@test_org_repo}") end end # .add_team_repository - describe ".team_repository?", :vcr do - it "checks if a repo is managed by a specific team" do + describe '.team_repository?', :vcr do + it 'checks if a repo is managed by a specific team' do is_team_repo = @client.team_repository?(@team.id, "#{test_github_org}/notateamrepository") expect(is_team_repo).to be false assert_requested :get, github_url("/teams/#{@team.id}/repos/#{test_github_org}/notateamrepository") end end - describe ".remove_team_repository", :vcr do - it "removes a team repository" do + describe '.remove_team_repository', :vcr do + it 'removes a team repository' do @client.remove_team_repository @team.id, @test_org_repo assert_requested :delete, github_url("/teams/#{@team.id}/repos/#{@test_org_repo}") end - end #.remove_team_repository + end # .remove_team_repository - describe ".delete_team", :vcr do - it "deletes a team" do + describe '.delete_team', :vcr do + it 'deletes a team' do @client.delete_team(@team.id) assert_requested :delete, github_url("/teams/#{@team.id}") end end # .delete_team end # with team - context "public org members", :order => :defined do - describe ".unpublicize_membership", :vcr do - it "unpublicizes membership" do + context 'public org members', order: :defined do + describe '.unpublicize_membership', :vcr do + it 'unpublicizes membership' do @client.unpublicize_membership test_github_org, test_github_login assert_requested :delete, github_url("/orgs/#{test_github_org}/public_members/#{test_github_login}") end end # .unpublicize_membership - describe ".publicize_membership", :vcr do - it "publicizes membership" do + describe '.publicize_membership', :vcr do + it 'publicizes membership' do @client.publicize_membership test_github_org, test_github_login assert_requested :put, github_url("/orgs/#{test_github_org}/public_members/#{test_github_login}") end end # .publicize_membership - describe ".organization_public_member?", :vcr do - it "checks publicized org membership" do + describe '.organization_public_member?', :vcr do + it 'checks publicized org membership' do is_member = @client.organization_public_member?(test_github_org, test_github_login) expect(is_member).to be true assert_requested :get, github_url("/orgs/#{test_github_org}/public_members/#{test_github_login}") @@ -260,39 +261,39 @@ end # .organization_public_member? end # public org members - describe ".remove_organization_member" do - it "removes a member from an organization" do - stub_delete github_url("/orgs/api-playground/members/api-padawan") - @client.remove_organization_member("api-playground", "api-padawan") - assert_requested :delete, github_url("/orgs/api-playground/members/api-padawan") + describe '.remove_organization_member' do + it 'removes a member from an organization' do + stub_delete github_url('/orgs/api-playground/members/api-padawan') + @client.remove_organization_member('api-playground', 'api-padawan') + assert_requested :delete, github_url('/orgs/api-playground/members/api-padawan') end end # .remove_organization_member - describe ".user_teams", :vcr do - it "lists all teams for the authenticated user" do + describe '.user_teams', :vcr do + it 'lists all teams for the authenticated user' do teams = @client.user_teams - assert_requested :get, github_url("/user/teams") + assert_requested :get, github_url('/user/teams') expect(teams).to be_kind_of(Array) end end # .user_teams - describe ".add_team_membership", :vcr do - it "invites a user to a team" do + describe '.add_team_membership', :vcr do + it 'invites a user to a team' do membership = @client.add_team_membership(test_github_team_id, test_github_login) assert_requested :put, github_url("teams/#{test_github_team_id}/memberships/#{test_github_login}") - expect(membership.state).to eq("active") + expect(membership.state).to eq('active') end end # .add_team_membership - describe ".team_membership", :vcr do + describe '.team_membership', :vcr do it "gets a user's team membership" do membership = @client.team_membership(test_github_team_id, test_github_login) assert_requested :get, github_url("teams/#{test_github_team_id}/memberships/#{test_github_login}") - expect(membership.state).to eq("active") + expect(membership.state).to eq('active') end end # .team_membership - describe ".remove_team_membership", :vcr do + describe '.remove_team_membership', :vcr do it "removes a user's membership for a team" do result = @client.remove_team_membership(test_github_team_id, test_github_login) assert_requested :delete, github_url("teams/#{test_github_team_id}/memberships/#{test_github_login}") @@ -300,105 +301,105 @@ end end # .remove_team_membership - describe ".organization_memberships", :vcr do - it "returns all organization memberships for the user" do + describe '.organization_memberships', :vcr do + it 'returns all organization memberships for the user' do memberships = @client.organization_memberships expect(memberships).to be_kind_of Array - assert_requested :get, github_url("/user/memberships/orgs") + assert_requested :get, github_url('/user/memberships/orgs') end end # .organization_memberships - describe ".remove_organization_membership", :vcr do - it "removes an organization membership for a given user" do + describe '.remove_organization_membership', :vcr do + it 'removes an organization membership for a given user' do stub_delete github_url("orgs/#{test_github_org}/memberships/#{test_github_login}") @client.remove_organization_membership( test_github_org, - :user => test_github_login, - :accept => "application/vnd.github.moondragon+json" + user: test_github_login, + accept: 'application/vnd.github.moondragon+json' ) assert_requested :delete, github_url("/orgs/#{test_github_org}/memberships/#{test_github_login}") end end - describe ".organization_membership", :vcr do - it "returns an organization membership" do + describe '.organization_membership', :vcr do + it 'returns an organization membership' do stub_get github_url("/user/memberships/orgs/#{test_github_org}") membership = @client.organization_membership(test_github_org) assert_requested :get, github_url("/user/memberships/orgs/#{test_github_org}") end - it "returns an organization membership for a given user" do + it 'returns an organization membership for a given user' do stub_get github_url("orgs/#{test_github_org}/memberships/#{test_github_login}") @client.organization_membership( test_github_org, - :user => test_github_login, - :accept => "application/vnd.github.moondragon+json" + user: test_github_login, + accept: 'application/vnd.github.moondragon+json' ) assert_requested :get, github_url("/orgs/#{test_github_org}/memberships/#{test_github_login}") end - it "returns an organization membership for a given user by the orgs id" do + it 'returns an organization membership for a given user by the orgs id' do org_id = 42 stub_get github_url("organizations/#{org_id}/memberships/#{test_github_login}") @client.organization_membership( org_id, - :user => test_github_login, - :accept => "application/vnd.github.moondragon+json" + user: test_github_login, + accept: 'application/vnd.github.moondragon+json' ) assert_requested :get, github_url("/organizations/#{org_id}/memberships/#{test_github_login}") end end # .organization_membership - describe ".update_organization_membership", :vcr do - it "updates an organization membership" do - membership = @client.update_organization_membership(test_github_org, {:state => 'active'}) + describe '.update_organization_membership', :vcr do + it 'updates an organization membership' do + membership = @client.update_organization_membership(test_github_org, { state: 'active' }) assert_requested :patch, github_url("/user/memberships/orgs/#{test_github_org}") end - it "adds or updates an organization membership for a given user" do + it 'adds or updates an organization membership for a given user' do @client.update_organization_membership( test_github_org, - :user => test_github_collaborator_login, - :role => "member", + user: test_github_collaborator_login, + role: 'member' ) assert_requested :put, github_url("/orgs/#{test_github_org}/memberships/#{test_github_collaborator_login}") end end # .update_organization_membership - describe ".migrations", :vcr do - it "starts a migration for an organization" do - result = @client.start_migration(test_github_org, ["github-api/api-playground"], accept: preview_header) + describe '.migrations', :vcr do + it 'starts a migration for an organization' do + result = @client.start_migration(test_github_org, ['github-api/api-playground'], accept: preview_header) expect(result).to be_kind_of Sawyer::Resource assert_requested :post, github_url("/orgs/#{test_github_org}/migrations") end - it "lists migrations for an organization" do + it 'lists migrations for an organization' do result = @client.migrations(test_github_org, accept: preview_header) expect(result).to be_kind_of Array assert_requested :get, github_url("/orgs/#{test_github_org}/migrations") end - it "gets the status of a migration" do + it 'gets the status of a migration' do result = @client.migration_status(test_github_org, 97, accept: preview_header) expect(result).to be_kind_of Sawyer::Resource assert_requested :get, github_url("/orgs/#{test_github_org}/migrations/97") end - it "downloads a migration archive" do + it 'downloads a migration archive' do result = @client.migration_archive_url(test_github_org, 97, accept: preview_header) expect(result).to be_kind_of String assert_requested :get, github_url("/orgs/#{test_github_org}/migrations/97/archive") end - it "unlocks a migrated repository" do + it 'unlocks a migrated repository' do @client.unlock_repository(test_github_org, 97, 'api-playground', accept: preview_header) expect(@client.last_response.status).to eq(204) assert_requested :delete, github_url("/orgs/#{test_github_org}/migrations/97/repos/api-playground/lock") end end # .migrations - describe ".billing_actions", :vcr do - it "returns github actions billing for organization" do + describe '.billing_actions', :vcr do + it 'returns github actions billing for organization' do billing_actions = @client.billing_actions(test_github_org) expect(billing_actions.total_minutes_used).to be_kind_of(Integer) assert_requested :get, github_url("/orgs/#{test_github_org}/settings/billing/actions") diff --git a/spec/octokit/client/pages_spec.rb b/spec/octokit/client/pages_spec.rb index d989bdfa1..8bfab13c3 100644 --- a/spec/octokit/client/pages_spec.rb +++ b/spec/octokit/client/pages_spec.rb @@ -1,51 +1,52 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Pages do - before do Octokit.reset! @client = oauth_client end - describe ".pages", :vcr do - it "lists page information" do - pages = @client.pages("github/developer.github.com") - expect(pages.cname).to eq("developer.github.com") - assert_requested :get, github_url("/repos/github/developer.github.com/pages") + describe '.pages', :vcr do + it 'lists page information' do + pages = @client.pages('github/developer.github.com') + expect(pages.cname).to eq('developer.github.com') + assert_requested :get, github_url('/repos/github/developer.github.com/pages') end end # .pages - describe ".pages_build", :vcr do + describe '.pages_build', :vcr do # Grabbed this build ID manually from pages_builds - it "lists a specific page build" do - build = @client.pages_build(@test_repo, 40071035, accept: preview_header) + it 'lists a specific page build' do + build = @client.pages_build(@test_repo, 40_071_035, accept: preview_header) expect(build.status).not_to be_nil assert_requested :get, github_url("/repos/#{@test_repo}/pages/builds/40071035") end end # .pages_build - describe ".list_pages_builds", :vcr do - it "lists information about all the page builds" do - builds = @client.pages_builds("github/developer.github.com") + describe '.list_pages_builds', :vcr do + it 'lists information about all the page builds' do + builds = @client.pages_builds('github/developer.github.com') expect(builds).to be_kind_of Array latest_build = builds.first - expect(latest_build.status).to eq("built") - assert_requested :get, github_url("/repos/github/developer.github.com/pages/builds") + expect(latest_build.status).to eq('built') + assert_requested :get, github_url('/repos/github/developer.github.com/pages/builds') end end # .list_pages_builds - describe ".latest_pages_build", :vcr do - it "lists information about the latest page build" do - latest_build = @client.latest_pages_build("github/developer.github.com") - expect(latest_build.status).to eq("built") - assert_requested :get, github_url("/repos/github/developer.github.com/pages/builds/latest") + describe '.latest_pages_build', :vcr do + it 'lists information about the latest page build' do + latest_build = @client.latest_pages_build('github/developer.github.com') + expect(latest_build.status).to eq('built') + assert_requested :get, github_url('/repos/github/developer.github.com/pages/builds/latest') end end # .latest_pages_build - describe ".request_page_build", :vcr do + describe '.request_page_build', :vcr do # This test requires some manual setup in your test repository, # ensure it has pages site enabled and setup. - it "requests a build for the latest revision" do + it 'requests a build for the latest revision' do request = @client.request_page_build(@test_repo, accept: preview_header) expect(request.status).not_to be_nil assert_requested :post, github_url("/repos/#{@test_repo}/pages/builds") diff --git a/spec/octokit/client/projects_spec.rb b/spec/octokit/client/projects_spec.rb index 6ae073440..9958a3530 100644 --- a/spec/octokit/client/projects_spec.rb +++ b/spec/octokit/client/projects_spec.rb @@ -1,41 +1,42 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Projects do - - describe ".projects", :vcr do - it "returns a list of projects for a repository" do + describe '.projects', :vcr do + it 'returns a list of projects for a repository' do projects = oauth_client.projects('octokit/octokit.rb', accept: preview_header) expect(projects).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/projects") + assert_requested :get, github_url('/repos/octokit/octokit.rb/projects') end end # .projects - describe ".create_project", :vcr do - it "returns the newly created project" do - project = oauth_client.create_project(@test_repo, "api kpi", accept: preview_header) - expect(project.name).to eq("api kpi") + describe '.create_project', :vcr do + it 'returns the newly created project' do + project = oauth_client.create_project(@test_repo, 'api kpi', accept: preview_header) + expect(project.name).to eq('api kpi') assert_requested :post, github_url("/repos/#{@test_repo}/projects") end end # .create_project - describe ".org_projects", :vcr do - it "returns the projects for an organization" do + describe '.org_projects', :vcr do + it 'returns the projects for an organization' do projects = oauth_client.org_projects(test_github_org, accept: preview_header) expect(projects).to be_kind_of Array assert_requested :get, github_url("/orgs/#{test_github_org}/projects") end end # .org_project - describe ".create_org_project", :vcr do - it "returns the new org project" do - project = oauth_client.create_org_project(test_github_org, "synergy", body: "do it", accept: preview_header) - expect(project.name).to eq "synergy" - expect(project.body).to eq "do it" + describe '.create_org_project', :vcr do + it 'returns the new org project' do + project = oauth_client.create_org_project(test_github_org, 'synergy', body: 'do it', accept: preview_header) + expect(project.name).to eq 'synergy' + expect(project.body).to eq 'do it' assert_requested :post, github_url("/orgs/#{test_github_org}/projects") end end # .create_org_project - context "with repository" do + context 'with repository' do before(:each) do delete_test_repo end @@ -44,144 +45,143 @@ delete_test_repo end - context "with project" do + context 'with project' do before(:each) do - @project = oauth_client.create_project(@test_repo, "implement apis", accept: preview_header) + @project = oauth_client.create_project(@test_repo, 'implement apis', accept: preview_header) end - describe ".project", :vcr do - it "returns a project" do + describe '.project', :vcr do + it 'returns a project' do project = oauth_client.project(@project.id, accept: preview_header) expect(project.name).not_to be_nil assert_requested :get, github_url("/projects/#{@project.id}") end end # .project - describe ".update_project", :vcr do - it "updates the project name and body then returns the updated project" do - name = "new name" - body = "new body" - project = oauth_client.update_project(@project.id, {name: name, body: body, accept: preview_header}) + describe '.update_project', :vcr do + it 'updates the project name and body then returns the updated project' do + name = 'new name' + body = 'new body' + project = oauth_client.update_project(@project.id, { name: name, body: body, accept: preview_header }) expect(project.name).to eq name expect(project.body).to eq body assert_requested :patch, github_url("/projects/#{@project.id}") end end # .update_project - describe ".delete_project", :vcr do - it "returns the result of deleting a project" do + describe '.delete_project', :vcr do + it 'returns the result of deleting a project' do result = oauth_client.delete_project(@project.id, accept: preview_header) expect(result).to eq true assert_requested :delete, github_url("/projects/#{@project.id}") end end # .delete_project - describe ".project_columns", :vcr do - it "returns the columns for a project" do + describe '.project_columns', :vcr do + it 'returns the columns for a project' do columns = oauth_client.project_columns(@project.id, accept: preview_header) expect(columns).to be_kind_of Array assert_requested :get, github_url("/projects/#{@project.id}/columns") end end # .project_columns - describe ".create_project_column", :vcr do - it "returns the newly created project column" do - column = oauth_client.create_project_column(@project.id, "Todos", accept: preview_header) - expect(column.name).to eq "Todos" + describe '.create_project_column', :vcr do + it 'returns the newly created project column' do + column = oauth_client.create_project_column(@project.id, 'Todos', accept: preview_header) + expect(column.name).to eq 'Todos' assert_requested :post, github_url("/projects/#{@project.id}/columns") end end # .create_project_column - context "with project column" do + context 'with project column' do before(:each) do @column = oauth_client.create_project_column(@project.id, "Todos #{Time.now.to_f}", accept: preview_header) end - describe ".project_column", :vcr do - it "returns a project column by id" do + describe '.project_column', :vcr do + it 'returns a project column by id' do column = oauth_client.project_column(@column.id, accept: preview_header) expect(column.name).to be_kind_of String assert_requested :get, github_url("/projects/columns/#{@column.id}") end end # .project_column - describe ".update_project_column", :vcr do - it "updates the project column and returns the updated column" do - column = oauth_client.update_project_column(@column.id, "new name", accept: preview_header) - expect(column.name).to eq "new name" + describe '.update_project_column', :vcr do + it 'updates the project column and returns the updated column' do + column = oauth_client.update_project_column(@column.id, 'new name', accept: preview_header) + expect(column.name).to eq 'new name' assert_requested :patch, github_url("/projects/columns/#{@column.id}") end end # .update_project_column - describe ".move_project_column", :vcr do - it "moves the project column" do - result = oauth_client.move_project_column(@column.id, "last", accept: preview_header) + describe '.move_project_column', :vcr do + it 'moves the project column' do + result = oauth_client.move_project_column(@column.id, 'last', accept: preview_header) expect(result).not_to be_nil assert_requested :post, github_url("/projects/columns/#{@column.id}/moves") end end # .move_project_column - describe ".delete_project_column", :vcr do - it "deletes the project column" do + describe '.delete_project_column', :vcr do + it 'deletes the project column' do result = oauth_client.delete_project_column(@column.id, accept: preview_header) expect(result).to eq true assert_requested :delete, github_url("/projects/columns/#{@column.id}") end end # .delete_project_column - describe ".column_cards", :vcr do - it "returns a list of the cards in a project column" do + describe '.column_cards', :vcr do + it 'returns a list of the cards in a project column' do cards = oauth_client.column_cards(@column.id, accept: preview_header) expect(cards).to be_kind_of Array assert_requested :get, github_url("/projects/columns/#{@column.id}/cards") end end # .column_cards - describe ".create_project_card", :vcr do - it "creates a new card with a note" do + describe '.create_project_card', :vcr do + it 'creates a new card with a note' do card = oauth_client.create_project_card(@column.id, note: 'thing', accept: preview_header) expect(card.note).to eq 'thing' assert_requested :post, github_url("/projects/columns/#{@column.id}/cards") end end # .create_project_card - context "with project card" do + context 'with project card' do before(:each) do @card = oauth_client.create_project_card(@column.id, note: 'octocard', accept: preview_header) end - describe ".project_card", :vcr do - it "returns a project card by id" do + describe '.project_card', :vcr do + it 'returns a project card by id' do card = oauth_client.project_card(@card.id, accept: preview_header) expect(card.note).to be_kind_of String assert_requested :get, github_url("/projects/columns/cards/#{@card.id}") end end # .project_card - describe ".update_project_card", :vcr do - it "updates the project card" do + describe '.update_project_card', :vcr do + it 'updates the project card' do card = oauth_client.update_project_card(@card.id, note: 'new note', accept: preview_header) expect(card.note).to eq 'new note' assert_requested :patch, github_url("/projects/columns/cards/#{@card.id}") end end # .update_project_card - describe ".move_project_card", :vcr do - it "moves the project card" do + describe '.move_project_card', :vcr do + it 'moves the project card' do result = oauth_client.move_project_card(@card.id, 'bottom', accept: preview_header) expect(result).not_to be_nil assert_requested :post, github_url("/projects/columns/cards/#{@card.id}/moves") end end # .move_project_card - describe ".delete_project_card", :vcr do - it "deletes the project card" do + describe '.delete_project_card', :vcr do + it 'deletes the project card' do success = oauth_client.delete_project_card(@card.id, accept: preview_header) expect(success).to eq true assert_requested :delete, github_url("/projects/columns/cards/#{@card.id}") end end # .delete_project_card - end # with project card end # with project column end # with project diff --git a/spec/octokit/client/pub_sub_hubbub_spec.rb b/spec/octokit/client/pub_sub_hubbub_spec.rb index 6acad4072..de2782d8c 100644 --- a/spec/octokit/client/pub_sub_hubbub_spec.rb +++ b/spec/octokit/client/pub_sub_hubbub_spec.rb @@ -1,99 +1,100 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::PubSubHubbub do - before do Octokit.reset! @client = oauth_client end - describe ".subscribe" do - 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' - }). - to_return(:status => 204) - result = @client.subscribe("https://github.com/elskwid/github-services/events/push", "github://Travis?token=travistoken", "12345") + describe '.subscribe' do + 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' + }) + .to_return(status: 204) + result = @client.subscribe('https://github.com/elskwid/github-services/events/push', 'github://Travis?token=travistoken', '12345') expect(result).to be true assert_requested request end - it "raises an error when topic is not recognized", :vcr do + 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 { - @client.subscribe("https://github.com/joshk/not_existing_project/events/push", "github://Travis?token=travistoken") - }.to raise_error Octokit::UnprocessableEntity - assert_requested :post, github_url("/hub"), :body => subscribe_request_body, :times => 1, - :headers => {'Content-type' => 'application/x-www-form-urlencoded'} + expect do + @client.subscribe('https://github.com/joshk/not_existing_project/events/push', 'github://Travis?token=travistoken') + end.to raise_error Octokit::UnprocessableEntity + assert_requested :post, github_url('/hub'), body: subscribe_request_body, times: 1, + headers: { 'Content-type' => 'application/x-www-form-urlencoded' } end end # .subscribe - describe ".unsubscribe", :vcr do - it "unsubscribes from pull events" do + 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") - assert_requested :post, github_url("/hub"), :body => unsubscribe_request_body, :times => 1, - :headers => {'Content-type' => 'application/x-www-form-urlencoded'} + result = @client.unsubscribe("https://github.com/#{@test_repo}/events/push", 'github://Travis?token=travistoken') + assert_requested :post, github_url('/hub'), body: unsubscribe_request_body, times: 1, + headers: { 'Content-type' => 'application/x-www-form-urlencoded' } expect(result).to be true end end # .unsubscribe - describe ".subscribe_service_hook" do - 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' - }). - to_return(:status => 204) - result = @client.subscribe_service_hook("elskwid/github-services", "Travis", { :token => 'travistoken' }, "12345") + describe '.subscribe_service_hook' do + 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' + }) + .to_return(status: 204) + result = @client.subscribe_service_hook('elskwid/github-services', 'Travis', { token: 'travistoken' }, '12345') expect(result).to be true assert_requested request end - it "encodes URL parameters", :vcr do + 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). - to_return(:status => 204) - expect(@client.subscribe_service_hook("joshk/completeness-fu", "irc", { :server => "chat.freenode.org", :room => "#myproject"})).to eql(true) + stub_post('/hub') + .with(body: irc_request_body) + .to_return(status: 204) + expect(@client.subscribe_service_hook('joshk/completeness-fu', 'irc', { server: 'chat.freenode.org', room: '#myproject' })).to eql(true) # Since we can't depend upon hash ordering across the Rubies - assert_requested :post, "https://api.github.com/hub", :times => 1 do |req| - req.body[%r{hub.callback=github%3A%2F%2Firc%3Froom%3D%2523myproject}] - req.body[%r{server%3Dchat.freenode.org}] + assert_requested :post, 'https://api.github.com/hub', times: 1 do |req| + req.body[/hub.callback=github%3A%2F%2Firc%3Froom%3D%2523myproject/] + req.body[/server%3Dchat.freenode.org/] end end end # .subscribe_service_hook - describe "unsubscribe_service_hook", :vcr do - it "unsubscribes to stop receiving events on specified topic" do + 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, - :headers => {'Content-type' => 'application/x-www-form-urlencoded'} + expect(@client.unsubscribe_service_hook(@test_repo, 'Travis')).to eq(true) + assert_requested :post, github_url('/hub'), body: unsubscribe_request_body, times: 1, + headers: { 'Content-type' => 'application/x-www-form-urlencoded' } end end end diff --git a/spec/octokit/client/pull_requests_spec.rb b/spec/octokit/client/pull_requests_spec.rb index 9912c411b..104bc9ecf 100644 --- a/spec/octokit/client/pull_requests_spec.rb +++ b/spec/octokit/client/pull_requests_spec.rb @@ -1,27 +1,27 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::PullRequests do - before do Octokit.reset! @client = oauth_client end - describe ".pull_requests", :vcr do - it "lists all pull requests" do - pulls = @client.pulls("octokit/octokit.rb") + describe '.pull_requests', :vcr do + it 'lists all pull requests' do + pulls = @client.pulls('octokit/octokit.rb') expect(pulls).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/pulls") + assert_requested :get, github_url('/repos/octokit/octokit.rb/pulls') end - it "lists all pull requests with state option" do - pulls = @client.pulls("octokit/octokit.rb", :state => 'open') + it 'lists all pull requests with state option' do + pulls = @client.pulls('octokit/octokit.rb', state: 'open') expect(pulls).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/pulls?state=open") + assert_requested :get, github_url('/repos/octokit/octokit.rb/pulls?state=open') end end # .pull_requests - context "methods that require a new pull" do - + context 'methods that require a new pull' do before(:each) do @pull = @client.create_pull_request(*arguments_to_create_pull_request) end @@ -31,58 +31,57 @@ end let(:arguments_to_create_pull_request) do - [@test_repo, "master", "branch-for-pr", "A new PR", "The Body"] + [@test_repo, 'master', 'branch-for-pr', 'A new PR', 'The Body'] end - describe ".create_pull_request", :vcr do - it "creates a pull request" do - expect(@pull.title).to eq("A new PR") + describe '.create_pull_request', :vcr do + it 'creates a pull request' do + expect(@pull.title).to eq('A new PR') assert_requested :post, github_url("/repos/#{@test_repo}/pulls") end - context "without body argument" do + context 'without body argument' do let(:arguments_to_create_pull_request) do super()[0..-2] end - it "creates a pull request without body argument" do + it 'creates a pull request without body argument' do expect(@pull.body).to be_nil assert_requested :post, github_url("/repos/#{@test_repo}/pulls") end end end # .create_pull_request - describe ".pull_request", :vcr do - it "returns a pull request" do + describe '.pull_request', :vcr do + it 'returns a pull request' do pull = @client.pull(@test_repo, @pull.number) - expect(pull.title).to eq("A new PR") + expect(pull.title).to eq('A new PR') assert_requested :get, github_url("/repos/#{@test_repo}/pulls/#{@pull.number}") end end # .pull_request - describe ".update_pull_request", :vcr do - it "updates a pull request" do + describe '.update_pull_request', :vcr do + it 'updates a pull request' do @client.update_pull_request(@test_repo, @pull.number, 'New title', 'Updated body') assert_requested :patch, github_url("/repos/#{@test_repo}/pulls/#{@pull.number}") end end # .update_pull_request - describe ".pull_merged?", :vcr do - it "returns whether the pull request has been merged" do + describe '.pull_merged?', :vcr do + it 'returns whether the pull request has been merged' do merged = @client.pull_merged?(@test_repo, @pull.number) expect(merged).not_to be true assert_requested :get, github_url("/repos/#{@test_repo}/pulls/#{@pull.number}/merge") end end # .pull_merged? - context "methods requiring a pull request comment" do - + context 'methods requiring a pull request comment' do before do new_comment = { - :body => "Hawt", - :commit_id => "9bf22dff54fd6a7650230b70417b55e8cccfc4f2", - :path => "test.md", - :position => 1 + body: 'Hawt', + commit_id: '9bf22dff54fd6a7650230b70417b55e8cccfc4f2', + path: 'test.md', + position: 1 } @comment = @client.create_pull_request_comment \ @test_repo, @@ -93,65 +92,63 @@ new_comment[:position] end - describe ".create_pull_request_comment", :vcr do - it "creates a new comment on a pull request" do + describe '.create_pull_request_comment', :vcr do + it 'creates a new comment on a pull request' do assert_requested :post, github_url("/repos/#{@test_repo}/pulls/#{@pull.number}/comments") end end # .create_pull_request_comment - describe ".create_pull_request_comment_reply", :vcr do - it "creates a new reply to a pull request comment" do + describe '.create_pull_request_comment_reply', :vcr do + it 'creates a new reply to a pull request comment' do new_comment = { - :body => "done.", - :in_reply_to => @comment.id + body: 'done.', + in_reply_to: @comment.id } reply = @client.create_pull_request_comment_reply(@test_repo, @pull.number, new_comment[:body], new_comment[:in_reply_to]) - assert_requested :post, github_url("/repos/#{@test_repo}/pulls/#{@pull.number}/comments"), :times => 2 + assert_requested :post, github_url("/repos/#{@test_repo}/pulls/#{@pull.number}/comments"), times: 2 expect(reply.body).to eq(new_comment[:body]) end end # .create_pull_request_comment_reply - describe ".update_pull_request_comment", :vcr do - it "updates a pull request comment" do - comment = @client.update_pull_request_comment(@test_repo, @comment.id, ":shipit:") - expect(comment.body).to eq(":shipit:") + describe '.update_pull_request_comment', :vcr do + it 'updates a pull request comment' do + comment = @client.update_pull_request_comment(@test_repo, @comment.id, ':shipit:') + expect(comment.body).to eq(':shipit:') assert_requested :patch, github_url("/repos/#{@test_repo}/pulls/comments/#{@comment.id}") end end # .update_pull_request_comment - describe ".delete_pull_request_comment", :vcr do - it "deletes a pull request comment" do + describe '.delete_pull_request_comment', :vcr do + it 'deletes a pull request comment' do result = @client.delete_pull_request_comment(@test_repo, @comment.id) expect(result).to eq(true) assert_requested :delete, github_url("/repos/#{@test_repo}/pulls/comments/#{@comment.id}") end end # .delete_pull_request_comment - end # pull request comment methods - describe ".close_pull_request", :vcr do - it "closes a pull request" do + describe '.close_pull_request', :vcr do + it 'closes a pull request' do response = @client.close_pull_request(@test_repo, @pull.number) expect(response.state).to eq('closed') assert_requested :patch, github_url("/repos/#{@test_repo}/pulls/#{@pull.number}") end end - end # new @pull methods # stub this so we don't have to set up new fixture data - describe ".merge_pull_request" do - it "merges the pull request" do - request = stub_put(github_url("/repos/api-playground/api-sandbox/pulls/123/merge")) - @client.merge_pull_request("api-playground/api-sandbox", 123) + describe '.merge_pull_request' do + it 'merges the pull request' do + request = stub_put(github_url('/repos/api-playground/api-sandbox/pulls/123/merge')) + @client.merge_pull_request('api-playground/api-sandbox', 123) assert_requested request end end # .merge_pull_request - describe ".create_pull_request_for_issue", :vcr do - it "creates a pull request and attach it to an existing issue" do - issue = @client.create_issue(@test_repo, 'A new issue', "Gonna turn this into a PR") - pull = @client.create_pull_request_for_issue(@test_repo, "master", "some-fourth-branch", issue.number) + describe '.create_pull_request_for_issue', :vcr do + it 'creates a pull request and attach it to an existing issue' do + issue = @client.create_issue(@test_repo, 'A new issue', 'Gonna turn this into a PR') + pull = @client.create_pull_request_for_issue(@test_repo, 'master', 'some-fourth-branch', issue.number) assert_requested :post, github_url("/repos/#{@test_repo}/pulls") # cleanup so we can re-run test with blank cassette @@ -159,46 +156,45 @@ end end # .create_pull_request_for_issue - describe ".pull_requests_comments", :vcr do - it "returns all comments on all pull requests" do - comments = @client.pull_requests_comments("octokit/octokit.rb") + describe '.pull_requests_comments', :vcr do + it 'returns all comments on all pull requests' do + comments = @client.pull_requests_comments('octokit/octokit.rb') expect(comments).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/pulls/comments") + assert_requested :get, github_url('/repos/octokit/octokit.rb/pulls/comments') end end # .pull_requests_comments - describe ".pull_request_commits", :vcr do - it "returns the commits for a pull request" do - commits = @client.pull_commits("octokit/octokit.rb", 67) + describe '.pull_request_commits', :vcr do + it 'returns the commits for a pull request' do + commits = @client.pull_commits('octokit/octokit.rb', 67) expect(commits).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/pulls/67/commits") + assert_requested :get, github_url('/repos/octokit/octokit.rb/pulls/67/commits') end end # .pull_request_commits - describe ".pull_request_files", :vcr do - it "lists files for a pull request" do - files = @client.pull_request_files("octokit/octokit.rb", 67) + describe '.pull_request_files', :vcr do + it 'lists files for a pull request' do + files = @client.pull_request_files('octokit/octokit.rb', 67) file = files.first expect(file.filename).to eq('lib/octokit/configuration.rb') expect(file.additions).to eq(4) - assert_requested :get, github_url("/repos/octokit/octokit.rb/pulls/67/files") + assert_requested :get, github_url('/repos/octokit/octokit.rb/pulls/67/files') end end # .pull_request_files - describe ".pull_request_comments", :vcr do - it "returns the comments for a pull request" do - comments = @client.pull_comments("octokit/octokit.rb", 67) + describe '.pull_request_comments', :vcr do + it 'returns the comments for a pull request' do + comments = @client.pull_comments('octokit/octokit.rb', 67) expect(comments).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/pulls/67/comments") + assert_requested :get, github_url('/repos/octokit/octokit.rb/pulls/67/comments') end end # .pull_request_comments - describe ".pull_request_comment", :vcr do - it "returns a comment on a pull request" do - comment = @client.pull_request_comment("octokit/octokit.rb", 1903950) + describe '.pull_request_comment', :vcr do + it 'returns a comment on a pull request' do + comment = @client.pull_request_comment('octokit/octokit.rb', 1_903_950) expect(comment.body).not_to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/pulls/comments/1903950") + assert_requested :get, github_url('/repos/octokit/octokit.rb/pulls/comments/1903950') end end # .pull_request_comment - end diff --git a/spec/octokit/client/rate_limit_spec.rb b/spec/octokit/client/rate_limit_spec.rb index 4fb5492a0..64d0659c6 100644 --- a/spec/octokit/client/rate_limit_spec.rb +++ b/spec/octokit/client/rate_limit_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client do @@ -5,23 +7,23 @@ let(:client) { client = Octokit::Client.new } - describe "#rate_limit" do - context "with no last response" do - it "makes a response", :vcr => { cassette_name: "rate_limit" } do + describe '#rate_limit' do + context 'with no last response' do + it 'makes a response', vcr: { cassette_name: 'rate_limit' } do rate = client.rate_limit expect(rate.limit).to be_kind_of Integer expect(rate.remaining).to be_kind_of Integer end # #rate_limit end - context "with last response" do + context 'with last response' do before do VCR.use_cassette 'root' do client.get('/') end end - it "checks the rate limit from the last response", :vcr => { cassette_name: "rate_limit" } do + it 'checks the rate limit from the last response', vcr: { cassette_name: 'rate_limit' } do rate = client.rate_limit expect(rate.limit).to be_kind_of Integer expect(rate.remaining).to be_kind_of Integer @@ -31,8 +33,8 @@ end end - describe "#rate_limit!", :vcr => { cassette_name: "rate_limit" } do - it "makes a web request to check the rate limit" do + describe '#rate_limit!', vcr: { cassette_name: 'rate_limit' } do + it 'makes a web request to check the rate limit' do rate = client.rate_limit! expect(rate.limit).to be_kind_of Integer expect(rate.remaining).to be_kind_of Integer @@ -41,41 +43,41 @@ end end # #rate_limit! - context "deprecated methods" do - let(:rate) { double("rate", remaining: 1) } + context 'deprecated methods' do + let(:rate) { double('rate', remaining: 1) } before do allow(client).to receive(:octokit_warn) end - describe "#rate_limit_remaining" do + describe '#rate_limit_remaining' do before do allow(client).to receive(:rate_limit).and_return(rate) end after do expect(client).to have_received(:octokit_warn) - .with("Deprecated: Please use .rate_limit.remaining") + .with('Deprecated: Please use .rate_limit.remaining') expect(client).to have_received(:rate_limit) end - it "triggers warning and will call remaining on rate_limit" do + it 'triggers warning and will call remaining on rate_limit' do client.rate_limit_remaining end end - describe "rate_limit_remaining!" do + describe 'rate_limit_remaining!' do before do allow(client).to receive(:rate_limit!).and_return(rate) end after do expect(client).to have_received(:octokit_warn) - .with("Deprecated: Please use .rate_limit!.remaining") + .with('Deprecated: Please use .rate_limit!.remaining') expect(client).to have_received(:rate_limit!) end - it "triggers warning and will remaining on rate_limit!" do + it 'triggers warning and will remaining on rate_limit!' do client.rate_limit_remaining! end end diff --git a/spec/octokit/client/reactions_spec.rb b/spec/octokit/client/reactions_spec.rb index 51c22f334..3f5b7afc5 100644 --- a/spec/octokit/client/reactions_spec.rb +++ b/spec/octokit/client/reactions_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Reactions do @@ -6,9 +8,9 @@ @client = oauth_client end - context "with repository", :vcr do + context 'with repository', :vcr do before(:each) do - @repo = @client.create_repository("an-repo", :auto_init => true) + @repo = @client.create_repository('an-repo', auto_init: true) end after(:each) do @@ -18,7 +20,7 @@ end end - context "with commit comment" do + context 'with commit comment' do before do @commit = @client.commits(@repo.full_name).last.rels[:self].get.data @commit_comment = @client.create_commit_comment \ @@ -27,73 +29,73 @@ @commit.files.last.filename end - describe ".commit_comment_reactions" do - it "returns an Array of reactions" do + describe '.commit_comment_reactions' do + it 'returns an Array of reactions' do reactions = @client.commit_comment_reactions(@repo.full_name, @commit_comment.id, accept: preview_header) expect(reactions).to be_kind_of Array assert_requested :get, github_url("/repos/#{@repo.full_name}/comments/#{@commit_comment.id}/reactions") end end # .commit_comment_reactions - describe ".create_commit_comment_reaction" do - it "creates a reaction" do - reaction = @client.create_commit_comment_reaction(@repo.full_name, @commit_comment.id, "+1", accept: preview_header) - expect(reaction.content).to eql("+1") + describe '.create_commit_comment_reaction' do + it 'creates a reaction' do + reaction = @client.create_commit_comment_reaction(@repo.full_name, @commit_comment.id, '+1', accept: preview_header) + expect(reaction.content).to eql('+1') assert_requested :post, github_url("/repos/#{@repo.full_name}/comments/#{@commit_comment.id}/reactions") end end # .create_commit_comment_reaction end # with commit comment - context "with issue", :vcr do + context 'with issue', :vcr do before do - @issue = @client.create_issue(@repo.full_name, "Migrate issues to v3", "Move all Issues calls to v3 of the API") + @issue = @client.create_issue(@repo.full_name, 'Migrate issues to v3', 'Move all Issues calls to v3 of the API') end - describe ".issue_reactions" do - it "returns an Array of reactions" do + describe '.issue_reactions' do + it 'returns an Array of reactions' do reactions = @client.issue_reactions(@repo.full_name, @issue.number, accept: preview_header) expect(reactions).to be_kind_of Array assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/reactions") end end # .issue_reactions - describe ".create_issue_reaction" do - it "creates a reaction" do - reaction = @client.create_issue_reaction(@repo.full_name, @issue.number, "+1", accept: preview_header) - expect(reaction.content).to eql("+1") + describe '.create_issue_reaction' do + it 'creates a reaction' do + reaction = @client.create_issue_reaction(@repo.full_name, @issue.number, '+1', accept: preview_header) + expect(reaction.content).to eql('+1') assert_requested :post, github_url("/repos/#{@repo.full_name}/issues/#{@issue.number}/reactions") end end # .create_issue_reaction - context "with issue comment" do + context 'with issue comment' do before do - @issue_comment = @client.add_comment(@repo.full_name, @issue.number, "Another test comment") + @issue_comment = @client.add_comment(@repo.full_name, @issue.number, 'Another test comment') end - describe ".issue_comment_reactions" do - it "returns an Array of reactions" do + describe '.issue_comment_reactions' do + it 'returns an Array of reactions' do reactions = @client.issue_comment_reactions(@repo.full_name, @issue_comment.id, accept: preview_header) expect(reactions).to be_kind_of Array assert_requested :get, github_url("/repos/#{@repo.full_name}/issues/comments/#{@issue_comment.id}/reactions") end end # .issue_commit_comment_reactions - describe ".create_issue_comment_reaction" do - it "creates a reaction" do - reaction = @client.create_issue_comment_reaction(@repo.full_name, @issue_comment.id, "+1", accept: preview_header) - expect(reaction.content).to eql("+1") + describe '.create_issue_comment_reaction' do + it 'creates a reaction' do + reaction = @client.create_issue_comment_reaction(@repo.full_name, @issue_comment.id, '+1', accept: preview_header) + expect(reaction.content).to eql('+1') assert_requested :post, github_url("/repos/#{@repo.full_name}/issues/comments/#{@issue_comment.id}/reactions") end end # .create_issue_comment_reaction end # with issue comment - context "with reaction" do + context 'with reaction' do before do - @reaction = @client.create_issue_reaction(@repo.full_name, @issue.number, "+1", accept: preview_header) + @reaction = @client.create_issue_reaction(@repo.full_name, @issue.number, '+1', accept: preview_header) end - describe ".delete_reaction" do - it "deletes the reaction" do + describe '.delete_reaction' do + it 'deletes the reaction' do @client.delete_reaction(@reaction.id, accept: preview_header) assert_requested :delete, github_url("/reactions/#{@reaction.id}") end @@ -101,23 +103,23 @@ end # with reaction end # with issue - context "with pull request" do + context 'with pull request' do before do - master_ref = @client.ref(@repo.full_name, "heads/master") - @client.create_ref(@repo.full_name, "heads/branch-for-pr", master_ref.object.sha) - @content = @client.create_contents(@repo.full_name, "lib/test.txt", "Adding content", "File Content", :branch => "branch-for-pr") + master_ref = @client.ref(@repo.full_name, 'heads/master') + @client.create_ref(@repo.full_name, 'heads/branch-for-pr', master_ref.object.sha) + @content = @client.create_contents(@repo.full_name, 'lib/test.txt', 'Adding content', 'File Content', branch: 'branch-for-pr') - args = [@repo.full_name, "master", "branch-for-pr", "A new PR", "The Body"] + args = [@repo.full_name, 'master', 'branch-for-pr', 'A new PR', 'The Body'] @pull = @client.create_pull_request(*args) end - context "with pull request review comment" do + context 'with pull request review comment' do before do new_comment = { - :body => "Looks good!", - :commit_id => @content.commit.sha, - :path => "lib/test.txt", - :position => 1 + body: 'Looks good!', + commit_id: @content.commit.sha, + path: 'lib/test.txt', + position: 1 } @pull_request_review_comment = @client.create_pull_request_comment \ @@ -129,18 +131,18 @@ new_comment[:position] end - describe ".pull_request_review_comment_reactions" do - it "returns an Array of reactions" do + describe '.pull_request_review_comment_reactions' do + it 'returns an Array of reactions' do reactions = @client.pull_request_review_comment_reactions(@repo.full_name, @pull_request_review_comment.id, accept: preview_header) expect(reactions).to be_kind_of Array assert_requested :get, github_url("/repos/#{@repo.full_name}/pulls/comments/#{@pull_request_review_comment.id}/reactions") end end # .pull_request_review_comment_reactions - describe ".create_pull_request_review_comment_reaction" do - it "creates a reaction" do - reaction = @client.create_pull_request_review_comment_reaction(@repo.full_name, @pull_request_review_comment.id, "+1", accept: preview_header) - expect(reaction.content).to eql("+1") + describe '.create_pull_request_review_comment_reaction' do + it 'creates a reaction' do + reaction = @client.create_pull_request_review_comment_reaction(@repo.full_name, @pull_request_review_comment.id, '+1', accept: preview_header) + expect(reaction.content).to eql('+1') assert_requested :post, github_url("/repos/#{@repo.full_name}/pulls/comments/#{@pull_request_review_comment.id}/reactions") end end # .create_pull_request_review_comment_reaction diff --git a/spec/octokit/client/refs_spec.rb b/spec/octokit/client/refs_spec.rb index 87f389158..5097b5965 100644 --- a/spec/octokit/client/refs_spec.rb +++ b/spec/octokit/client/refs_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Refs do @@ -6,110 +8,109 @@ @client = oauth_client end - describe ".matching_refs", :vcr do - it "returns all matching refs" do - refs = @client.matching_refs("sferik/rails_admin", "heads/rails") + describe '.matching_refs', :vcr do + it 'returns all matching refs' do + refs = @client.matching_refs('sferik/rails_admin', 'heads/rails') expect(refs).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/git/matching-refs/heads/rails") + assert_requested :get, github_url('/repos/sferik/rails_admin/git/matching-refs/heads/rails') end - it "returns all matching tag refs" do - refs = @client.matching_refs("sferik/rails_admin", "tags/v2") + it 'returns all matching tag refs' do + refs = @client.matching_refs('sferik/rails_admin', 'tags/v2') expect(refs).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/git/matching-refs/tags/v2") + assert_requested :get, github_url('/repos/sferik/rails_admin/git/matching-refs/tags/v2') end end - describe ".refs", :vcr do - it "returns all refs" do - refs = @client.refs("sferik/rails_admin") + describe '.refs', :vcr do + it 'returns all refs' do + refs = @client.refs('sferik/rails_admin') expect(refs).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/git/refs") + assert_requested :get, github_url('/repos/sferik/rails_admin/git/refs') end - it "returns all tag refs" do - refs = @client.refs("sferik/rails_admin", "tags") + it 'returns all tag refs' do + refs = @client.refs('sferik/rails_admin', 'tags') expect(refs).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/git/refs/tags") + assert_requested :get, github_url('/repos/sferik/rails_admin/git/refs/tags') end end # .refs - describe ".ref", :vcr do - it "returns a tags ref" do - ref = @client.ref("sferik/rails_admin", "tags/v0.0.3") - expect(ref.object.type).to eq("tag") - assert_requested :get, github_url("/repos/sferik/rails_admin/git/refs/tags/v0.0.3") + describe '.ref', :vcr do + it 'returns a tags ref' do + ref = @client.ref('sferik/rails_admin', 'tags/v0.0.3') + expect(ref.object.type).to eq('tag') + assert_requested :get, github_url('/repos/sferik/rails_admin/git/refs/tags/v0.0.3') end end # .ref - describe ".create_ref" do - it "prepends refs/ to the ref parameter" do - request = stub_post("/repos/#{@test_repo}/git/refs"). - with(:body => {ref: "refs/heads/testing/test-ref-2", sha: @first_sha}.to_json) - @client.create_ref(@test_repo, "heads/testing/test-ref-2", @first_sha) - assert_requested request + describe '.create_ref' do + it 'prepends refs/ to the ref parameter' do + request = stub_post("/repos/#{@test_repo}/git/refs") + .with(body: { ref: 'refs/heads/testing/test-ref-2', sha: @first_sha }.to_json) + @client.create_ref(@test_repo, 'heads/testing/test-ref-2', @first_sha) + assert_requested request end - it "prepends refs/ to the ref parameter when required" do - request = stub_post("/repos/#{@test_repo}/git/refs"). - with(:body => {ref: "refs/heads/refs/test-ref-2", sha: @first_sha}.to_json) - @client.create_ref(@test_repo, "heads/refs/test-ref-2", @first_sha) - assert_requested request + it 'prepends refs/ to the ref parameter when required' do + request = stub_post("/repos/#{@test_repo}/git/refs") + .with(body: { ref: 'refs/heads/refs/test-ref-2', sha: @first_sha }.to_json) + @client.create_ref(@test_repo, 'heads/refs/test-ref-2', @first_sha) + assert_requested request end - it "does not duplicate refs/ in ref parameter" do - request = stub_post("/repos/#{@test_repo}/git/refs"). - with(:body => {ref: "refs/heads/testing/test-ref-2", sha: @first_sha}.to_json) - @client.create_ref(@test_repo, "refs/heads/testing/test-ref-2", @first_sha) - assert_requested request + it 'does not duplicate refs/ in ref parameter' do + request = stub_post("/repos/#{@test_repo}/git/refs") + .with(body: { ref: 'refs/heads/testing/test-ref-2', sha: @first_sha }.to_json) + @client.create_ref(@test_repo, 'refs/heads/testing/test-ref-2', @first_sha) + assert_requested request end end # .create_ref - context "with ref", :vcr do + context 'with ref', :vcr do before(:each) do commits = @client.commits(@test_repo) @first_sha = commits.first.sha @last_sha = commits.last.sha - @ref = @client.create_ref(@test_repo,"heads/testing/test-ref", @first_sha) + @ref = @client.create_ref(@test_repo, 'heads/testing/test-ref', @first_sha) end after(:each) do begin - @client.delete_ref(@test_repo, "heads/testing/test-ref") + @client.delete_ref(@test_repo, 'heads/testing/test-ref') rescue Octokit::UnprocessableEntity end end - describe ".create_ref" do - it "creates a ref" do + describe '.create_ref' do + it 'creates a ref' do assert_requested :post, github_url("/repos/#{@test_repo}/git/refs") end end # .create_ref - describe ".update_branch" do - it "updates a branch" do - @client.update_branch(@test_repo, "testing/test-ref", @last_sha, true) + describe '.update_branch' do + it 'updates a branch' do + @client.update_branch(@test_repo, 'testing/test-ref', @last_sha, true) assert_requested :patch, github_url("/repos/#{@test_repo}/git/refs/heads/testing/test-ref") end end # .update_branch - describe ".update_ref" do - it "updates a ref" do - @client.update_ref(@test_repo, "heads/testing/test-ref", @last_sha, true) + describe '.update_ref' do + it 'updates a ref' do + @client.update_ref(@test_repo, 'heads/testing/test-ref', @last_sha, true) assert_requested :patch, github_url("/repos/#{@test_repo}/git/refs/heads/testing/test-ref") end end # .update_ref - describe ".delete_branch" do - it "deletes an existing branch" do - @client.delete_branch(@test_repo, "testing/test-ref") + describe '.delete_branch' do + it 'deletes an existing branch' do + @client.delete_branch(@test_repo, 'testing/test-ref') assert_requested :delete, github_url("/repos/#{@test_repo}/git/refs/heads/testing/test-ref") end end # .delete_branch - describe ".delete_ref" do - it "deletes an existing ref" do - @client.delete_ref(@test_repo, "heads/testing/test-ref") + describe '.delete_ref' do + it 'deletes an existing ref' do + @client.delete_ref(@test_repo, 'heads/testing/test-ref') assert_requested :delete, github_url("/repos/#{@test_repo}/git/refs/heads/testing/test-ref") end end # .delete_ref end # with ref end - diff --git a/spec/octokit/client/releases_spec.rb b/spec/octokit/client/releases_spec.rb index b810479eb..d507e07de 100644 --- a/spec/octokit/client/releases_spec.rb +++ b/spec/octokit/client/releases_spec.rb @@ -1,55 +1,56 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Releases do - before do Octokit.reset! @client = oauth_client end - describe ".releases" do - it "lists releases for a repo", :vcr do + describe '.releases' do + it 'lists releases for a repo', :vcr do releases = @client.releases @test_repo expect(releases).to be_kind_of Array assert_requested :get, github_url("/repos/#{@test_repo}/releases") end end - describe ".create_release", :vcr do - it "creates a release" do + describe '.create_release', :vcr do + it 'creates a release' do release = @client.create_release \ - @test_repo, "test-create-release-tag", :name => "Test Create Release" - expect(release.tag_name).to eq("test-create-release-tag") - expect(release.name).to eq("Test Create Release") + @test_repo, 'test-create-release-tag', name: 'Test Create Release' + expect(release.tag_name).to eq('test-create-release-tag') + expect(release.name).to eq('Test Create Release') assert_requested :post, github_url("/repos/#{@test_repo}/releases") end end - describe ".release", :vcr do - it "gets a single release" do + describe '.release', :vcr do + it 'gets a single release' do created = @client.create_release \ - @test_repo, "test-get-release-tag", :name => "Test Get Release" + @test_repo, 'test-get-release-tag', name: 'Test Get Release' release = @client.release created.rels[:self].href - expect(release.tag_name).to eq("test-get-release-tag") - expect(release.name).to eq("Test Get Release") + expect(release.tag_name).to eq('test-get-release-tag') + expect(release.name).to eq('Test Get Release') end end - describe ".update_release", :vcr do - it "updates a release" do + describe '.update_release', :vcr do + it 'updates a release' do created = @client.create_release \ - @test_repo, "test-update-release-tag", :name => "Test Update Release" + @test_repo, 'test-update-release-tag', name: 'Test Update Release' release = @client.update_release \ - created.rels[:self].href, :name => "An updated release" - expect(release.name).to eq("An updated release") + created.rels[:self].href, name: 'An updated release' + expect(release.name).to eq('An updated release') assert_requested :patch, created.rels[:self].href end end - describe ".delete_release", :vcr do - it "deletes a release" do + describe '.delete_release', :vcr do + it 'deletes a release' do created = @client.create_release \ - @test_repo, "test-delete-release-tag", :name => "Test Delete Release" + @test_repo, 'test-delete-release-tag', name: 'Test Delete Release' url = created.rels[:self].href result = @client.delete_release url expect(result).to be true @@ -57,90 +58,88 @@ end end - context "handling release assets" do - + context 'handling release assets' do before do - @release_url = "https://api.github.com/repos/api-playground/api-sandbox/releases/43567" + @release_url = 'https://api.github.com/repos/api-playground/api-sandbox/releases/43567' end - describe ".release_assets", :vcr do - it "lists assets for a release" do + describe '.release_assets', :vcr do + it 'lists assets for a release' do assets = @client.release_assets(@release_url) expect(assets).to be_kind_of(Array) end end - describe ".upload_release_asset", :vcr do - it "uploads a release asset by path" do - local_path = "spec/fixtures/upload.png" - name = "upload_by_path.png" - asset = @client.upload_asset(@release_url, local_path, :content_type => "image/png", :name => name) + describe '.upload_release_asset', :vcr do + it 'uploads a release asset by path' do + local_path = 'spec/fixtures/upload.png' + name = 'upload_by_path.png' + asset = @client.upload_asset(@release_url, local_path, content_type: 'image/png', name: name) expect(asset.name).to eq(name) end - it "uploads a release asset as file object" do - file = File.new("spec/fixtures/upload.png", "r+b") + it 'uploads a release asset as file object' do + file = File.new('spec/fixtures/upload.png', 'r+b') size = File.size(file) - name = "upload_by_file.png" - asset = @client.upload_asset(@release_url, file, :content_type => "image/png", :name => name) + name = 'upload_by_file.png' + asset = @client.upload_asset(@release_url, file, content_type: 'image/png', name: name) expect(asset.name).to eq(name) expect(asset.size).to eq(size) end - it "uploads a release asset with a default name" do - path = "spec/fixtures/upload.png" - name = "upload.png" - asset = @client.upload_asset(@release_url, path, :content_type => "image/png") + it 'uploads a release asset with a default name' do + path = 'spec/fixtures/upload.png' + name = 'upload.png' + asset = @client.upload_asset(@release_url, path, content_type: 'image/png') expect(asset.name).to eq(name) end - it "guesses the content type for an asset" do - path = "spec/fixtures/upload.png" - name = "upload_guess_content_type.png" - asset = @client.upload_asset(@release_url, path, :name => name) + it 'guesses the content type for an asset' do + path = 'spec/fixtures/upload.png' + name = 'upload_guess_content_type.png' + asset = @client.upload_asset(@release_url, path, name: name) expect(asset.name).to eq(name) - expect(asset.content_type).to eq("image/png") + expect(asset.content_type).to eq('image/png') end end - describe ".release_asset" do - it "gets a single release asset" do - asset_url = "https://api.github.com/repos/api-playground/api-sandbox/releases/assets/21313" + describe '.release_asset' do + it 'gets a single release asset' do + asset_url = 'https://api.github.com/repos/api-playground/api-sandbox/releases/assets/21313' request = stub_get(asset_url) @client.release_asset(asset_url) assert_requested request end end - describe ".update_release_asset" do - it "edits a release asset", :vcr do - asset_url = "https://api.github.com/repos/api-playground/api-sandbox/releases/assets/21313" - updated = @client.update_release_asset(asset_url, :label => "Updated") - expect(updated.label).to eq("Updated") + describe '.update_release_asset' do + it 'edits a release asset', :vcr do + asset_url = 'https://api.github.com/repos/api-playground/api-sandbox/releases/assets/21313' + updated = @client.update_release_asset(asset_url, label: 'Updated') + expect(updated.label).to eq('Updated') end end - describe ".delete_release_asset" do - it "deletes a release asset" do - asset_url = "https://api.github.com/repos/api-playground/api-sandbox/releases/assets/21313" - request = stub_delete(asset_url).to_return(:status => 204) + describe '.delete_release_asset' do + it 'deletes a release asset' do + asset_url = 'https://api.github.com/repos/api-playground/api-sandbox/releases/assets/21313' + request = stub_delete(asset_url).to_return(status: 204) expect(@client.delete_release_asset(asset_url)).to be true assert_requested request end end - end describe '.release_for_tag', :vcr do - it "returns the release for a tag" do - release = @client.release_for_tag("octokit/octokit.rb", "v3.7.0") - expect(release.tag_name).to eq("v3.7.0") - assert_requested :get, github_url("/repos/octokit/octokit.rb/releases/tags/v3.7.0") + it 'returns the release for a tag' do + release = @client.release_for_tag('octokit/octokit.rb', 'v3.7.0') + expect(release.tag_name).to eq('v3.7.0') + assert_requested :get, github_url('/repos/octokit/octokit.rb/releases/tags/v3.7.0') end end # .release_for_tag describe '.latest_release', :vcr do - it "returns the latest release" do - result = Octokit.latest_release("octokit/octokit.rb") - assert_requested :get, github_url("/repos/octokit/octokit.rb/releases/latest") + it 'returns the latest release' do + result = Octokit.latest_release('octokit/octokit.rb') + assert_requested :get, github_url('/repos/octokit/octokit.rb/releases/latest') end end # .latest_release end diff --git a/spec/octokit/client/repositories_spec.rb b/spec/octokit/client/repositories_spec.rb index 68b7c929d..7d6ce2dba 100644 --- a/spec/octokit/client/repositories_spec.rb +++ b/spec/octokit/client/repositories_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Repositories do @@ -6,44 +8,44 @@ @client = oauth_client end - describe ".repository", :vcr do - it "returns the matching repository" do - repository = @client.repository("sferik/rails_admin") - expect(repository.name).to eq("rails_admin") - assert_requested :get, github_url("/repos/sferik/rails_admin") + describe '.repository', :vcr do + it 'returns the matching repository' do + repository = @client.repository('sferik/rails_admin') + expect(repository.name).to eq('rails_admin') + assert_requested :get, github_url('/repos/sferik/rails_admin') end - it "returns the repository, including topics" do - repository = @client.repository("github/linguist", :accept => Octokit::Preview::PREVIEW_TYPES.fetch(:topics)) + it 'returns the repository, including topics' do + repository = @client.repository('github/linguist', accept: Octokit::Preview::PREVIEW_TYPES.fetch(:topics)) expect(repository.topics).to be_kind_of Array - expect(repository.topics).to include("syntax-highlighting") + expect(repository.topics).to include('syntax-highlighting') end end # .repository - describe ".set_private" do - it "sets a repository private" do + describe '.set_private' do + it 'sets a repository private' do # Stub this because Padawan is on a free plan - request = stub_patch(github_url("/repos/#{@test_repo}")). - with(:body => {:private => true, :name => test_github_repository}.to_json) + request = stub_patch(github_url("/repos/#{@test_repo}")) + .with(body: { private: true, name: test_github_repository }.to_json) @client.set_private @test_repo assert_requested request end end # .set_private - describe ".set_public" do - it "sets a repository public" do + describe '.set_public' do + it 'sets a repository public' do # Stub this because Padawan is on a free plan - request = stub_patch(github_url("/repos/#{@test_repo}")). - with(:body => {:private => false, :name => test_github_repository}.to_json) + request = stub_patch(github_url("/repos/#{@test_repo}")) + .with(body: { private: false, name: test_github_repository }.to_json) @client.set_public @test_repo assert_requested request end end # .set_public - describe ".create_repository", :vcr do - it "creates a repository for an organization" do - repository = @client.create_repository("an-org-repo", :organization => test_github_org) - expect(repository.name).to eq("an-org-repo") + describe '.create_repository', :vcr do + it 'creates a repository for an organization' do + repository = @client.create_repository('an-org-repo', organization: test_github_org) + expect(repository.name).to eq('an-org-repo') assert_requested :post, github_url("/orgs/#{test_github_org}/repos") # cleanup @@ -53,14 +55,14 @@ end end - it "creates a repository for an organization by ID" do - request = stub_post(github_url("/organizations/1/repos")) - repository = @client.create_repository("an-org-repo", :organization => 1) + it 'creates a repository for an organization by ID' do + request = stub_post(github_url('/organizations/1/repos')) + repository = @client.create_repository('an-org-repo', organization: 1) assert_requested request end end - describe ".edit_repository", :vcr do + describe '.edit_repository', :vcr do before(:each) do @repo = @client.create_repository(test_github_repository) end @@ -69,50 +71,50 @@ @client.delete_repository(@repo.full_name) end - context "is_template is passed in params", :vcr do - it "uses the template repositories preview flag and succeeds" do + context 'is_template is passed in params', :vcr do + it 'uses the template repositories preview flag and succeeds' do @client.edit_repository(@repo.full_name, is_template: true) expect(@client.repository(@repo.full_name).is_template).to be true end end end - describe ".add_deploy_key" do - it "adds a repository deploy keys" do + describe '.add_deploy_key' do + it 'adds a repository deploy keys' do request = stub_post(github_url("/repos/#{@test_repo}/keys")) - @client.add_deploy_key(@test_repo, "Padawan", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDN/h7Hf5TA6G4p19deF8YS9COfuBd133GPs49tO6AU/DKIt7tlitbnUnttT0VbNZM4fplyinPu5vJl60eusn/Ngq2vDfSHP5SfgHfA9H8cnHGPYG7w6F0CujFB3tjBhHa3L6Je50E3NC4+BGGhZMpUoTClEI5yEzx3qosRfpfJu/2MUp/V2aARCAiHUlUoj5eiB15zC25uDsY7SYxkh1JO0ecKSMISc/OCdg0kwi7it4t7S/qm8Wh9pVGuA5FmVk8w0hvL+hHWB9GT02WPqiesMaS9Sj3t0yuRwgwzLDaudQPKKTKYXi+SjwXxTJ/lei2bZTMC4QxYbqfqYQt66pQB wynn.netherland+api-padawan@gmail.com" ) + @client.add_deploy_key(@test_repo, 'Padawan', 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDN/h7Hf5TA6G4p19deF8YS9COfuBd133GPs49tO6AU/DKIt7tlitbnUnttT0VbNZM4fplyinPu5vJl60eusn/Ngq2vDfSHP5SfgHfA9H8cnHGPYG7w6F0CujFB3tjBhHa3L6Je50E3NC4+BGGhZMpUoTClEI5yEzx3qosRfpfJu/2MUp/V2aARCAiHUlUoj5eiB15zC25uDsY7SYxkh1JO0ecKSMISc/OCdg0kwi7it4t7S/qm8Wh9pVGuA5FmVk8w0hvL+hHWB9GT02WPqiesMaS9Sj3t0yuRwgwzLDaudQPKKTKYXi+SjwXxTJ/lei2bZTMC4QxYbqfqYQt66pQB wynn.netherland+api-padawan@gmail.com') assert_requested request end end # .add_deploy_key - describe ".deploy_key" do - it "returns a specific deploy key for a repo" do - key_id = 8675309 + describe '.deploy_key' do + it 'returns a specific deploy key for a repo' do + key_id = 8_675_309 request = stub_get github_url "/repos/#{@test_repo}/keys/#{key_id}" @client.deploy_key @test_repo, key_id assert_requested request end end # .deploy_key - describe ".edit_deploy_key" do - it "modifies a deploy key" do - key_id = 8675309 - request = stub_patch(github_url "/repos/#{@test_repo}/keys/#{key_id}").to_return(:status => 405) - expect { @client.edit_deploy_key(@test_repo, key_id, :title => 'Staging') }. - to raise_error(Octokit::MethodNotAllowed) + describe '.edit_deploy_key' do + it 'modifies a deploy key' do + key_id = 8_675_309 + request = stub_patch(github_url("/repos/#{@test_repo}/keys/#{key_id}")).to_return(status: 405) + expect { @client.edit_deploy_key(@test_repo, key_id, title: 'Staging') } + .to raise_error(Octokit::MethodNotAllowed) assert_requested request end end # .edit_deploy_key - describe ".remove_deploy_key" do - it "removes a repository deploy keys" do + describe '.remove_deploy_key' do + it 'removes a repository deploy keys' do request = stub_delete(github_url("/repos/#{@test_repo}/keys/1234")) @client.remove_deploy_key(@test_repo, 1234) assert_requested request end end # .remove_deploy_key - context "with repository" do + context 'with repository' do before(:each) do @repo = @client.create_repository(test_github_repository, auto_init: true) end @@ -124,34 +126,34 @@ end end - describe ".create_repository_from_template", :vcr do + describe '.create_repository_from_template', :vcr do before do @client.edit_repository(@repo.full_name, is_template: true) end - it "generates a repository from the template" do - @client.create_repository_from_template(@repo.id, "Cloned repo") + it 'generates a repository from the template' do + @client.create_repository_from_template(@repo.id, 'Cloned repo') assert_requested :post, github_url("/repositories/#{@repo.id}/generate") end end - describe ".create_repository", :vcr do - it "creates a repository" do - expect(@repo.name).to eq("an-repo") - assert_requested :post, github_url("/user/repos") + describe '.create_repository', :vcr do + it 'creates a repository' do + expect(@repo.name).to eq('an-repo') + assert_requested :post, github_url('/user/repos') end end # .create_repository - describe ".update_repository", :vcr do - it "updates the matching repository" do + describe '.update_repository', :vcr do + it 'updates the matching repository' do description = "It's epic" - repository = @client.edit_repository(@repo.full_name, :description => description) + repository = @client.edit_repository(@repo.full_name, description: description) expect(repository.description).to eq(description) assert_requested :patch, github_url("/repos/#{@repo.full_name}") end end # .update_repository - describe ".deploy_keys", :vcr do + describe '.deploy_keys', :vcr do it "returns a repository's deploy keys" do public_keys = @client.deploy_keys @repo.full_name expect(public_keys).to be_kind_of Array @@ -159,104 +161,104 @@ end end # .deploy_keys - describe ".add_collaborator", :vcr do - it "adds a repository collaborators" do + describe '.add_collaborator', :vcr do + it 'adds a repository collaborators' do begin - @client.remove_collaborator(@repo.full_name, "pengwynn") + @client.remove_collaborator(@repo.full_name, 'pengwynn') rescue Octokit::NotFound end - @client.add_collaborator(@repo.full_name, "pengwynn") + @client.add_collaborator(@repo.full_name, 'pengwynn') assert_requested :put, github_url("/repos/#{@repo.full_name}/collaborators/pengwynn") end end # .add_collaborator - describe ".remove_collaborator", :vcr do - it "removes a repository collaborators" do + describe '.remove_collaborator', :vcr do + it 'removes a repository collaborators' do begin - @client.add_collaborator(@repo.full_name, "pengwynn") + @client.add_collaborator(@repo.full_name, 'pengwynn') rescue Octokit::UnprocessableEntity end - @client.remove_collaborator(@repo.full_name, "pengwynn") + @client.remove_collaborator(@repo.full_name, 'pengwynn') assert_requested :delete, github_url("/repos/#{@repo.full_name}/collaborators/pengwynn") end end # .remove_collaborator - describe ".collaborator?", :vcr do - it "checks if a user is a repository collaborator" do + describe '.collaborator?', :vcr do + it 'checks if a user is a repository collaborator' do begin - @client.add_collaborator(@repo.full_name, "pengwynn") + @client.add_collaborator(@repo.full_name, 'pengwynn') rescue Octokit::UnprocessableEntity end - @client.collaborator?(@repo.full_name, "pengwynn") + @client.collaborator?(@repo.full_name, 'pengwynn') assert_requested :get, github_url("/repos/#{@repo.full_name}/collaborators/pengwynn") end end # .collaborator? - describe ".repository_teams", :vcr do - it "returns all repository teams" do + describe '.repository_teams', :vcr do + it 'returns all repository teams' do teams = @client.repository_teams(@repo.full_name) assert_requested :get, github_url("/repos/#{@repo.full_name}/teams") expect(teams).to be_kind_of Array end end # .repository_teams - describe ".delete_repository", :vcr do - it "deletes a repository" do - @client.delete_repository("#{@repo.full_name}") + describe '.delete_repository', :vcr do + it 'deletes a repository' do + @client.delete_repository(@repo.full_name.to_s) assert_requested :delete, github_url("/repos/#{@repo.full_name}") end end # .delete_repository - describe ".dispatch_event", :vcr do - it "creates a dispatch event" do + describe '.dispatch_event', :vcr do + it 'creates a dispatch event' do event_dispatched = @client.dispatch_event(@repo.full_name, 'test dispatch event') expect(event_dispatched).to be_truthy assert_requested :post, github_url("/repos/#{@repo.full_name}/dispatches") end end # .dispatch_event - describe ".branch_protection", :vcr do - it "returns nil for an unprotected branch" do - branch_protection = @client.branch_protection(@repo.full_name, "master", accept: preview_header) + describe '.branch_protection', :vcr do + it 'returns nil for an unprotected branch' do + branch_protection = @client.branch_protection(@repo.full_name, 'master', accept: preview_header) expect(branch_protection).to be_nil assert_requested :get, github_url("/repos/#{@repo.full_name}/branches/master/protection") end - context "with protected branch" do + context 'with protected branch' do before(:each) do protect_params = { accept: preview_header, enforce_admins: true, required_pull_request_reviews: nil, - required_status_checks: { strict: true, contexts: []} + required_status_checks: { strict: true, contexts: [] } } - @client.protect_branch(@repo.full_name, "master", protect_params) + @client.protect_branch(@repo.full_name, 'master', protect_params) end - it "returns branch protection summary" do - branch_protection = @client.branch_protection(@repo.full_name, "master", accept: preview_header) + it 'returns branch protection summary' do + branch_protection = @client.branch_protection(@repo.full_name, 'master', accept: preview_header) expect(branch_protection).not_to be_nil assert_requested :get, github_url("/repos/#{@repo.full_name}/branches/master/protection") end end end # .branch_protection - describe ".topics", :vcr do - it "returns repository topics" do - topics = Octokit.topics(@repo.full_name, :accept => Octokit::Preview::PREVIEW_TYPES.fetch(:topics)) - expect(topics.names).to include("octokit") + describe '.topics', :vcr do + it 'returns repository topics' do + topics = Octokit.topics(@repo.full_name, accept: Octokit::Preview::PREVIEW_TYPES.fetch(:topics)) + expect(topics.names).to include('octokit') assert_requested :get, github_url("/repos/#{@repo.full_name}/topics") end end # .topics - describe ".replace_all_topics", :vcr do - it "replaces all topics for a repository" do - new_topics = ["octocat", "github", "github-api"] + describe '.replace_all_topics', :vcr do + it 'replaces all topics for a repository' do + new_topics = %w[octocat github github-api] options = { - :accept => Octokit::Preview::PREVIEW_TYPES.fetch(:topics) + accept: Octokit::Preview::PREVIEW_TYPES.fetch(:topics) } topics = @client.replace_all_topics(@repo.full_name, new_topics, options) expect(topics.names.sort).to eq(new_topics.sort) @@ -265,147 +267,147 @@ end # .replace_all_topics end # with repository - describe ".repositories", :vcr do + describe '.repositories', :vcr do it "returns a user's repositories" do - repositories = Octokit.repositories("sferik") + repositories = Octokit.repositories('sferik') expect(repositories).to be_kind_of Array - assert_requested :get, github_url("/users/sferik/repos") + assert_requested :get, github_url('/users/sferik/repos') end it "returns authenticated user's repositories" do repositories = @client.repositories expect(repositories).to be_kind_of Array - assert_requested :get, github_url("/user/repos") + assert_requested :get, github_url('/user/repos') end end # .repositories - describe ".all_repositories", :vcr do - it "returns all repositories on github" do + describe '.all_repositories', :vcr do + it 'returns all repositories on github' do repositories = Octokit.all_repositories expect(repositories).to be_kind_of Array - assert_requested :get, github_url("/repositories") + assert_requested :get, github_url('/repositories') end end # .all_repositories - describe ".star", :vcr do - it "stars a repository" do - result = @client.star("sferik/rails_admin") + describe '.star', :vcr do + it 'stars a repository' do + result = @client.star('sferik/rails_admin') expect(result).to be true - assert_requested :put, github_url("/user/starred/sferik/rails_admin") + assert_requested :put, github_url('/user/starred/sferik/rails_admin') end end # .star - describe ".unstar", :vcr do - it "unstars a repository" do - result = @client.unstar("sferik/rails_admin") + describe '.unstar', :vcr do + it 'unstars a repository' do + result = @client.unstar('sferik/rails_admin') expect(result).to be true - assert_requested :delete, github_url("/user/starred/sferik/rails_admin") + assert_requested :delete, github_url('/user/starred/sferik/rails_admin') end end # .unstar - describe ".watch", :vcr do - it "watches a repository" do - result = @client.watch("sferik/rails_admin") + describe '.watch', :vcr do + it 'watches a repository' do + result = @client.watch('sferik/rails_admin') expect(result).to be true - assert_requested :put, github_url("/user/watched/sferik/rails_admin") + assert_requested :put, github_url('/user/watched/sferik/rails_admin') end end # .watch - describe ".unwatch", :vcr do - it "unwatches a repository" do - result = @client.unwatch("sferik/rails_admin") + describe '.unwatch', :vcr do + it 'unwatches a repository' do + result = @client.unwatch('sferik/rails_admin') expect(result).to be true - assert_requested :delete, github_url("/user/watched/sferik/rails_admin") + assert_requested :delete, github_url('/user/watched/sferik/rails_admin') end end # .unwatch - describe ".fork", :vcr do - it "forks a repository" do - repository = @client.fork("sferik/rails_admin") - assert_requested :post, github_url("/repos/sferik/rails_admin/forks") + describe '.fork', :vcr do + it 'forks a repository' do + repository = @client.fork('sferik/rails_admin') + assert_requested :post, github_url('/repos/sferik/rails_admin/forks') # cleanup @client.delete_repository(repository.full_name) end end # .fork - describe ".collaborators", :vcr do + describe '.collaborators', :vcr do it "returns a repository's collaborators" do - collaborators = Octokit.collaborators("sferik/rails_admin") + collaborators = Octokit.collaborators('sferik/rails_admin') expect(collaborators).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/collaborators") + assert_requested :get, github_url('/repos/sferik/rails_admin/collaborators') end end # .collaborators - describe ".contributors", :vcr do - it "returns repository contributors" do - contributors = Octokit.contributors("sferik/rails_admin", true) + describe '.contributors', :vcr do + it 'returns repository contributors' do + contributors = Octokit.contributors('sferik/rails_admin', true) expect(contributors).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/contributors?anon=1") + assert_requested :get, github_url('/repos/sferik/rails_admin/contributors?anon=1') end - it "returns repository contributors excluding anonymous" do - contributors = Octokit.contributors("sferik/rails_admin") + it 'returns repository contributors excluding anonymous' do + contributors = Octokit.contributors('sferik/rails_admin') expect(contributors).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/contributors") + assert_requested :get, github_url('/repos/sferik/rails_admin/contributors') end end # .contributors - describe ".stargazers", :vcr do - it "returns all repository stargazers" do - stargazers = Octokit.stargazers("sferik/rails_admin") + describe '.stargazers', :vcr do + it 'returns all repository stargazers' do + stargazers = Octokit.stargazers('sferik/rails_admin') expect(stargazers).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/stargazers") + assert_requested :get, github_url('/repos/sferik/rails_admin/stargazers') end end # .stargazers - describe ".watchers", :vcr do - it "returns all repository watchers" do - watchers = Octokit.watchers("sferik/rails_admin") + describe '.watchers', :vcr do + it 'returns all repository watchers' do + watchers = Octokit.watchers('sferik/rails_admin') expect(watchers).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/watchers") + assert_requested :get, github_url('/repos/sferik/rails_admin/watchers') end end # .watchers - describe ".network", :vcr do + describe '.network', :vcr do it "returns a repository's network" do - network = Octokit.network("sferik/rails_admin") + network = Octokit.network('sferik/rails_admin') expect(network).to be_kind_of Array - assert_requested :get, github_url("/repos/sferik/rails_admin/forks") + assert_requested :get, github_url('/repos/sferik/rails_admin/forks') end end # .network - describe ".languages", :vcr do + describe '.languages', :vcr do it "returns a repository's languages" do - languages = Octokit.languages("sferik/rails_admin") + languages = Octokit.languages('sferik/rails_admin') expect(languages[:Ruby]).not_to be_nil - assert_requested :get, github_url("/repos/sferik/rails_admin/languages") + assert_requested :get, github_url('/repos/sferik/rails_admin/languages') end end # .languages - describe ".tags", :vcr do + describe '.tags', :vcr do it "returns a repository's tags" do - tags = Octokit.tags("octokit/octokit.rb") + tags = Octokit.tags('octokit/octokit.rb') expect(tags).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/tags") + assert_requested :get, github_url('/repos/octokit/octokit.rb/tags') end end # .tags - describe ".branches", :vcr do + describe '.branches', :vcr do it "returns a repository's branches" do - branches = Octokit.branches("octokit/octokit.rb") + branches = Octokit.branches('octokit/octokit.rb') expect(branches).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/branches") + assert_requested :get, github_url('/repos/octokit/octokit.rb/branches') end - it "returns a single branch" do - branch = Octokit.branch("octokit/octokit.rb", "master") + it 'returns a single branch' do + branch = Octokit.branch('octokit/octokit.rb', 'master') expect(branch.commit.sha).not_to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/branches/master") + assert_requested :get, github_url('/repos/octokit/octokit.rb/branches/master') end end # .branches context 'with repository' do before(:each) do - @repo = @client.create_repository("an-repo", auto_init: true) + @repo = @client.create_repository('an-repo', auto_init: true) end after(:each) do @@ -415,30 +417,28 @@ end end - describe ".permission_level", :vcr do - it "returns the permission level a user has on a repository" do - @client.permission_level(@repo.full_name, "lizzhale") + describe '.permission_level', :vcr do + it 'returns the permission level a user has on a repository' do + @client.permission_level(@repo.full_name, 'lizzhale') assert_requested :get, github_url("/repos/#{@repo.full_name}/collaborators/lizzhale/permission") end end # .permission_level - describe ".protect_branch", :vcr do - it "protects a single branch" do - branch = @client.protect_branch(@repo.full_name, "master", + describe '.protect_branch', :vcr do + it 'protects a single branch' do + branch = @client.protect_branch(@repo.full_name, 'master', { accept: preview_header, required_status_checks: { strict: true, contexts: [] }, enforce_admins: true, - required_pull_request_reviews: nil, - } - ) + required_pull_request_reviews: nil }) expect(branch.url).not_to be_nil assert_requested :put, github_url("/repos/#{@repo.full_name}/branches/master/protection") end - it "protects a single branch with required_status_checks" do + it 'protects a single branch with required_status_checks' do rules = { required_status_checks: { strict: true, @@ -448,13 +448,13 @@ required_pull_request_reviews: nil, restrictions: nil } - branch = @client.protect_branch(@repo.full_name, "master", rules.merge(accept: preview_header)) + branch = @client.protect_branch(@repo.full_name, 'master', rules.merge(accept: preview_header)) expect(branch.required_status_checks.strict).to be true expect(branch.restrictions).to be_nil assert_requested :put, github_url("/repos/#{@repo.full_name}/branches/master/protection") end - it "protects a single branch with required_approving_review_count" do + it 'protects a single branch with required_approving_review_count' do rules = { required_status_checks: { strict: true, @@ -463,17 +463,16 @@ enforce_admins: true, required_pull_request_reviews: { required_approving_review_count: 2 - }, + } } - branch = @client.protect_branch(@repo.full_name, "master", rules.merge(accept: preview_header)) + branch = @client.protect_branch(@repo.full_name, 'master', rules.merge(accept: preview_header)) expect(branch.required_pull_request_reviews.required_approving_review_count).to eq 2 assert_requested :put, github_url("/repos/#{@repo.full_name}/branches/master/protection") end - end # .protect_branch - context "with protected branch" do + context 'with protected branch' do before(:each) do protection = { required_status_checks: { @@ -485,96 +484,95 @@ restrictions: nil } - @client.protect_branch(@repo.full_name, "master", protection.merge(accept: preview_header)) + @client.protect_branch(@repo.full_name, 'master', protection.merge(accept: preview_header)) end - describe ".unprotect_branch", :vcr do - it "unprotects a single branch" do - branch = @client.unprotect_branch(@repo.full_name, "master", accept: preview_header) + describe '.unprotect_branch', :vcr do + it 'unprotects a single branch' do + branch = @client.unprotect_branch(@repo.full_name, 'master', accept: preview_header) expect(branch).to eq true assert_requested :delete, github_url("/repos/#{@repo.full_name}/branches/master/protection") end end # .unprotect_branch - end # with protected_branch - describe ".rename_branch", :vcr do - it "renames a single branch" do - branch = @client.rename_branch(@repo.full_name, "master", "main") - expect(branch.name).to eq "main" + describe '.rename_branch', :vcr do + it 'renames a single branch' do + branch = @client.rename_branch(@repo.full_name, 'master', 'main') + expect(branch.name).to eq 'main' assert_requested :post, github_url("/repos/#{@repo.full_name}/branches/master/rename") end end # .rename_branch end # with repository - describe ".assignees", :vcr do - it "lists all the available assignees (owner + collaborators)" do - assignees = Octokit.repo_assignees("octokit/octokit.rb") + describe '.assignees', :vcr do + it 'lists all the available assignees (owner + collaborators)' do + assignees = Octokit.repo_assignees('octokit/octokit.rb') expect(assignees).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/assignees") + assert_requested :get, github_url('/repos/octokit/octokit.rb/assignees') end end # .assignees - describe ".check_assignee", :vcr do - it "checks to see if a particular user is an assignee for a repository" do - Octokit.check_assignee("octokit/octokit.rb", 'andrew') - assert_requested :get, github_url("/repos/octokit/octokit.rb/assignees/andrew") + describe '.check_assignee', :vcr do + it 'checks to see if a particular user is an assignee for a repository' do + Octokit.check_assignee('octokit/octokit.rb', 'andrew') + assert_requested :get, github_url('/repos/octokit/octokit.rb/assignees/andrew') end end # .check_assignee - describe ".subscribers", :vcr do - it "lists all the users watching the repository" do - subscribers = Octokit.subscribers("octokit/octokit.rb") + describe '.subscribers', :vcr do + it 'lists all the users watching the repository' do + subscribers = Octokit.subscribers('octokit/octokit.rb') expect(subscribers).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/subscribers") + assert_requested :get, github_url('/repos/octokit/octokit.rb/subscribers') end end # .subscribers - describe ".update_subscription", :vcr do - it "updates a repository subscription" do - @client.update_subscription("octokit/octokit.rb", :subscribed => false) - assert_requested :put, github_url("/repos/octokit/octokit.rb/subscription") + describe '.update_subscription', :vcr do + it 'updates a repository subscription' do + @client.update_subscription('octokit/octokit.rb', subscribed: false) + assert_requested :put, github_url('/repos/octokit/octokit.rb/subscription') end end # .update_subscription - describe ".subscription", :vcr do - it "returns a repository subscription" do - @client.subscription("octokit/octokit.rb") - assert_requested :get, github_url("/repos/octokit/octokit.rb/subscription") + describe '.subscription', :vcr do + it 'returns a repository subscription' do + @client.subscription('octokit/octokit.rb') + assert_requested :get, github_url('/repos/octokit/octokit.rb/subscription') end end # .subscription - describe ".delete_subscription", :vcr do - it "returns true when repo subscription deleted" do - @client.delete_subscription("octokit/octokit.rb") - assert_requested :delete, github_url("/repos/octokit/octokit.rb/subscription") + describe '.delete_subscription', :vcr do + it 'returns true when repo subscription deleted' do + @client.delete_subscription('octokit/octokit.rb') + assert_requested :delete, github_url('/repos/octokit/octokit.rb/subscription') end end # .delete_subscription - describe ".repository?", :vcr do - it "returns true if the repository exists" do - result = @client.repository?("sferik/rails_admin") + describe '.repository?', :vcr do + it 'returns true if the repository exists' do + result = @client.repository?('sferik/rails_admin') expect(result).to be true - assert_requested :get, github_url("/repos/sferik/rails_admin") + assert_requested :get, github_url('/repos/sferik/rails_admin') end it "returns false if the repository doesn't exist" do - result = @client.repository?("pengwynn/octokit") + result = @client.repository?('pengwynn/octokit') expect(result).to be false - assert_requested :get, github_url("/repos/pengwynn/octokit") + assert_requested :get, github_url('/repos/pengwynn/octokit') end - it "returns false if the repository has an invalid format" do - result = @client.repository?("invalid format") + it 'returns false if the repository has an invalid format' do + result = @client.repository?('invalid format') expect(result).to be false end - it "returns false if the repository has more than one slash" do - result = @client.repository?("more_than/one/slash") + it 'returns false if the repository has more than one slash' do + result = @client.repository?('more_than/one/slash') expect(result).to be false end end # .repository? - describe ".transfer_repository", :vcr do + describe '.transfer_repository', :vcr do before do - @repository = @client.create_repository("a-repo", auto_init: true) + @repository = @client.create_repository('a-repo', auto_init: true) end after do @@ -585,7 +583,7 @@ end end - it "repository transfer from myself to my organization" do + it 'repository transfer from myself to my organization' do accept_header = Octokit::Preview::PREVIEW_TYPES[:transfer_repository] @client.transfer_repository(@repository.full_name, test_github_org, { accept: accept_header }) assert_requested :post, github_url("/repos/#{@repository.full_name}/transfer") @@ -595,10 +593,10 @@ end end # .transfer_repository - describe ".vulnerability_alerts_enabled?", :vcr do + describe '.vulnerability_alerts_enabled?', :vcr do let(:accept_preview_header) { Octokit::Preview::PREVIEW_TYPES[:vulnerability_alerts] } - it "returns true when vulnerability alerts are enabled" do + it 'returns true when vulnerability alerts are enabled' do @client.enable_vulnerability_alerts(@test_repo, accept: accept_preview_header) result = @client.vulnerability_alerts_enabled?(@test_repo, accept: accept_preview_header) @@ -606,7 +604,7 @@ expect(result).to be true end - it "returns false with vulnerability alerts disabled" do + it 'returns false with vulnerability alerts disabled' do @client.disable_vulnerability_alerts(@test_repo, accept: accept_preview_header) result = @client.vulnerability_alerts_enabled?(@test_repo, accept: accept_preview_header) @@ -615,20 +613,20 @@ end end # .vulnerability_alerts_enabled? - describe ".enable_vulnerability_alerts", :vcr do + describe '.enable_vulnerability_alerts', :vcr do let(:accept_preview_header) { Octokit::Preview::PREVIEW_TYPES[:vulnerability_alerts] } - it "enables vulnerability alerts for the repository" do + it 'enables vulnerability alerts for the repository' do result = @client.enable_vulnerability_alerts(@test_repo, accept: accept_preview_header) assert_requested :put, github_url("/repos/#{@test_repo}/vulnerability-alerts") expect(result).to be true end end # .enable_vulnerability_alerts - describe ".disable_vulnerability_alerts", :vcr do + describe '.disable_vulnerability_alerts', :vcr do let(:accept_preview_header) { Octokit::Preview::PREVIEW_TYPES[:vulnerability_alerts] } - it "disables vulnerability alerts for the repository" do + it 'disables vulnerability alerts for the repository' do result = @client.disable_vulnerability_alerts(@test_repo, accept: accept_preview_header) assert_requested :delete, github_url("/repos/#{@test_repo}/vulnerability-alerts") expect(result).to be true diff --git a/spec/octokit/client/repository_invitations_spec.rb b/spec/octokit/client/repository_invitations_spec.rb index 7d03c3743..fa8ae1d19 100644 --- a/spec/octokit/client/repository_invitations_spec.rb +++ b/spec/octokit/client/repository_invitations_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::RepositoryInvitations do @@ -6,9 +8,9 @@ @client = oauth_client end - context "with repository" do + context 'with repository' do before(:each) do - @repo = @client.create_repository("an-repo", :organization => test_github_org) + @repo = @client.create_repository('an-repo', organization: test_github_org) end after(:each) do @@ -18,44 +20,44 @@ end end - describe ".invite_user_to_repository", :vcr do - it "invites a user to a repository" do - @client.invite_user_to_repository(@repo.id, "tarebyte") + describe '.invite_user_to_repository', :vcr do + it 'invites a user to a repository' do + @client.invite_user_to_repository(@repo.id, 'tarebyte') assert_requested :put, github_url("/repositories/#{@repo.id}/collaborators/tarebyte") end end - describe ".repository_invitations", :vcr do - it "lists the repositories outstanding invitations" do + describe '.repository_invitations', :vcr do + it 'lists the repositories outstanding invitations' do invitations = @client.repository_invitations(@repo.id) expect(invitations).to be_kind_of(Array) assert_requested :get, github_url("/repositories/#{@repo.id}/invitations") end end - describe ".user_repository_invitations", :vcr do - it "lists the users repository invitations" do + describe '.user_repository_invitations', :vcr do + it 'lists the users repository invitations' do invitations = @client.user_repository_invitations expect(invitations).to be_kind_of(Array) - assert_requested :get, github_url("/user/repository_invitations") + assert_requested :get, github_url('/user/repository_invitations') end end - context "with stubbed repository invitation" do + context 'with stubbed repository invitation' do before do @invitation_id = 8_675_309 end - describe ".accept_repository_invitation", :vcr do - it "accepts the repository invitation on behalf of the user" do + describe '.accept_repository_invitation', :vcr do + it 'accepts the repository invitation on behalf of the user' do request = stub_patch("/user/repository_invitations/#{@invitation_id}") @client.accept_repository_invitation(@invitation_id) assert_requested request end end - describe ".decline_repository_invitation", :vcr do - it "declines the repository invitation on behalf of the user" do + describe '.decline_repository_invitation', :vcr do + it 'declines the repository invitation on behalf of the user' do request = stub_delete("/user/repository_invitations/#{@invitation_id}") @client.decline_repository_invitation(@invitation_id) assert_requested request @@ -63,21 +65,21 @@ end end - context "with repository invitation" do + context 'with repository invitation' do before(:each) do - @invitation = @client.invite_user_to_repository(@repo.id, "tarebyte") + @invitation = @client.invite_user_to_repository(@repo.id, 'tarebyte') end - describe ".delete_repository_invitation", :vcr do - it "deletes the repository invitation" do + describe '.delete_repository_invitation', :vcr do + it 'deletes the repository invitation' do @client.delete_repository_invitation(@repo.id, @invitation.id) assert_requested :delete, github_url("/repositories/#{@repo.id}/invitations/#{@invitation.id}") end end - describe ".update_repository_invitation", :vcr do - it "updates the repository invitation" do - @client.update_repository_invitation(@repo.id, @invitation.id, :permissions => "read") + describe '.update_repository_invitation', :vcr do + it 'updates the repository invitation' do + @client.update_repository_invitation(@repo.id, @invitation.id, permissions: 'read') assert_requested :patch, github_url("/repositories/#{@repo.id}/invitations/#{@invitation.id}") end end diff --git a/spec/octokit/client/reviews_spec.rb b/spec/octokit/client/reviews_spec.rb index 09a476b70..d7953b676 100644 --- a/spec/octokit/client/reviews_spec.rb +++ b/spec/octokit/client/reviews_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' require 'securerandom' @@ -21,7 +23,7 @@ describe '.pull_request_review', :vcr do let(:test_pr) { 825 } - let(:test_review) { 6505518 } + let(:test_review) { 6_505_518 } it 'returns a single pull request review' do reviews = @client.pull_request_review('octokit/octokit.rb', test_pr, @@ -35,7 +37,7 @@ describe '.pull_request_review_comments', :vcr do let(:test_pr) { 825 } - let(:test_review) { 6505518 } + let(:test_review) { 6_505_518 } it 'returns all comments for a single review' do reviews = @client.pull_request_review_comments('octokit/octokit.rb', @@ -58,7 +60,7 @@ end end - context 'with pull request review' do + context 'with pull request review' do describe '.update_pull_request_review' do it 'updates the review summary comment with new text' do requested_url = github_url('/repos/octokit/octokit.rb/pulls/1/reviews/1') @@ -117,21 +119,21 @@ collaborator_client = Octokit::Client.new(access_token: test_github_collaborator_token) collaborator_client.accept_repository_invitation(invitation.id) - @client.add_team_repository(test_github_team_id, @repo.full_name, permission: "push") + @client.add_team_repository(test_github_team_id, @repo.full_name, permission: 'push') end describe '.pull_request_review_requests' do before do options = { reviewers: [test_github_collaborator_login], - team_reviewers: [test_github_team_slug], + team_reviewers: [test_github_team_slug] } @client.request_pull_request_review(@repo.full_name, @pull.number, options) end after do options = { reviewers: [test_github_collaborator_login], - team_reviewers: [test_github_team_slug], + team_reviewers: [test_github_team_slug] } @client.delete_pull_request_review_request(@repo.full_name, @pull.number, options) end @@ -154,14 +156,14 @@ after do options = { reviewers: [test_github_collaborator_login], - team_reviewers: [test_github_team_slug], + team_reviewers: [test_github_team_slug] } @client.delete_pull_request_review_request(@repo.full_name, @pull.number, options) end it 'requests a new pull request review from a user' do options = { - reviewers: [test_github_collaborator_login], + reviewers: [test_github_collaborator_login] } review_request = @client.request_pull_request_review(@repo.full_name, @pull.number, options) @@ -173,7 +175,7 @@ it 'requests a new pull request review from a team' do options = { - team_reviewers: [test_github_team_slug], + team_reviewers: [test_github_team_slug] } review_request = @client.request_pull_request_review(@repo.full_name, @pull.number, options) @@ -188,14 +190,14 @@ before do options = { reviewers: [test_github_collaborator_login], - team_reviewers: [test_github_team_slug], + team_reviewers: [test_github_team_slug] } @client.request_pull_request_review(@repo.full_name, @pull.number, options) end it 'deletes a requests for a pull request review from a user' do options = { - reviewers: [test_github_collaborator_login], + reviewers: [test_github_collaborator_login] } review = @client.delete_pull_request_review_request(@repo.full_name, @pull.number, options) expect(review).to be_kind_of Sawyer::Resource @@ -207,7 +209,7 @@ it 'deletes a requests for a pull request review from a team' do options = { reviewers: [], - team_reviewers: [test_github_team_slug], + team_reviewers: [test_github_team_slug] } review = @client.delete_pull_request_review_request(@repo.full_name, @pull.number, options) expect(review).to be_kind_of Sawyer::Resource diff --git a/spec/octokit/client/say_spec.rb b/spec/octokit/client/say_spec.rb index 9ecbacacd..329314a8b 100644 --- a/spec/octokit/client/say_spec.rb +++ b/spec/octokit/client/say_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Say do @@ -6,18 +8,17 @@ @client = oauth_client end - describe ".say", :vcr do - it "returns an ASCII octocat" do + describe '.say', :vcr do + it 'returns an ASCII octocat' do text = @client.say expect(text).to match(/MMMMMMMMMMMMMMMMMMMMM/) - assert_requested :get, github_url("/octocat") + assert_requested :get, github_url('/octocat') end - it "returns an ASCII octocat with custom text" do - text = @client.say "There is no need to be upset" + it 'returns an ASCII octocat with custom text' do + text = @client.say 'There is no need to be upset' expect(text).to match(/upset/) - assert_requested :get, github_url("/octocat?s=There+is+no+need+to+be+upset") + assert_requested :get, github_url('/octocat?s=There+is+no+need+to+be+upset') end end - end diff --git a/spec/octokit/client/search_spec.rb b/spec/octokit/client/search_spec.rb index bfd967819..09670be03 100644 --- a/spec/octokit/client/search_spec.rb +++ b/spec/octokit/client/search_spec.rb @@ -1,17 +1,18 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Search do - before do Octokit.reset! @client = oauth_client end - describe ".search_code" do - it "searches code", :vcr do + describe '.search_code' do + it 'searches code', :vcr do results = @client.search_code 'code user:github in:file extension:gemspec -repo:octokit/octokit.rb', \ - :sort => 'indexed', - :order => 'asc' + sort: 'indexed', + order: 'asc' assert_requested :get, github_url('/search/code?q=code%20user:github%20in:file%20extension:gemspec%20-repo:octokit/octokit.rb&sort=indexed&order=asc') expect(results.total_count).to be_kind_of Integer @@ -19,12 +20,12 @@ end end # .search_code - describe ".search_commits" do - it "searches commits", :vcr do + describe '.search_commits' do + it 'searches commits', :vcr do results = @client.search_commits 'repo:octokit/octokit.rb author:jasonrudolph', \ - :sort => 'author-date', - :order => 'asc', - :accept => preview_header + sort: 'author-date', + order: 'asc', + accept: preview_header assert_requested :get, github_url('/search/commits?q=repo:octokit/octokit.rb%20author:jasonrudolph&sort=author-date&order=asc') expect(results.total_count).to be_kind_of Integer @@ -32,11 +33,11 @@ end end # .search_commits - describe ".search_issues" do - it "searches issues", :vcr do + describe '.search_issues' do + it 'searches issues', :vcr do results = @client.search_issues 'http author:jasonrudolph', \ - :sort => 'created', - :order => 'desc' + sort: 'created', + order: 'desc' assert_requested :get, github_url('/search/issues?q=http%20author:jasonrudolph&sort=created&order=desc') expect(results.total_count).to be_kind_of Integer @@ -44,11 +45,11 @@ end end # .search_issues - describe ".search_repositories" do - it "searches repositories", :vcr do + describe '.search_repositories' do + it 'searches repositories', :vcr do results = @client.search_repositories 'tetris language:assembly', \ - :sort => 'stars', - :order => 'desc' + sort: 'stars', + order: 'desc' assert_requested :get, github_url('/search/repositories?q=tetris%20language:assembly&sort=stars&order=desc') expect(results.total_count).to be_kind_of Integer @@ -56,20 +57,20 @@ end end # .search_repositories - describe ".search_users" do - it "searches users", :vcr do + describe '.search_users' do + it 'searches users', :vcr do results = @client.search_users 'mike followers:>10', \ - :sort => 'joined', - :order => 'desc' + sort: 'joined', + order: 'desc' assert_requested :get, github_url('/search/users?q=mike%20followers:%3E10&sort=joined&order=desc') expect(results.total_count).to be_kind_of Integer expect(results.items).to be_kind_of Array end - it "utilizes auto_pagination", :vcr do + it 'utilizes auto_pagination', :vcr do @client.auto_paginate = true - results = @client.search_users 'user:pengwynn user:defunkt', :per_page => 1 + results = @client.search_users 'user:pengwynn user:defunkt', per_page: 1 expect(results.total_count).to eq(2) expect(results.items.length).to eq(2) @@ -80,4 +81,3 @@ def preview_header Octokit::Preview::PREVIEW_TYPES[:commit_search] end end - diff --git a/spec/octokit/client/service_status_spec.rb b/spec/octokit/client/service_status_spec.rb index 086d6803b..7e549e1ac 100644 --- a/spec/octokit/client/service_status_spec.rb +++ b/spec/octokit/client/service_status_spec.rb @@ -1,43 +1,43 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::ServiceStatus do - before do Octokit.reset! end - describe ".github_status_summary", :vcr do - it "returns the current system status summary" do + describe '.github_status_summary', :vcr do + it 'returns the current system status summary' do current_status = Octokit.github_status_summary expect(current_status.status).not_to be_nil expect(current_status.components).not_to be_nil - assert_requested :get, "https://www.githubstatus.com/api/v2/summary.json" + assert_requested :get, 'https://www.githubstatus.com/api/v2/summary.json' end end # .github_status_summary - describe ".github_status", :vcr do - it "returns the current system status" do + describe '.github_status', :vcr do + it 'returns the current system status' do current_status = Octokit.github_status expect(current_status.status).not_to be_nil - assert_requested :get, "https://www.githubstatus.com/api/v2/status.json" + assert_requested :get, 'https://www.githubstatus.com/api/v2/status.json' end end # .github_status - describe ".github_status_last_message", :vcr do - it "returns the last human message" do + describe '.github_status_last_message', :vcr do + it 'returns the last human message' do message = Octokit.github_status_last_message expect(message.status).not_to be_nil expect(message.description).not_to be_nil - assert_requested :get, "https://www.githubstatus.com/api/v2/components.json" + assert_requested :get, 'https://www.githubstatus.com/api/v2/components.json' end end # .github_status_last_message - describe ".github_status_messages", :vcr do - it "returns the most recent status messages" do + describe '.github_status_messages', :vcr do + it 'returns the most recent status messages' do messages = Octokit.github_status_messages expect(messages).to be_kind_of Array - assert_requested :get, "https://www.githubstatus.com/api/v2/components.json" + assert_requested :get, 'https://www.githubstatus.com/api/v2/components.json' end end # .github_status_messages - end diff --git a/spec/octokit/client/source_import_spec.rb b/spec/octokit/client/source_import_spec.rb index 1e063eea4..0406e9d81 100644 --- a/spec/octokit/client/source_import_spec.rb +++ b/spec/octokit/client/source_import_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::SourceImport do @@ -7,7 +9,7 @@ end before(:each) do - @repo = @client.create_repository("an-repo") + @repo = @client.create_repository('an-repo') end after(:each) do @@ -17,94 +19,94 @@ end end - describe "pre deprecation" do - describe ".start_source_import", :vcr do - it "provides deprecation warning" do + describe 'pre deprecation' do + describe '.start_source_import', :vcr do + it 'provides deprecation warning' do allow(@client).to receive(:octokit_warn) - result = @client.start_source_import(@repo.full_name, "hg", "https://bitbucket.org/spraints/goboom") + result = @client.start_source_import(@repo.full_name, 'hg', 'https://bitbucket.org/spraints/goboom') expect(result).to be_kind_of Sawyer::Resource expect(@client).to have_received(:octokit_warn) - .with("Octokit#start_source_import vcs parameter is now an option, please update your call before the next major Octokit version update.") + .with('Octokit#start_source_import vcs parameter is now an option, please update your call before the next major Octokit version update.') assert_requested :put, github_url("/repos/#{@repo.full_name}/import") end end # .start_source_import end - describe "post deprecation" do + describe 'post deprecation' do before(:each) do - @client.start_source_import(@repo.full_name, "https://bitbucket.org/spraints/goboom", { :vcs => "hg", accept: preview_header }) + @client.start_source_import(@repo.full_name, 'https://bitbucket.org/spraints/goboom', { vcs: 'hg', accept: preview_header }) end - describe ".start_source_import", :vcr do - it "starts a source import" do + describe '.start_source_import', :vcr do + it 'starts a source import' do assert_requested :put, github_url("/repos/#{@repo.full_name}/import") end end # .start_source_import - describe ".source_import_progress", :vcr do - it "returns the progress of the source import" do + describe '.source_import_progress', :vcr do + it 'returns the progress of the source import' do result = @client.source_import_progress(@repo.full_name, accept: preview_header) expect(result).to be_kind_of Sawyer::Resource assert_requested :get, github_url("/repos/#{@repo.full_name}/import") end end # .source_import_progress - describe ".update_source_import", :vcr do - it "restarts the source import" do + describe '.update_source_import', :vcr do + it 'restarts the source import' do result = @client.update_source_import(@repo.full_name, accept: preview_header) expect(result).to be_kind_of Sawyer::Resource assert_requested :patch, github_url("/repos/#{@repo.full_name}/import") end end # .update_source_import - describe ".source_import_commit_authors", :vcr do - it "lists the source imports commit authors" do + describe '.source_import_commit_authors', :vcr do + it 'lists the source imports commit authors' do commit_authors = @client.source_import_commit_authors(@repo.full_name, accept: preview_header) expect(commit_authors).to be_kind_of Array assert_requested :get, github_url("/repos/#{@repo.full_name}/import/authors") end end # .source_import_commit_authors - describe ".map_source_import_commit_author", :vcr do - it "updates the commit authors identity" do + describe '.map_source_import_commit_author', :vcr do + it 'updates the commit authors identity' do # We have to wait for the importer to load the authors before continuing - while(@client.source_import_commit_authors(@repo.full_name, accept: preview_header).empty?) + while @client.source_import_commit_authors(@repo.full_name, accept: preview_header).empty? sleep 1 end commit_author_url = @client.source_import_commit_authors(@repo.full_name, accept: preview_header).first.url commit_author = @client.map_source_import_commit_author(commit_author_url, { - :email => "hubot@github.com", - :name => "Hubot the Robot", - accept: preview_header - }) + email: 'hubot@github.com', + name: 'Hubot the Robot', + accept: preview_header + }) - expect(commit_author.email).to eql("hubot@github.com") - expect(commit_author.name).to eql("Hubot the Robot") + expect(commit_author.email).to eql('hubot@github.com') + expect(commit_author.name).to eql('Hubot the Robot') assert_requested :patch, commit_author_url end end # .map_source_import_commit_author - describe ".cancel_source_import", :vcr do - it "cancels the source import" do + describe '.cancel_source_import', :vcr do + it 'cancels the source import' do result = @client.cancel_source_import(@repo.full_name, accept: preview_header) expect(result).to be true assert_requested :delete, github_url("/repos/#{@repo.full_name}/import") end end # .cancel_source_import - describe ".source_import_large_files", :vcr do - it "lists the source imports large files" do + describe '.source_import_large_files', :vcr do + it 'lists the source imports large files' do large_files = @client.source_import_large_files(@repo.full_name, accept: preview_header) expect(large_files).to be_kind_of Array assert_requested :get, github_url("/repos/#{@repo.full_name}/import/large_files") end end # .source_import_large_files - describe ".set_source_import_lfs_preference", :vcr do - it "sets use_lfs to opt_in for the import" do - result = @client.set_source_import_lfs_preference(@repo.full_name, "opt_in", accept: preview_header) + describe '.set_source_import_lfs_preference', :vcr do + it 'sets use_lfs to opt_in for the import' do + result = @client.set_source_import_lfs_preference(@repo.full_name, 'opt_in', accept: preview_header) expect(result).to be_kind_of Sawyer::Resource assert_requested :patch, github_url("repos/#{@repo.full_name}/import/lfs") end diff --git a/spec/octokit/client/stats_spec.rb b/spec/octokit/client/stats_spec.rb index fd51e107a..925f46495 100644 --- a/spec/octokit/client/stats_spec.rb +++ b/spec/octokit/client/stats_spec.rb @@ -1,21 +1,22 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Stats do - before do Octokit.reset! @client = oauth_client end - context "with empty repo" do + context 'with empty repo' do before do VCR.turn_off! - stub_request(:any, /api\.github\.com\/repos\/octokit/). - to_return( - { :status => 202 }, # Cold request - { :status => 202 }, # Cold request - { :status => 204, :body => [].to_json }, # Warm request - { :status => 204, :body => [].to_json } # Warm request + stub_request(:any, %r{api\.github\.com/repos/octokit}) + .to_return( + { status: 202 }, # Cold request + { status: 202 }, # Cold request + { status: 204, body: [].to_json }, # Warm request + { status: 204, body: [].to_json } # Warm request ) end @@ -23,39 +24,39 @@ VCR.turn_on! end - describe ".contributors_stats" do - it "returns nil when statistics are not ready" do - stats = @client.contributors_stats("octokit/octokit.rb") + describe '.contributors_stats' do + it 'returns nil when statistics are not ready' do + stats = @client.contributors_stats('octokit/octokit.rb') expect(stats).to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/contributors") + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/contributors') end - it "returns [] when GitHub returns 204" do - stats = @client.contributors_stats("octokit/octokit.rb", :retry_timeout => 3) + it 'returns [] when GitHub returns 204' do + stats = @client.contributors_stats('octokit/octokit.rb', retry_timeout: 3) expect(stats).to eq([]) end it "doesn't retry when GitHub returns 204" do - stats = @client.contributors_stats("octokit/octokit.rb", :retry_timeout => 4) - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/contributors"), :times => 3 + stats = @client.contributors_stats('octokit/octokit.rb', retry_timeout: 4) + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/contributors'), times: 3 end - it "returns nil on timeout" do - stats = @client.contributors_stats("octokit/octokit.rb", :retry_timeout => 1, :retry_wait => 1) + it 'returns nil on timeout' do + stats = @client.contributors_stats('octokit/octokit.rb', retry_timeout: 1, retry_wait: 1) expect(stats).to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/contributors"), :times => 2 + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/contributors'), times: 2 end end end - context "with cold graph cache" do + context 'with cold graph cache' do before do VCR.turn_off! - stub_request(:any, /api\.github\.com\/repos\/octokit/). - to_return( - { :status => 202 }, # Cold request - { :status => 202 }, # Cold request - { :status => 200, :body => [].to_json }, # Warm request + stub_request(:any, %r{api\.github\.com/repos/octokit}) + .to_return( + { status: 202 }, # Cold request + { status: 202 }, # Cold request + { status: 200, body: [].to_json } # Warm request ) end @@ -63,128 +64,127 @@ VCR.turn_on! end - describe ".contributors_stats" do - it "returns contributors and their contribution stats" do - stats = @client.contributors_stats("octokit/octokit.rb") + describe '.contributors_stats' do + it 'returns contributors and their contribution stats' do + stats = @client.contributors_stats('octokit/octokit.rb') expect(stats).to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/contributors") + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/contributors') end - it "retries" do - stats = @client.contributors_stats("octokit/octokit.rb", :retry_timeout => 3) + it 'retries' do + stats = @client.contributors_stats('octokit/octokit.rb', retry_timeout: 3) expect(stats).to_not be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/contributors"), :times => 3 + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/contributors'), times: 3 end - it "returns nil on timeout" do - stats = @client.contributors_stats("octokit/octokit.rb", :retry_timeout => 1, :retry_wait => 1) + it 'returns nil on timeout' do + stats = @client.contributors_stats('octokit/octokit.rb', retry_timeout: 1, retry_wait: 1) expect(stats).to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/contributors"), :times => 2 + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/contributors'), times: 2 end end # .contributors_stats - describe ".commit_activity_stats" do - it "returns the commit activity stats" do - stats = @client.commit_activity_stats("octokit/octokit.rb") + describe '.commit_activity_stats' do + it 'returns the commit activity stats' do + stats = @client.commit_activity_stats('octokit/octokit.rb') expect(stats).to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/commit_activity") + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/commit_activity') end - it "retries" do - stats = @client.commit_activity_stats("octokit/octokit.rb", :retry_timeout => 3) + it 'retries' do + stats = @client.commit_activity_stats('octokit/octokit.rb', retry_timeout: 3) expect(stats).to_not be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/commit_activity"), :times => 3 + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/commit_activity'), times: 3 end end # .commit_activity_stats - describe ".code_frequency_stats" do - it "returns the code frequency stats" do + describe '.code_frequency_stats' do + it 'returns the code frequency stats' do stats = @client.code_frequency_stats('octokit/octokit.rb') expect(stats).to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/code_frequency") + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/code_frequency') end - it "retries" do - stats = @client.code_frequency_stats("octokit/octokit.rb", :retry_timeout => 3) + it 'retries' do + stats = @client.code_frequency_stats('octokit/octokit.rb', retry_timeout: 3) expect(stats).to_not be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/code_frequency"), :times => 3 + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/code_frequency'), times: 3 end end # .code_frequency_stats - describe ".participation_stats" do - it "returns the owner and contributor participation stats" do + describe '.participation_stats' do + it 'returns the owner and contributor participation stats' do stats = @client.participation_stats('octokit/octokit.rb') expect(stats).to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/participation") + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/participation') end - it "retries" do - stats = @client.participation_stats("octokit/octokit.rb", :retry_timeout => 3) + it 'retries' do + stats = @client.participation_stats('octokit/octokit.rb', retry_timeout: 3) expect(stats).to_not be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/participation"), :times => 3 + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/participation'), times: 3 end end # .participation_stats - describe ".punch_card_stats" do - it "returns commit count by hour punch card stats" do + describe '.punch_card_stats' do + it 'returns commit count by hour punch card stats' do stats = @client.punch_card_stats('octokit/octokit.rb') expect(stats).to be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/punch_card") + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/punch_card') end - it "retries" do - stats = @client.punch_card_stats("octokit/octokit.rb", :retry_timeout => 3) + it 'retries' do + stats = @client.punch_card_stats('octokit/octokit.rb', retry_timeout: 3) expect(stats).to_not be_nil - assert_requested :get, github_url("/repos/octokit/octokit.rb/stats/punch_card"), :times => 3 + assert_requested :get, github_url('/repos/octokit/octokit.rb/stats/punch_card'), times: 3 end end # .punch_card_stats end - describe ".contributors_stats", :vcr do - it "returns contributors and their contribution stats" do - stats = @client.contributors_stats("pengwynn/pingwynn") + describe '.contributors_stats', :vcr do + it 'returns contributors and their contribution stats' do + stats = @client.contributors_stats('pengwynn/pingwynn') expect(stats).to be_kind_of Array expect(stats.first.author.login).not_to be_nil - assert_requested :get, github_url("/repos/pengwynn/pingwynn/stats/contributors") + assert_requested :get, github_url('/repos/pengwynn/pingwynn/stats/contributors') end end # .contributors_stats - describe ".commit_activity_stats", :vcr do - it "returns the commit activity stats" do - stats = @client.commit_activity_stats("pengwynn/pingwynn") + describe '.commit_activity_stats', :vcr do + it 'returns the commit activity stats' do + stats = @client.commit_activity_stats('pengwynn/pingwynn') expect(stats).to be_kind_of Array expect(stats.first.week).to be_kind_of Integer - assert_requested :get, github_url("/repos/pengwynn/pingwynn/stats/commit_activity") + assert_requested :get, github_url('/repos/pengwynn/pingwynn/stats/commit_activity') end end # .commit_activity_stats - describe ".code_frequency_stats", :vcr do - it "returns the code frequency stats" do - stats = @client.code_frequency_stats("pengwynn/pingwynn") + describe '.code_frequency_stats', :vcr do + it 'returns the code frequency stats' do + stats = @client.code_frequency_stats('pengwynn/pingwynn') expect(stats).to be_kind_of Array - assert_requested :get, github_url("/repos/pengwynn/pingwynn/stats/code_frequency") + assert_requested :get, github_url('/repos/pengwynn/pingwynn/stats/code_frequency') end end # .code_frequency_stats - describe ".participation_stats", :vcr do - it "returns the owner and contributor participation stats" do - stats = @client.participation_stats("pengwynn/pingwynn") + describe '.participation_stats', :vcr do + it 'returns the owner and contributor participation stats' do + stats = @client.participation_stats('pengwynn/pingwynn') expect(stats.fields).to include(:owner) - assert_requested :get, github_url("/repos/pengwynn/pingwynn/stats/participation") + assert_requested :get, github_url('/repos/pengwynn/pingwynn/stats/participation') end end # .participation_stats - describe ".punch_card_stats", :vcr do - it "returns commit count by hour punch card stats" do - stats = @client.punch_card_stats("pengwynn/pingwynn") + describe '.punch_card_stats', :vcr do + it 'returns commit count by hour punch card stats' do + stats = @client.punch_card_stats('pengwynn/pingwynn') expect(stats).to be_kind_of Array - assert_requested :get, github_url("/repos/pengwynn/pingwynn/stats/punch_card") + assert_requested :get, github_url('/repos/pengwynn/pingwynn/stats/punch_card') end end # .punch_card_stats - end diff --git a/spec/octokit/client/statuses_spec.rb b/spec/octokit/client/statuses_spec.rb index f3ba25dc9..86fa904b2 100644 --- a/spec/octokit/client/statuses_spec.rb +++ b/spec/octokit/client/statuses_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Statuses do @@ -5,32 +7,32 @@ @client = oauth_client end - describe ".statuses", :vcr do - it "lists commit statuses" do + describe '.statuses', :vcr do + it 'lists commit statuses' do statuses = Octokit.statuses('octokit/octokit.rb', '7d069dedd4cb56bf57760688657abd0e6b5a28b8') expect(statuses).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/statuses/7d069dedd4cb56bf57760688657abd0e6b5a28b8") + assert_requested :get, github_url('/repos/octokit/octokit.rb/statuses/7d069dedd4cb56bf57760688657abd0e6b5a28b8') end end # .statuses - describe ".combined_status", :vcr do - it "gets a combined status" do + describe '.combined_status', :vcr do + it 'gets a combined status' do status = Octokit.combined_status('octokit/octokit.rb', 'fd1a4e2c734f9ff8dd2c9ca940fccd4a678d5908') expect(status.sha).to eq('fd1a4e2c734f9ff8dd2c9ca940fccd4a678d5908') expect(status.statuses).to be_kind_of Array - assert_requested :get, github_url("/repos/octokit/octokit.rb/commits/fd1a4e2c734f9ff8dd2c9ca940fccd4a678d5908/status") + assert_requested :get, github_url('/repos/octokit/octokit.rb/commits/fd1a4e2c734f9ff8dd2c9ca940fccd4a678d5908/status') end end - context "with repository" do + context 'with repository' do before do @commit_sha = @client.commits(@test_repo).first.sha end - describe ".create_status", :vcr do - it "creates status" do + describe '.create_status', :vcr do + it 'creates status' do info = { - :target_url => 'http://wynnnetherland.com' + target_url: 'http://wynnnetherland.com' } @client.create_status(@test_repo, @commit_sha, 'success', info) assert_requested :post, github_url("/repos/#{@test_repo}/statuses/#{@commit_sha}") diff --git a/spec/octokit/client/traffic_spec.rb b/spec/octokit/client/traffic_spec.rb index 90931a2c2..686b25ba8 100644 --- a/spec/octokit/client/traffic_spec.rb +++ b/spec/octokit/client/traffic_spec.rb @@ -1,32 +1,34 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Traffic do - describe ".top_referrers", :vcr do - it "returns the referrers stats for a repository" do + describe '.top_referrers', :vcr do + it 'returns the referrers stats for a repository' do referrers = oauth_client.top_referrers(@test_repo, accept: preview_header) expect(referrers).to be_kind_of Array assert_requested :get, github_url("/repos/#{@test_repo}/traffic/popular/referrers") end end # .top_referrers - describe ".top_paths", :vcr do - it "returns the top path statistics for a repository" do + describe '.top_paths', :vcr do + it 'returns the top path statistics for a repository' do top_paths = oauth_client.top_paths(@test_repo, accept: preview_header) expect(top_paths).to be_kind_of Array assert_requested :get, github_url("/repos/#{@test_repo}/traffic/popular/paths") end end # .top_paths - describe ".views", :vcr do - it "returns the views breakdown for a repository" do + describe '.views', :vcr do + it 'returns the views breakdown for a repository' do views = oauth_client.views(@test_repo, accept: preview_header) expect(views.count).to be_kind_of Integer assert_requested :get, github_url("/repos/#{@test_repo}/traffic/views") end end # .views - describe ".clones", :vcr do - it "returns the clone stats for a repository" do + describe '.clones', :vcr do + it 'returns the clone stats for a repository' do clones = oauth_client.clones(@test_repo, accept: preview_header) expect(clones.count).to be_kind_of Integer assert_requested :get, github_url("/repos/#{@test_repo}/traffic/clones") diff --git a/spec/octokit/client/users_spec.rb b/spec/octokit/client/users_spec.rb index 0cf3a3692..84e820b4b 100644 --- a/spec/octokit/client/users_spec.rb +++ b/spec/octokit/client/users_spec.rb @@ -1,38 +1,39 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Client::Users do - before(:each) do Octokit.reset! @client = oauth_client end - describe ".all_users", :vcr do - it "returns all GitHub users" do + describe '.all_users', :vcr do + it 'returns all GitHub users' do users = Octokit.all_users expect(users).to be_kind_of Array end end # .all_users - describe ".user", :vcr do - it "returns a user" do - user = Octokit.client.user("sferik") + describe '.user', :vcr do + it 'returns a user' do + user = Octokit.client.user('sferik') expect(user.login).to eq('sferik') end - it "handle [bot] users", :vcr do - user = Octokit.client.user("shipit[bot]") + it 'handle [bot] users', :vcr do + user = Octokit.client.user('shipit[bot]') expect(user.login).to eq('shipit[bot]') end - it "returns the authenticated user" do + it 'returns the authenticated user' do user = @client.user expect(user.login).to eq(test_github_login) end end # .user - describe ".validate_credentials", :vcr do - it "validates username and password" do + describe '.validate_credentials', :vcr do + it 'validates username and password' do result = Octokit.validate_credentials( login: test_github_login, password: test_github_password @@ -42,19 +43,19 @@ end end # .validate_credentials - describe ".update_user", :vcr do - it "updates a user profile" do - user = @client.update_user(:location => "San Francisco, CA", :hireable => false) + describe '.update_user', :vcr do + it 'updates a user profile' do + user = @client.update_user(location: 'San Francisco, CA', hireable: false) expect(user.login).to eq(test_github_login) - assert_requested :patch, github_url("/user") + assert_requested :patch, github_url('/user') end end # .update_user - describe ".followers", :vcr do - it "returns followers for a user" do - users = Octokit.followers("sferik") + describe '.followers', :vcr do + it 'returns followers for a user' do + users = Octokit.followers('sferik') expect(users).to be_kind_of Array - assert_requested :get, github_url("/users/sferik/followers") + assert_requested :get, github_url('/users/sferik/followers') end it "returns the authenticated user's followers" do users = @client.followers @@ -63,11 +64,11 @@ end end # .followers - describe ".following", :vcr do - it "returns following for a user" do - users = Octokit.following("sferik") + describe '.following', :vcr do + it 'returns following for a user' do + users = Octokit.following('sferik') expect(users).to be_kind_of Array - assert_requested :get, github_url("/users/sferik/following") + assert_requested :get, github_url('/users/sferik/following') end it "returns the authenticated user's following" do users = @client.following @@ -76,79 +77,79 @@ end end # .following - describe ".follows?", :vcr do - it "checks if the authenticated user follows another" do - @client.follows?("sferik") - assert_requested :get, github_url("/user/following/sferik") + describe '.follows?', :vcr do + it 'checks if the authenticated user follows another' do + @client.follows?('sferik') + assert_requested :get, github_url('/user/following/sferik') end - it "checks if given user is following target user" do - @client.follows?("sferik", "pengwynn") - assert_requested :get, github_url("/users/sferik/following/pengwynn") + it 'checks if given user is following target user' do + @client.follows?('sferik', 'pengwynn') + assert_requested :get, github_url('/users/sferik/following/pengwynn') end end # .follows? - describe ".follow", :vcr do - it "follows a user" do - @client.follow("pengwynn") - assert_requested :put, github_url("/user/following/pengwynn") + describe '.follow', :vcr do + it 'follows a user' do + @client.follow('pengwynn') + assert_requested :put, github_url('/user/following/pengwynn') end end # .follow - describe ".unfollow", :vcr do - it "unfollows a user" do - @client.unfollow("pengwynn") - assert_requested :delete, github_url("/user/following/pengwynn") + describe '.unfollow', :vcr do + it 'unfollows a user' do + @client.unfollow('pengwynn') + assert_requested :delete, github_url('/user/following/pengwynn') end end # .unfollow - describe ".starred?", :vcr do - it "checks if the authenticated user has starred a repository" do - @client.starred?("sferik/rails_admin") - assert_requested :get, github_url("/user/starred/sferik/rails_admin") + describe '.starred?', :vcr do + it 'checks if the authenticated user has starred a repository' do + @client.starred?('sferik/rails_admin') + assert_requested :get, github_url('/user/starred/sferik/rails_admin') end end # .starred? - describe ".starred", :vcr do - context "not authenticated" do + describe '.starred', :vcr do + context 'not authenticated' do it "gets a user's starred repositories" do - Octokit.starred("sferik") - assert_requested :get, github_url("/users/sferik/starred") + Octokit.starred('sferik') + assert_requested :get, github_url('/users/sferik/starred') end end - context "authenticated" do + context 'authenticated' do it "gets the authenticated user's starred repositories" do @client.starred - assert_requested :get, github_url("/user/starred") + assert_requested :get, github_url('/user/starred') end it "gets a user's starred repositories" do - @client.starred("sferik") - assert_requested :get, github_url("/users/sferik/starred") + @client.starred('sferik') + assert_requested :get, github_url('/users/sferik/starred') end end end # .starred - describe ".keys", :vcr do - it "returns public keys for the authenticated user" do + describe '.keys', :vcr do + it 'returns public keys for the authenticated user' do public_keys = @client.keys expect(public_keys).to be_kind_of Array - assert_requested :get, github_url("/user/keys") + assert_requested :get, github_url('/user/keys') end end # .keys - describe ".user_keys", :vcr do - it "returns public keys for another user" do - public_keys = Octokit.user_keys("pengwynn") + describe '.user_keys', :vcr do + it 'returns public keys for another user' do + public_keys = Octokit.user_keys('pengwynn') expect(public_keys).to be_kind_of Array - assert_requested :get, github_url("/users/pengwynn/keys") + assert_requested :get, github_url('/users/pengwynn/keys') end end # .user_keys - context "methods requiring an existing @public_key", :vcr do - + context 'methods requiring an existing @public_key', :vcr do before(:each) do - title, key = "wynning", "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDN/h7Hf5TA6G4p19deF8YS9COfuBd133GPs49tO6AU/DKIt7tlitbnUnttT0VbNZM4fplyinPu5vJl60eusn/Ngq2vDfSHP5SfgHfA9H8cnHGPYG7w6F0CujFB3tjBhHa3L6Je50E3NC4+BGGhZMpUoTClEI5yEzx3qosRfpfJu/2MUp/V2aARCAiHUlUoj5eiB15zC25uDsY7SYxkh1JO0ecKSMISc/OCdg0kwi7it4t7S/qm8Wh9pVGuA5FmVk8w0hvL+hHWB9GT02WPqiesMaS9Sj3t0yuRwgwzLDaudQPKKTKYXi+SjwXxTJ/lei2bZTMC4QxYbqfqYQt66pQB wynn.netherland+api-padawan@gmail.com" + title = 'wynning' + key = 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDN/h7Hf5TA6G4p19deF8YS9COfuBd133GPs49tO6AU/DKIt7tlitbnUnttT0VbNZM4fplyinPu5vJl60eusn/Ngq2vDfSHP5SfgHfA9H8cnHGPYG7w6F0CujFB3tjBhHa3L6Je50E3NC4+BGGhZMpUoTClEI5yEzx3qosRfpfJu/2MUp/V2aARCAiHUlUoj5eiB15zC25uDsY7SYxkh1JO0ecKSMISc/OCdg0kwi7it4t7S/qm8Wh9pVGuA5FmVk8w0hvL+hHWB9GT02WPqiesMaS9Sj3t0yuRwgwzLDaudQPKKTKYXi+SjwXxTJ/lei2bZTMC4QxYbqfqYQt66pQB wynn.netherland+api-padawan@gmail.com' @public_key = @client.add_key(title, key) end @@ -156,86 +157,85 @@ @client.remove_key(@public_key.id) end - describe ".add_key" do - it "adds a public key" do - assert_requested :post, github_url("/user/keys") + describe '.add_key' do + it 'adds a public key' do + assert_requested :post, github_url('/user/keys') end end # .add_key - describe ".key" do - it "returns a public key" do + describe '.key' do + it 'returns a public key' do @client.key @public_key.id assert_requested :get, github_url("/user/keys/#{@public_key.id}") end end - describe ".update_key" do - it "updates a public key" do - expect { @client.update_key(@public_key.id, :title => 'Updated key') }. - to raise_error(Octokit::MethodNotAllowed) + describe '.update_key' do + it 'updates a public key' do + expect { @client.update_key(@public_key.id, title: 'Updated key') } + .to raise_error(Octokit::MethodNotAllowed) assert_requested :patch, github_url("/user/keys/#{@public_key.id}") end end # .update_key - describe ".remove_key" do - it "removes a public key" do + describe '.remove_key' do + it 'removes a public key' do @client.remove_key(@public_key.id) assert_requested :delete, github_url("/user/keys/#{@public_key.id}") end end # .remove_key - end # @public_key methods - describe ".emails", :vcr do - it "returns email addresses" do + describe '.emails', :vcr do + it 'returns email addresses' do emails = @client.emails expect(emails).to be_kind_of Array - assert_requested :get, github_url("/user/emails") + assert_requested :get, github_url('/user/emails') end end # .emails - describe ".add_email", :vcr do - it "adds an email address" do - @client.add_email("wynn.netherland+apitest@gmail.com") - assert_requested :post, github_url("/user/emails") + describe '.add_email', :vcr do + it 'adds an email address' do + @client.add_email('wynn.netherland+apitest@gmail.com') + assert_requested :post, github_url('/user/emails') end end # .add_email - describe ".remove_email", :vcr do - it "removes an email address" do - @client.remove_email("wynn.netherland+apitest@gmail.com") - assert_requested :delete, github_url("/user/emails") + describe '.remove_email', :vcr do + it 'removes an email address' do + @client.remove_email('wynn.netherland+apitest@gmail.com') + assert_requested :delete, github_url('/user/emails') end end # .remove_email - describe ".subscriptions", :vcr do - context "not authenticated" do - it "returns the repositories a user watches for notifications" do - Octokit.subscriptions("pengwynn") - assert_requested :get, github_url("/users/pengwynn/subscriptions") + describe '.subscriptions', :vcr do + context 'not authenticated' do + it 'returns the repositories a user watches for notifications' do + Octokit.subscriptions('pengwynn') + assert_requested :get, github_url('/users/pengwynn/subscriptions') end end - context "authenticated" do - it "returns the repositories the authenticated user watches for notifications" do + context 'authenticated' do + it 'returns the repositories the authenticated user watches for notifications' do @client.subscriptions - assert_requested :get, github_url("/user/subscriptions") + assert_requested :get, github_url('/user/subscriptions') end - it "returns the repositories a user watches for notifications" do - @client.subscriptions("pengwynn") - assert_requested :get, github_url("/users/pengwynn/subscriptions") + it 'returns the repositories a user watches for notifications' do + @client.subscriptions('pengwynn') + assert_requested :get, github_url('/users/pengwynn/subscriptions') end end end # .subscriptions - describe ".exchange_code_for_token" do - context "with application authenticated client" do - it "returns the access_token" do + describe '.exchange_code_for_token' do + context 'with application authenticated client' do + it 'returns the access_token' do request_body = { - code: "code", - client_id: "123", - client_secret: "345" + code: 'code', + client_id: '123', + client_secret: '345' } client = Octokit::Client.new( @@ -243,15 +243,15 @@ client_secret: request_body[:client_secret] ) - request = stub_post("https://github.com/login/oauth/access_token"). - with( - basic_auth: [request_body[:client_id], request_body[:client_secret]], - body: request_body.to_json - ).to_return(json_response("web_flow_token.json")) + request = stub_post('https://github.com/login/oauth/access_token') + .with( + basic_auth: [request_body[:client_id], request_body[:client_secret]], + body: request_body.to_json + ).to_return(json_response('web_flow_token.json')) - response = client.exchange_code_for_token("code") + response = client.exchange_code_for_token('code') - expect(response.access_token).to eq "this_be_ye_token/use_it_wisely" + expect(response.access_token).to eq 'this_be_ye_token/use_it_wisely' assert_requested request end end # with application authenticated client @@ -259,9 +259,9 @@ context 'with credentials passed as parameters by unauthed client' do it 'returns the access_token' do client = Octokit::Client.new - post = stub_request(:post, "https://github.com/login/oauth/access_token"). - with(:body => {:code=>"code", :client_id=>"id", :client_secret=>"secret"}.to_json). - to_return(json_response("web_flow_token.json")) + post = stub_request(:post, 'https://github.com/login/oauth/access_token') + .with(body: { code: 'code', client_id: 'id', client_secret: 'secret' }.to_json) + .to_return(json_response('web_flow_token.json')) response = client.exchange_code_for_token('code', 'id', 'secret') expect(response.access_token).to eq 'this_be_ye_token/use_it_wisely' assert_requested post @@ -269,47 +269,47 @@ end # with credentials passed as parameters end # .exchange_code_for_token - describe ".migrations", :vcr do - it "starts a migration for a user" do - result = @client.start_user_migration(["snakeoil-ceo/the-insecure"], accept: preview_header, lock_repositories: true) + describe '.migrations', :vcr do + it 'starts a migration for a user' do + result = @client.start_user_migration(['snakeoil-ceo/the-insecure'], accept: preview_header, lock_repositories: true) expect(result).to be_kind_of Sawyer::Resource - assert_requested :post, github_url("/user/migrations") + assert_requested :post, github_url('/user/migrations') end - it "lists migrations for a user" do + it 'lists migrations for a user' do result = @client.user_migrations(accept: preview_header) expect(result).to be_kind_of Array - assert_requested :get, github_url("/user/migrations") + assert_requested :get, github_url('/user/migrations') end - it "gets the status of a user migration" do - result = @client.user_migration_status(400195, accept: preview_header) + it 'gets the status of a user migration' do + result = @client.user_migration_status(400_195, accept: preview_header) expect(result).to be_kind_of Sawyer::Resource - assert_requested :get, github_url("/user/migrations/400195") + assert_requested :get, github_url('/user/migrations/400195') end - it "lists repositories for a user migration" do - result = @client.user_migration_repositories(400195, accept: preview_header) + it 'lists repositories for a user migration' do + result = @client.user_migration_repositories(400_195, accept: preview_header) expect(result).to be_kind_of Array - assert_requested :get, github_url("/user/migrations/400195/repositories") + assert_requested :get, github_url('/user/migrations/400195/repositories') end - it "gets a user migration archive url" do - result = @client.user_migration_archive_url(400195, accept: preview_header) + it 'gets a user migration archive url' do + result = @client.user_migration_archive_url(400_195, accept: preview_header) expect(result).to be_kind_of String - assert_requested :get, github_url("/user/migrations/400195/archive") + assert_requested :get, github_url('/user/migrations/400195/archive') end - it "deletes a user migration archive" do - result = @client.delete_user_migration_archive(400195, accept: preview_header) + it 'deletes a user migration archive' do + result = @client.delete_user_migration_archive(400_195, accept: preview_header) expect(result).to be_kind_of String - assert_requested :delete, github_url("/user/migrations/400195/archive") + assert_requested :delete, github_url('/user/migrations/400195/archive') end - it "unlocks a migrated user repository" do - @client.unlock_user_repository(400195, 'the-insecure', accept: preview_header) + it 'unlocks a migrated user repository' do + @client.unlock_user_repository(400_195, 'the-insecure', accept: preview_header) expect(@client.last_response.status).to eq(204) - assert_requested :delete, github_url("/user/migrations/400195/repos/the-insecure/lock") + assert_requested :delete, github_url('/user/migrations/400195/repos/the-insecure/lock') end end # .migrations diff --git a/spec/octokit/client_spec.rb b/spec/octokit/client_spec.rb index aaf51e7b9..0ed2d0e1c 100644 --- a/spec/octokit/client_spec.rb +++ b/spec/octokit/client_spec.rb @@ -1,8 +1,9 @@ +# frozen_string_literal: true + require 'helper' require 'json' describe Octokit::Client do - before do Octokit.reset! end @@ -11,12 +12,11 @@ Octokit.reset! end - describe "module configuration" do - + describe 'module configuration' do before do Octokit.reset! Octokit.configure do |config| - Octokit::Configurable.keys.each do |key| + Octokit::Configurable.each_key do |key| config.send("#{key}=", "Some #{key}") end end @@ -26,40 +26,39 @@ Octokit.reset! end - it "inherits the module configuration" do + it 'inherits the module configuration' do client = Octokit::Client.new - Octokit::Configurable.keys.each do |key| + Octokit::Configurable.each_key do |key| expect(client.instance_variable_get(:"@#{key}")).to eq("Some #{key}") end end - describe "with class level configuration" do - + describe 'with class level configuration' do before do @opts = { - :connection_options => {:ssl => {:verify => false}}, - :per_page => 40, - :login => "defunkt", - :password => "il0veruby" + connection_options: { ssl: { verify: false } }, + per_page: 40, + login: 'defunkt', + password: 'il0veruby' } end - it "uses defaults when parameters are nil" do - new_opts = @opts.merge(:api_endpoint => nil) + it 'uses defaults when parameters are nil' do + new_opts = @opts.merge(api_endpoint: nil) client = Octokit::Client.new(new_opts) expect(client.api_endpoint).to eq(Octokit.api_endpoint) end - it "overrides module configuration" do + it 'overrides module configuration' do 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.login).to eq('defunkt') + 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 - it "can set configuration after initialization" do + it 'can set configuration after initialization' do client = Octokit::Client.new client.configure do |config| @opts.each do |key, value| @@ -67,93 +66,94 @@ end 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.login).to eq('defunkt') + 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 - it "masks passwords on inspect" do + it 'masks passwords on inspect' do client = Octokit::Client.new(@opts) inspected = client.inspect - expect(inspected).not_to include("il0veruby") + expect(inspected).not_to include('il0veruby') end - it "masks tokens on inspect" do - client = Octokit::Client.new(:access_token => '87614b09dd141c22800f96f11737ade5226d7ba8') + it 'masks tokens on inspect' do + client = Octokit::Client.new(access_token: '87614b09dd141c22800f96f11737ade5226d7ba8') inspected = client.inspect - expect(inspected).not_to include("87614b09dd141c22800f96f11737ade5226d7ba8") + expect(inspected).not_to include('87614b09dd141c22800f96f11737ade5226d7ba8') end - it "masks bearer token on inspect" do + it 'masks bearer token on inspect' do client = Octokit::Client.new(bearer_token: 'secret JWT') inspected = client.inspect - expect(inspected).not_to include("secret JWT") + expect(inspected).not_to include('secret JWT') end - it "masks client secrets on inspect" do - client = Octokit::Client.new(:client_secret => '87614b09dd141c22800f96f11737ade5226d7ba8') + it 'masks client secrets on inspect' do + client = Octokit::Client.new(client_secret: '87614b09dd141c22800f96f11737ade5226d7ba8') inspected = client.inspect - expect(inspected).not_to include("87614b09dd141c22800f96f11737ade5226d7ba8") + expect(inspected).not_to include('87614b09dd141c22800f96f11737ade5226d7ba8') end - describe "with .netrc" do + describe 'with .netrc' do before do - File.chmod(0600, File.join(fixture_path, '.netrc')) + File.chmod(0o600, File.join(fixture_path, '.netrc')) end - it "can read .netrc files" do + it 'can read .netrc files' do 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") + 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') end - it "can read non-standard API endpoint creds from .netrc" do + 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") + 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') end end end end - describe "content type" do - it "sets a default Content-Type header" do - gist_request = stub_post("/gists"). - with({ - :headers => {"Content-Type" => "application/json"}}) + describe 'content type' do + it 'sets a default Content-Type header' do + gist_request = stub_post('/gists') + .with({ + headers: { 'Content-Type' => 'application/json' } + }) - Octokit.client.post "/gists", {} + Octokit.client.post '/gists', {} assert_requested gist_request end - it "fixes % bug", :vcr do + it 'fixes % bug', :vcr do new_gist = { - :description => "%A gist from Octokit", - :public => true, - :files => { - "zen.text" => { :content => "Keep it logically awesome." } + description: '%A gist from Octokit', + public: true, + files: { + 'zen.text' => { content: 'Keep it logically awesome.' } } } client = Octokit::Client.new - client.post "/gists", new_gist + client.post '/gists', new_gist expect(client.last_response.status).to eq(201) end end - describe "authentication" do + describe 'authentication' do before do Octokit.reset! @client = Octokit.client end - describe "with module level config" do + describe 'with module level config' do before do Octokit.reset! end - it "sets basic auth creds with .configure" do + it 'sets basic auth creds with .configure' do Octokit.configure do |config| config.login = 'pengwynn' config.password = 'il0veruby' @@ -161,13 +161,13 @@ expect(Octokit.client).to be_basic_authenticated end - it "sets basic auth creds with module methods" do + it 'sets basic auth creds with module methods' do Octokit.login = 'pengwynn' Octokit.password = 'il0veruby' expect(Octokit.client).to be_basic_authenticated end - it "sets oauth token with .configure" do + it 'sets oauth token with .configure' do Octokit.configure do |config| config.access_token = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' end @@ -175,18 +175,18 @@ expect(Octokit.client).to be_token_authenticated end - it "sets oauth token with module methods" do + it 'sets oauth token with module methods' do Octokit.access_token = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' expect(Octokit.client).not_to be_basic_authenticated expect(Octokit.client).to be_token_authenticated end - it "sets bearer token with module method" do + it 'sets bearer token with module method' do Octokit.bearer_token = 'secret JWT' expect(Octokit.client).to be_bearer_authenticated end - it "sets bearer token with .configure" do + it 'sets bearer token with .configure' do Octokit.configure do |config| config.bearer_token = 'secret JWT' end @@ -195,7 +195,7 @@ expect(Octokit.client).to be_bearer_authenticated end - it "sets oauth application creds with .configure" do + it 'sets oauth application creds with .configure' do Octokit.configure do |config| config.client_id = '97b4937b385eb63d1f46' config.client_secret = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' @@ -205,7 +205,7 @@ expect(Octokit.client).to be_application_authenticated end - it "sets oauth token with module methods" do + it 'sets oauth token with module methods' do Octokit.client_id = '97b4937b385eb63d1f46' Octokit.client_secret = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' expect(Octokit.client).not_to be_basic_authenticated @@ -214,30 +214,30 @@ end end - describe "with class level config" do - it "sets basic auth creds with .configure" do + describe 'with class level config' do + it 'sets basic auth creds with .configure' do @client.configure do |config| config.login = 'pengwynn' config.password = 'il0veruby' end expect(@client).to be_basic_authenticated end - it "sets basic auth creds with instance methods" do + it 'sets basic auth creds with instance methods' do @client.login = 'pengwynn' @client.password = 'il0veruby' expect(@client).to be_basic_authenticated end - it "sets oauth token with .configure" do + it 'sets oauth token with .configure' do @client.access_token = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' expect(@client).not_to be_basic_authenticated expect(@client).to be_token_authenticated end - it "sets oauth token with instance methods" do + it 'sets oauth token with instance methods' do @client.access_token = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' expect(@client).not_to be_basic_authenticated expect(@client).to be_token_authenticated end - it "sets oauth application creds with .configure" do + it 'sets oauth application creds with .configure' do @client.configure do |config| config.client_id = '97b4937b385eb63d1f46' config.client_secret = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' @@ -246,7 +246,7 @@ expect(@client).not_to be_token_authenticated expect(@client).to be_application_authenticated end - it "sets oauth token with module methods" do + it 'sets oauth token with module methods' do @client.client_id = '97b4937b385eb63d1f46' @client.client_secret = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' expect(@client).not_to be_basic_authenticated @@ -255,29 +255,29 @@ end end - describe "when basic authenticated" do - it "makes authenticated calls" do + describe 'when basic authenticated' do + it 'makes authenticated calls' do Octokit.configure do |config| config.login = 'pengwynn' config.password = 'il0veruby' end - root_request = stub_request(:get, github_url("/")).with(basic_auth: ["pengwynn", "il0veruby"]) - Octokit.client.get("/") + root_request = stub_request(:get, github_url('/')).with(basic_auth: %w[pengwynn il0veruby]) + Octokit.client.get('/') assert_requested root_request end end - describe "when token authenticated", :vcr do - it "makes authenticated calls" do + describe 'when token authenticated', :vcr do + it 'makes authenticated calls' do client = oauth_client - root_request = stub_get("/"). - with(:headers => {:authorization => "token #{test_github_token}"}) - client.get("/") + root_request = stub_get('/') + .with(headers: { authorization: "token #{test_github_token}" }) + client.get('/') assert_requested root_request end - it "fetches and memoizes login" do + it 'fetches and memoizes login' do client = oauth_client expect(client.login).to eq(test_github_login) @@ -285,60 +285,60 @@ end end - describe "when bearer authenticated", :vcr do - it "makes authenticated calls" do + describe 'when bearer authenticated', :vcr do + it 'makes authenticated calls' do jwt = 'secret JWT' client = Octokit::Client.new(bearer_token: jwt) - root_request = stub_get("/"). - with(:headers => {:authorization => "Bearer #{jwt}"}) - client.get("/") + root_request = stub_get('/') + .with(headers: { authorization: "Bearer #{jwt}" }) + client.get('/') assert_requested root_request end end - describe "when application authenticated" do - it "makes authenticated calls" do + describe 'when application authenticated' do + it 'makes authenticated calls' do client = Octokit::Client.new( client_id: '97b4937b385eb63d1f46', client_secret: 'd255197b4937b385eb63d1f4677e3ffee61fbaea' ) - root_request = stub_request(:get, github_url("/")) - .with(basic_auth: ["97b4937b385eb63d1f46", "d255197b4937b385eb63d1f4677e3ffee61fbaea"]) + root_request = stub_request(:get, github_url('/')) + .with(basic_auth: %w[97b4937b385eb63d1f46 d255197b4937b385eb63d1f4677e3ffee61fbaea]) - client.get("/") + client.get('/') assert_requested root_request end end end - describe ".agent" do + describe '.agent' do before do Octokit.reset! end - it "acts like a Sawyer agent" do + it 'acts like a Sawyer agent' do expect(Octokit.client.agent).to respond_to :start end - it "caches the agent" do + it 'caches the agent' do client = Octokit::Client.new agent = client.agent expect(agent.object_id).to eq(client.agent.object_id) end end # .agent - describe ".root" do - it "fetches the API root" do + describe '.root' do + it 'fetches the API root' do Octokit.reset! VCR.use_cassette 'root' do root = Octokit.client.root - expect(root.rels[:issues].href).to eq("https://api.github.com/issues") + expect(root.rels[:issues].href).to eq('https://api.github.com/issues') end end - it "passes app creds in the query string" do - root_request = stub_request(:get, github_url("/")) - .with(basic_auth: ['97b4937b385eb63d1f46', 'd255197b4937b385eb63d1f4677e3ffee61fbaea']) + it 'passes app creds in the query string' do + root_request = stub_request(:get, github_url('/')) + .with(basic_auth: %w[97b4937b385eb63d1f46 d255197b4937b385eb63d1f4677e3ffee61fbaea]) client = Octokit.client client.client_id = '97b4937b385eb63d1f46' client.client_secret = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' @@ -347,282 +347,282 @@ end end - describe ".last_response", :vcr do - it "caches the last agent response" do + describe '.last_response', :vcr do + it 'caches the last agent response' do Octokit.reset! client = Octokit.client expect(client.last_response).to be_nil - client.get "/" + client.get '/' expect(client.last_response.status).to eq(200) end end # .last_response - describe ".get", :vcr do + describe '.get', :vcr do before(:each) do Octokit.reset! end - it "handles query params" do - Octokit.get "/", :foo => "bar" - assert_requested :get, "https://api.github.com?foo=bar" + it 'handles query params' do + Octokit.get '/', foo: 'bar' + assert_requested :get, 'https://api.github.com?foo=bar' end - it "handles headers" do - request = stub_get("/zen"). - with(:query => {:foo => "bar"}, :headers => {:accept => "text/plain"}) - Octokit.get "/zen", :foo => "bar", :accept => "text/plain" + it 'handles headers' do + request = stub_get('/zen') + .with(query: { foo: 'bar' }, headers: { accept: 'text/plain' }) + Octokit.get '/zen', foo: 'bar', accept: 'text/plain' assert_requested request end end # .get - describe ".head", :vcr do - it "handles query params" do + describe '.head', :vcr do + it 'handles query params' do Octokit.reset! - Octokit.head "/", :foo => "bar" - assert_requested :head, "https://api.github.com?foo=bar" + Octokit.head '/', foo: 'bar' + assert_requested :head, 'https://api.github.com?foo=bar' end - it "handles headers" do + it 'handles headers' do Octokit.reset! - request = stub_head("/zen"). - with(:query => {:foo => "bar"}, :headers => {:accept => "text/plain"}) - Octokit.head "/zen", :foo => "bar", :accept => "text/plain" + request = stub_head('/zen') + .with(query: { foo: 'bar' }, headers: { accept: 'text/plain' }) + Octokit.head '/zen', foo: 'bar', accept: 'text/plain' assert_requested request end end # .head - describe "when making requests" do + describe 'when making requests' do before do Octokit.reset! @client = Octokit.client end - it "Accepts application/vnd.github.v3+json by default" do + it 'Accepts application/vnd.github.v3+json by default' do VCR.use_cassette 'root' do - root_request = stub_get("/"). - with(:headers => {:accept => "application/vnd.github.v3+json"}) - @client.get "/" + root_request = stub_get('/') + .with(headers: { accept: 'application/vnd.github.v3+json' }) + @client.get '/' assert_requested root_request expect(@client.last_response.status).to eq(200) end end it "allows Accept'ing another media type" do - root_request = stub_get("/"). - with(:headers => {:accept => "application/vnd.github.beta.diff+json"}) - @client.get "/", :accept => "application/vnd.github.beta.diff+json" + root_request = stub_get('/') + .with(headers: { accept: 'application/vnd.github.beta.diff+json' }) + @client.get '/', accept: 'application/vnd.github.beta.diff+json' assert_requested root_request expect(@client.last_response.status).to eq(200) end - it "sets a default user agent" do - root_request = stub_get("/"). - with(:headers => {:user_agent => Octokit::Default.user_agent}) - @client.get "/" + it 'sets a default user agent' do + root_request = stub_get('/') + .with(headers: { user_agent: Octokit::Default.user_agent }) + @client.get '/' assert_requested root_request expect(@client.last_response.status).to eq(200) end - it "sets a custom user agent" do - user_agent = "Mozilla/5.0 I am Spartacus!" - root_request = stub_get("/"). - with(:headers => {:user_agent => user_agent}) - client = Octokit::Client.new(:user_agent => user_agent) - client.get "/" + it 'sets a custom user agent' do + user_agent = 'Mozilla/5.0 I am Spartacus!' + root_request = stub_get('/') + .with(headers: { user_agent: user_agent }) + client = Octokit::Client.new(user_agent: user_agent) + client.get '/' assert_requested root_request expect(client.last_response.status).to eq(200) end - it "sets a proxy server" do + it 'sets a proxy server' do Octokit.configure do |config| config.proxy = 'http://proxy.example.com:80' end 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 + it 'no sets an ssl verify' do client = Octokit::Client.new expect(client.connection_options[:ssl]).to be nil end - it "sets an ssl verify => true" do + it 'sets an ssl verify => true' do client = Octokit::Client.new( - :connection_options => {:ssl => {:verify => true}} + connection_options: { ssl: { verify: true } } ) 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 + it 'sets an ssl verify => false' do client = Octokit::Client.new( - :connection_options => {:ssl => {:verify => false}} + connection_options: { ssl: { verify: false } } ) 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 + 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") 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 + it 'ensures ssl verify mode is set to default when no override provided' do 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 - headers = {"X-GitHub-Foo" => "bar"} - root_request = stub_post("/"). - with(:headers => headers). - to_return(:status => 201) + it 'passes along request headers for POST' do + headers = { 'X-GitHub-Foo' => 'bar' } + root_request = stub_post('/') + .with(headers: headers) + .to_return(status: 201) client = Octokit::Client.new - client.post "/", :headers => headers + client.post '/', headers: headers assert_requested root_request expect(client.last_response.status).to eq(201) end - it "adds app creds in query params to anonymous requests" do + it 'adds app creds in query params to anonymous requests' do client = Octokit::Client.new client.client_id = key = '97b4937b385eb63d1f46' client.client_secret = secret = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' - root_request = stub_request(:get, github_url("/")).with(basic_auth: [key, secret]) + root_request = stub_request(:get, github_url('/')).with(basic_auth: [key, secret]) - client.get("/") + client.get('/') assert_requested root_request end - it "omits app creds in query params for basic requests" do - client = Octokit::Client.new :login => "login", :password => "passw0rd" + it 'omits app creds in query params for basic requests' do + client = Octokit::Client.new login: 'login', password: 'passw0rd' client.client_id = key = '97b4937b385eb63d1f46' client.client_secret = secret = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' - root_request = stub_request(:get, github_url("/?foo=bar")).with(basic_auth: ["login", "passw0rd"]) + root_request = stub_request(:get, github_url('/?foo=bar')).with(basic_auth: %w[login passw0rd]) - client.get("/", :foo => "bar") + client.get('/', foo: 'bar') assert_requested root_request end - it "omits app creds in query params for token requests" do - client = Octokit::Client.new(:access_token => '87614b09dd141c22800f96f11737ade5226d7ba8') + it 'omits app creds in query params for token requests' do + client = Octokit::Client.new(access_token: '87614b09dd141c22800f96f11737ade5226d7ba8') client.client_id = key = '97b4937b385eb63d1f46' client.client_secret = secret = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' - root_request = stub_get(github_url("/?foo=bar")).with \ - :headers => {"Authorization" => "token 87614b09dd141c22800f96f11737ade5226d7ba8"} + root_request = stub_get(github_url('/?foo=bar')).with \ + headers: { 'Authorization' => 'token 87614b09dd141c22800f96f11737ade5226d7ba8' } - client.get("/", :foo => "bar") + client.get('/', foo: 'bar') assert_requested root_request end end - describe "redirect handling" do - it "follows redirect for 301 response" do + describe 'redirect handling' do + it 'follows redirect for 301 response' do client = oauth_client - original_request = stub_get("/foo"). - to_return(:status => 301, :headers => { "Location" => "/bar" }) - redirect_request = stub_get("/bar").to_return(:status => 200) + original_request = stub_get('/foo') + .to_return(status: 301, headers: { 'Location' => '/bar' }) + redirect_request = stub_get('/bar').to_return(status: 200) - client.get("/foo") + client.get('/foo') assert_requested original_request assert_requested redirect_request end - it "follows redirect for 302 response" do + it 'follows redirect for 302 response' do client = oauth_client - original_request = stub_get("/foo"). - to_return(:status => 302, :headers => { "Location" => "/bar" }) - redirect_request = stub_get("/bar").to_return(:status => 200) + original_request = stub_get('/foo') + .to_return(status: 302, headers: { 'Location' => '/bar' }) + redirect_request = stub_get('/bar').to_return(status: 200) - client.get("/foo") + client.get('/foo') assert_requested original_request assert_requested redirect_request end - it "follows redirect for 307 response" do + it 'follows redirect for 307 response' do client = oauth_client - original_request = stub_post(github_url("/foo")). - with(:body => { :some_property => "some_value" }.to_json). - to_return(:status => 307, :headers => { "Location" => "/bar" }) - redirect_request = stub_post(github_url("/bar")). - with(:body => { :some_property => "some_value" }.to_json). - to_return(:status => 201, :headers => { "Location" => "/bar" }) + original_request = stub_post(github_url('/foo')) + .with(body: { some_property: 'some_value' }.to_json) + .to_return(status: 307, headers: { 'Location' => '/bar' }) + redirect_request = stub_post(github_url('/bar')) + .with(body: { some_property: 'some_value' }.to_json) + .to_return(status: 201, headers: { 'Location' => '/bar' }) - client.post("/foo", { :some_property => "some_value" }) + client.post('/foo', { some_property: 'some_value' }) assert_requested original_request assert_requested redirect_request end - it "follows redirects for supported HTTP methods" do + it 'follows redirects for supported HTTP methods' do client = oauth_client - http_methods = [:head, :get, :post, :put, :patch, :delete] + http_methods = %i[head get post put patch delete] http_methods.each do |http| - original_request = stub_request(http, github_url("/foo")). - to_return(:status => 301, :headers => { "Location" => "/bar" }) - redirect_request = stub_request(http, github_url("/bar")). - to_return(:status => 200) + original_request = stub_request(http, github_url('/foo')) + .to_return(status: 301, headers: { 'Location' => '/bar' }) + redirect_request = stub_request(http, github_url('/bar')) + .to_return(status: 200) - client.send(http, "/foo") + client.send(http, '/foo') assert_requested original_request assert_requested redirect_request end end - it "does not change HTTP method when following a redirect" do + it 'does not change HTTP method when following a redirect' do client = oauth_client - original_request = stub_delete("/foo"). - to_return(:status => 301, :headers => { "Location" => "/bar" }) - redirect_request = stub_delete("/bar").to_return(:status => 200) + original_request = stub_delete('/foo') + .to_return(status: 301, headers: { 'Location' => '/bar' }) + redirect_request = stub_delete('/bar').to_return(status: 200) - client.delete("/foo") + client.delete('/foo') assert_requested original_request assert_requested redirect_request - other_methods = [:head, :get, :post, :put, :patch] + other_methods = %i[head get post put patch] other_methods.each do |http| - assert_not_requested http, github_url("/bar") + assert_not_requested http, github_url('/bar') end end - it "keeps authentication info when redirecting to the same host" do + it 'keeps authentication info when redirecting to the same host' do client = oauth_client - original_request = stub_get("/foo"). - with(:headers => {"Authorization" => "token #{test_github_token}"}). - to_return(:status => 301, :headers => { "Location" => "/bar" }) - redirect_request = stub_get("/bar"). - with(:headers => {"Authorization" => "token #{test_github_token}"}). - to_return(:status => 200) + original_request = stub_get('/foo') + .with(headers: { 'Authorization' => "token #{test_github_token}" }) + .to_return(status: 301, headers: { 'Location' => '/bar' }) + redirect_request = stub_get('/bar') + .with(headers: { 'Authorization' => "token #{test_github_token}" }) + .to_return(status: 200) - client.get("/foo") + client.get('/foo') assert_requested original_request assert_requested redirect_request end - it "drops authentication info when redirecting to a different host" do + it 'drops authentication info when redirecting to a different host' do client = oauth_client - original_request = stub_request(:get, github_url("/foo")). - with(:headers => {"Authorization" => "token #{test_github_token}"}). - to_return(:status => 301, :headers => { "Location" => "https://example.com/bar" }) - redirect_request = stub_request(:get, "https://example.com/bar"). - to_return(:status => 200) + original_request = stub_request(:get, github_url('/foo')) + .with(headers: { 'Authorization' => "token #{test_github_token}" }) + .to_return(status: 301, headers: { 'Location' => 'https://example.com/bar' }) + redirect_request = stub_request(:get, 'https://example.com/bar') + .to_return(status: 200) - client.get("/foo") + client.get('/foo') assert_requested original_request - assert_requested(:get, "https://example.com/bar") { |req| - req.headers["Authorization"] == "dummy" - } + assert_requested(:get, 'https://example.com/bar') do |req| + req.headers['Authorization'] == 'dummy' + end end - it "follows at most 3 consecutive redirects" do + it 'follows at most 3 consecutive redirects' do client = oauth_client - original_request = stub_get("/a"). - to_return(:status => 302, :headers => { "Location" => "/b" }) - first_redirect = stub_get("/b"). - to_return(:status => 302, :headers => { "Location" => "/c" }) - second_redirect = stub_get("/c"). - to_return(:status => 302, :headers => { "Location" => "/d" }) - third_redirect = stub_get("/d"). - to_return(:status => 302, :headers => { "Location" => "/e" }) - fourth_redirect = stub_get("/e").to_return(:status => 200) - - expect { client.get("/a") }.to raise_error(Octokit::Middleware::RedirectLimitReached) + original_request = stub_get('/a') + .to_return(status: 302, headers: { 'Location' => '/b' }) + first_redirect = stub_get('/b') + .to_return(status: 302, headers: { 'Location' => '/c' }) + second_redirect = stub_get('/c') + .to_return(status: 302, headers: { 'Location' => '/d' }) + third_redirect = stub_get('/d') + .to_return(status: 302, headers: { 'Location' => '/e' }) + fourth_redirect = stub_get('/e').to_return(status: 200) + + expect { client.get('/a') }.to raise_error(Octokit::Middleware::RedirectLimitReached) assert_requested original_request assert_requested first_redirect assert_requested second_redirect @@ -631,7 +631,7 @@ end end - describe "auto pagination", :vcr do + describe 'auto pagination', :vcr do before do Octokit.reset! Octokit.configure do |config| @@ -644,7 +644,7 @@ Octokit.reset! end - it "fetches all the pages" do + it 'fetches all the pages' do url = '/search/users?q=user:joeyw user:pengwynn user:sferik' Octokit.client.paginate url assert_requested :get, github_url("#{url}&per_page=1") @@ -653,26 +653,26 @@ end end - it "accepts a block for custom result concatination" do - results = Octokit.client.paginate("/search/users?per_page=1&q=user:pengwynn+user:defunkt", - :per_page => 1) { |data, last_response| + it 'accepts a block for custom result concatination' do + results = Octokit.client.paginate('/search/users?per_page=1&q=user:pengwynn+user:defunkt', + per_page: 1) do |data, last_response| data.items.concat last_response.data.items - } + end expect(results.total_count).to eq(2) expect(results.items.length).to eq(2) end - it "sets headers for all pages" do - url = "/search/repositories?q=octokit+language:Python" - accept_text_match = "application/vnd.github.v3.text-match+json" - github_media_type_header = "github.v3; param=text-match; format=json" - Octokit.client.paginate url, :accept => accept_text_match - expect(Octokit.client.last_response.headers["x-github-media-type"]).to eq(github_media_type_header) + it 'sets headers for all pages' do + url = '/search/repositories?q=octokit+language:Python' + accept_text_match = 'application/vnd.github.v3.text-match+json' + github_media_type_header = 'github.v3; param=text-match; format=json' + Octokit.client.paginate url, accept: accept_text_match + expect(Octokit.client.last_response.headers['x-github-media-type']).to eq(github_media_type_header) end end - describe ".as_app" do + describe '.as_app' do before do @client_id = '97b4937b385eb63d1f46' @client_secret = 'd255197b4937b385eb63d1f4677e3ffee61fbaea' @@ -685,36 +685,30 @@ config.per_page = 50 end - @root_request = stub_request(:get, github_url("/")).with(basic_auth: [@client_id, @client_secret]) + @root_request = stub_request(:get, github_url('/')).with(basic_auth: [@client_id, @client_secret]) end - it "uses preconfigured client and secret" do + it 'uses preconfigured client and secret' do client = Octokit.client - login = client.as_app do |c| - c.login - end + login = client.as_app(&:login) expect(login).to eq(@client_id) end - it "requires a client and secret" do + it 'requires a client and secret' do Octokit.reset! client = Octokit.client - expect { - client.as_app do |c| - c.get - end - }.to raise_error Octokit::ApplicationCredentialsRequired + expect do + client.as_app(&:get) + end.to raise_error Octokit::ApplicationCredentialsRequired end - it "duplicates the client" do + it 'duplicates the client' do client = Octokit.client - page_size = client.as_app do |c| - c.per_page - end + page_size = client.as_app(&:per_page) expect(page_size).to eq(client.per_page) end - it "uses client and secret as Basic auth" do + it 'uses client and secret as Basic auth' do client = Octokit.client app_client = client.as_app do |c| c @@ -722,20 +716,20 @@ expect(app_client).to be_basic_authenticated end - it "makes authenticated requests" do - stub_get github_url("/user") + it 'makes authenticated requests' do + stub_get github_url('/user') client = Octokit.client - client.get "/user" + client.get '/user' client.as_app do |c| - c.get "/" + c.get '/' end assert_requested @root_request end end - context "error handling" do + context 'error handling' do before do Octokit.reset! VCR.turn_off! @@ -745,270 +739,270 @@ VCR.turn_on! end - it "raises on 404" do - stub_get('/booya').to_return(:status => 404) + it 'raises on 404' do + stub_get('/booya').to_return(status: 404) expect { Octokit.get('/booya') }.to raise_error Octokit::NotFound end - it "raises on 500" do - stub_get('/boom').to_return(:status => 500) + it 'raises on 500' do + stub_get('/boom').to_return(status: 500) expect { Octokit.get('/boom') }.to raise_error Octokit::InternalServerError end - it "includes a message" do - stub_get('/boom'). - to_return \ - :status => 422, - :headers => { - :content_type => "application/json", - }, - :body => {:message => "No repository found for hubtopic"}.to_json + it 'includes a message' do + stub_get('/boom') + .to_return \ + status: 422, + headers: { + content_type: 'application/json' + }, + body: { message: 'No repository found for hubtopic' }.to_json begin Octokit.get('/boom') rescue Octokit::UnprocessableEntity => e - expect(e.message).to include("GET https://api.github.com/boom: 422 - No repository found") + expect(e.message).to include('GET https://api.github.com/boom: 422 - No repository found') end end - it "includes an error" do - stub_get('/boom'). - to_return \ - :status => 422, - :headers => { - :content_type => "application/json", - }, - :body => {:error => "No repository found for hubtopic"}.to_json + it 'includes an error' do + stub_get('/boom') + .to_return \ + status: 422, + headers: { + content_type: 'application/json' + }, + body: { error: 'No repository found for hubtopic' }.to_json begin Octokit.get('/boom') rescue Octokit::UnprocessableEntity => e - expect(e.message).to include("GET https://api.github.com/boom: 422 - Error: No repository found") + expect(e.message).to include('GET https://api.github.com/boom: 422 - Error: No repository found') end end - it "includes an error summary" do - stub_get('/boom'). - to_return \ - :status => 422, - :headers => { - :content_type => "application/json", - }, - :body => { - :message => "Validation Failed", - :errors => [ - "Position is invalid", - :resource => "Issue", - :field => "title", - :code => "missing_field" - ] - }.to_json + it 'includes an error summary' do + stub_get('/boom') + .to_return \ + status: 422, + headers: { + content_type: 'application/json' + }, + body: { + message: 'Validation Failed', + errors: [ + 'Position is invalid', + resource: 'Issue', + field: 'title', + code: 'missing_field' + ] + }.to_json begin Octokit.get('/boom') rescue Octokit::UnprocessableEntity => e - expect(e.message).to include("GET https://api.github.com/boom: 422 - Validation Failed") - expect(e.message).to include(" Position is invalid") - expect(e.message).to include(" resource: Issue") - expect(e.message).to include(" field: title") - expect(e.message).to include(" code: missing_field") + expect(e.message).to include('GET https://api.github.com/boom: 422 - Validation Failed') + expect(e.message).to include(' Position is invalid') + expect(e.message).to include(' resource: Issue') + expect(e.message).to include(' field: title') + expect(e.message).to include(' code: missing_field') end end - it "exposes errors array" do - stub_get('/boom'). - to_return \ - :status => 422, - :headers => { - :content_type => "application/json", - }, - :body => { - :message => "Validation Failed", - :errors => [ - :resource => "Issue", - :field => "title", - :code => "missing_field" - ] - }.to_json + it 'exposes errors array' do + stub_get('/boom') + .to_return \ + status: 422, + headers: { + content_type: 'application/json' + }, + body: { + message: 'Validation Failed', + errors: [ + resource: 'Issue', + field: 'title', + code: 'missing_field' + ] + }.to_json begin Octokit.get('/boom') rescue Octokit::UnprocessableEntity => e - expect(e.errors.first[:resource]).to eq("Issue") - expect(e.errors.first[:field]).to eq("title") - expect(e.errors.first[:code]).to eq("missing_field") + expect(e.errors.first[:resource]).to eq('Issue') + expect(e.errors.first[:field]).to eq('title') + expect(e.errors.first[:code]).to eq('missing_field') end end - it "knows the difference between different kinds of forbidden" do - stub_get('/some/admin/stuffs').to_return(:status => 403) + it 'knows the difference between different kinds of forbidden' do + stub_get('/some/admin/stuffs').to_return(status: 403) expect { Octokit.get('/some/admin/stuffs') }.to raise_error Octokit::Forbidden stub_get('/users/mojomobo').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "API rate limit exceeded"}.to_json + body: { message: 'API rate limit exceeded' }.to_json expect { Octokit.get('/users/mojomobo') }.to raise_error Octokit::TooManyRequests stub_get('/users/mojomobo').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "You have exceeded a secondary rate limit."}.to_json + body: { message: 'You have exceeded a secondary rate limit.' }.to_json expect { Octokit.get('/users/mojomobo') }.to raise_error Octokit::TooManyRequests stub_get('/user').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "Maximum number of login attempts exceeded"}.to_json + body: { message: 'Maximum number of login attempts exceeded' }.to_json expect { Octokit.get('/user') }.to raise_error Octokit::TooManyLoginAttempts stub_get('/user').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "This API returns blobs up to 1 MB in size"}.to_json + body: { message: 'This API returns blobs up to 1 MB in size' }.to_json expect { Octokit.get('/user') }.to raise_error Octokit::TooLargeContent stub_get('/user').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "You have triggered an abuse detection mechanism and have been temporarily blocked from content creation. Please retry your request again later."}.to_json + body: { message: 'You have triggered an abuse detection mechanism and have been temporarily blocked from content creation. Please retry your request again later.' }.to_json expect { Octokit.get('/user') }.to raise_error Octokit::AbuseDetected stub_get('/blocked/repository').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "Repository access blocked"}.to_json - expect { Octokit.get("/blocked/repository") }.to raise_error Octokit::RepositoryUnavailable + body: { message: 'Repository access blocked' }.to_json + expect { Octokit.get('/blocked/repository') }.to raise_error Octokit::RepositoryUnavailable stub_post('/user/repos').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "At least one email address must be verified to do that"}.to_json - expect { Octokit.post("/user/repos") }.to raise_error Octokit::UnverifiedEmail + body: { message: 'At least one email address must be verified to do that' }.to_json + expect { Octokit.post('/user/repos') }.to raise_error Octokit::UnverifiedEmail stub_post('/user/repos').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "Sorry. Your account was suspended. Please contact github-enterprise@example.com"}.to_json - expect { Octokit.post("/user/repos") }.to raise_error Octokit::AccountSuspended + body: { message: 'Sorry. Your account was suspended. Please contact github-enterprise@example.com' }.to_json + expect { Octokit.post('/user/repos') }.to raise_error Octokit::AccountSuspended stub_post('/user/repos').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "The repository has been disabled due to a billing issue with the owner account."}.to_json - expect { Octokit.post("/user/repos") }.to raise_error Octokit::BillingIssue + body: { message: 'The repository has been disabled due to a billing issue with the owner account.' }.to_json + expect { Octokit.post('/user/repos') }.to raise_error Octokit::BillingIssue stub_get('/teams/8675309').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "Resource protected by organization SAML enforcement. You must grant your personal token access to this organization."}.to_json - expect { Octokit.get("/teams/8675309") }.to raise_error Octokit::SAMLProtected + body: { message: 'Resource protected by organization SAML enforcement. You must grant your personal token access to this organization.' }.to_json + expect { Octokit.get('/teams/8675309') }.to raise_error Octokit::SAMLProtected stub_get('/torrentz').to_return \ - :status => 451, - :headers => { - :content_type => "application/json", + status: 451, + headers: { + content_type: 'application/json' } expect { Octokit.get('/torrentz') }.to raise_error Octokit::UnavailableForLegalReasons stub_post('/installation/repositories').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "This installation owned by octocat suspended your access at 2020-08-28T16:32:59Z."}.to_json - expect { Octokit.post("/installation/repositories") }.to raise_error Octokit::InstallationSuspended + body: { message: 'This installation owned by octocat suspended your access at 2020-08-28T16:32:59Z.' }.to_json + expect { Octokit.post('/installation/repositories') }.to raise_error Octokit::InstallationSuspended stub_post('/app/installations/12345/access_tokens').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", + status: 403, + headers: { + content_type: 'application/json' }, - :body => {:message => "This installation has been suspended // See: https://docs.github.com/rest/reference/apps#create-an-installation-access-token-for-an-app"}.to_json - expect { Octokit.post("/app/installations/12345/access_tokens") }.to raise_error Octokit::InstallationSuspended + body: { message: 'This installation has been suspended // See: https://docs.github.com/rest/reference/apps#create-an-installation-access-token-for-an-app' }.to_json + expect { Octokit.post('/app/installations/12345/access_tokens') }.to raise_error Octokit::InstallationSuspended end - it "knows the difference between different kinds of unprocessable entity" do - stub_get('/some/admin/stuffs').to_return(:status => 422) + it 'knows the difference between different kinds of unprocessable entity' do + stub_get('/some/admin/stuffs').to_return(status: 422) expect { Octokit.get('/some/admin/stuffs') }.to raise_error Octokit::UnprocessableEntity stub_post('/repositories/123456789/pulls/1/comments').to_return \ - :status => 422, - :headers => { - :content_type => "application/json", + status: 422, + headers: { + content_type: 'application/json' }, - :body => { - :message => "Validation Failed", - :errors => [ - "end_commit_oid is not part of the pull request", - :resource => "PullRequestReviewComment", - :field => "end_commit_oid", - :code => "custom" + body: { + message: 'Validation Failed', + errors: [ + 'end_commit_oid is not part of the pull request', + resource: 'PullRequestReviewComment', + field: 'end_commit_oid', + code: 'custom' ] }.to_json expect { Octokit.post('/repositories/123456789/pulls/1/comments') }.to raise_error Octokit::CommitIsNotPartOfPullRequest stub_post('/repositories/123456789/pulls/21/comments').to_return \ - :status => 422, - :headers => { - :content_type => 'application/json', + status: 422, + headers: { + content_type: 'application/json' }, - :body => { - :message => 'Validation Failed', - :errors => [ - :message => 'path diff too large', - :resource => 'PullRequestReviewComment', - :field => 'path', - :code => 'custom' + body: { + message: 'Validation Failed', + errors: [ + message: 'path diff too large', + resource: 'PullRequestReviewComment', + field: 'path', + code: 'custom' ] }.to_json expect { Octokit.post('/repositories/123456789/pulls/21/comments') }.to raise_error Octokit::PathDiffTooLarge end - it "raises on unknown client errors" do + it 'raises on unknown client errors' do stub_get('/user').to_return \ - :status => 418, - :headers => { - :content_type => "application/json", + status: 418, + headers: { + content_type: 'application/json' }, - :body => {:message => "I'm a teapot"}.to_json + body: { message: "I'm a teapot" }.to_json expect { Octokit.get('/user') }.to raise_error Octokit::ClientError end - it "raises on unknown server errors" do + it 'raises on unknown server errors' do stub_get('/user').to_return \ - :status => 509, - :headers => { - :content_type => "application/json", + status: 509, + headers: { + content_type: 'application/json' }, - :body => {:message => "Bandwidth exceeded"}.to_json + body: { message: 'Bandwidth exceeded' }.to_json expect { Octokit.get('/user') }.to raise_error Octokit::ServerError end - it "resets last_response on errors" do - stub_get('/booya').to_return(:status => 200) + it 'resets last_response on errors' do + stub_get('/booya').to_return(status: 200) stub_get('/user').to_return \ - :status => 509, - :headers => { - :content_type => "application/json", + status: 509, + headers: { + content_type: 'application/json' }, - :body => {:message => "Bandwidth exceeded"}.to_json + body: { message: 'Bandwidth exceeded' }.to_json client = Octokit.client client.get('/booya') @@ -1017,43 +1011,43 @@ expect(client.last_response).to be_nil end - it "handles documentation URLs in error messages" do + it 'handles documentation URLs in error messages' do stub_get('/user').to_return \ - :status => 415, - :headers => { - :content_type => "application/json", + status: 415, + headers: { + content_type: 'application/json' }, - :body => { - :message => "Unsupported Media Type", - :documentation_url => "http://developer.github.com/v3" + body: { + message: 'Unsupported Media Type', + documentation_url: 'http://developer.github.com/v3' }.to_json begin Octokit.get('/user') rescue Octokit::UnsupportedMediaType => e - msg = "415 - Unsupported Media Type" + msg = '415 - Unsupported Media Type' expect(e.message).to include(msg) - expect(e.documentation_url).to eq("http://developer.github.com/v3") + expect(e.documentation_url).to eq('http://developer.github.com/v3') end end - it "handles an error response with an array body" do + it 'handles an error response with an array body' do stub_get('/user').to_return \ - :status => 500, - :headers => { - :content_type => "application/json" + status: 500, + headers: { + content_type: 'application/json' }, - :body => [].to_json + body: [].to_json expect { Octokit.get('/user') }.to raise_error Octokit::ServerError end - it "exposes the response status code" do - stub_get('/boom'). - to_return \ - :status => 422, - :headers => { - :content_type => "application/json", - }, - :body => {:error => "No repository found for hubtopic"}.to_json + it 'exposes the response status code' do + stub_get('/boom') + .to_return \ + status: 422, + headers: { + content_type: 'application/json' + }, + body: { error: 'No repository found for hubtopic' }.to_json begin Octokit.get('/boom') rescue Octokit::UnprocessableEntity => e @@ -1061,155 +1055,155 @@ end end - it "exposes the response headers" do - stub_get('/boom'). - to_return \ - :status => 422, - :headers => { - :content_type => "application/json", - }, - :body => {:error => "No repository found for hubtopic"}.to_json + it 'exposes the response headers' do + stub_get('/boom') + .to_return \ + status: 422, + headers: { + content_type: 'application/json' + }, + body: { error: 'No repository found for hubtopic' }.to_json begin Octokit.get('/boom') rescue Octokit::UnprocessableEntity => e - expect(e.response_headers).to eql({ "content-type" => "application/json" }) + expect(e.response_headers).to eql({ 'content-type' => 'application/json' }) end end - it "exposes the response body" do - stub_get('/boom'). - to_return \ - :status => 422, - :headers => { - :content_type => "application/json", - }, - :body => {:error => "No repository found for hubtopic"}.to_json + it 'exposes the response body' do + stub_get('/boom') + .to_return \ + status: 422, + headers: { + content_type: 'application/json' + }, + body: { error: 'No repository found for hubtopic' }.to_json begin Octokit.get('/boom') rescue Octokit::UnprocessableEntity => e - expect(e.response_body).to eql({:error => "No repository found for hubtopic"}.to_json) + expect(e.response_body).to eql({ error: 'No repository found for hubtopic' }.to_json) end end end - it "knows the difference between unauthorized and needs OTP" do - stub_get('/authorizations').to_return(:status => 401) - expect { Octokit.get('/authorizations') }.to raise_error Octokit::Unauthorized + it 'knows the difference between unauthorized and needs OTP' do + stub_get('/authorizations').to_return(status: 401) + expect { Octokit.get('/authorizations') }.to raise_error Octokit::Unauthorized - stub_get('/authorizations/1').to_return \ - :status => 401, - :headers => { - :content_type => "application/json", - "X-GitHub-OTP" => "required; sms" - }, - :body => {:message => "Must specify two-factor authentication OTP code."}.to_json - expect { Octokit.get('/authorizations/1') }.to raise_error Octokit::OneTimePasswordRequired + stub_get('/authorizations/1').to_return \ + status: 401, + headers: { + :content_type => 'application/json', + 'X-GitHub-OTP' => 'required; sms' + }, + body: { message: 'Must specify two-factor authentication OTP code.' }.to_json + expect { Octokit.get('/authorizations/1') }.to raise_error Octokit::OneTimePasswordRequired end - it "knows the password delivery mechanism when needs OTP" do + it 'knows the password delivery mechanism when needs OTP' do stub_get('/authorizations/1').to_return \ - :status => 401, - :headers => { - :content_type => "application/json", - "X-GitHub-OTP" => "required; app" + status: 401, + headers: { + :content_type => 'application/json', + 'X-GitHub-OTP' => 'required; app' }, - :body => {:message => "Must specify two-factor authentication OTP code."}.to_json + body: { message: 'Must specify two-factor authentication OTP code.' }.to_json begin Octokit.get('/authorizations/1') - rescue Octokit::OneTimePasswordRequired => otp_error - expect(otp_error.password_delivery).to eql 'app' + rescue Octokit::OneTimePasswordRequired => e + expect(e.password_delivery).to eql 'app' end end - it "returns empty context when non rate limit error occurs" do + it 'returns empty context when non rate limit error occurs' do stub_get('/user').to_return \ - :status => 509, - :headers => { - :content_type => "application/json", - }, - :body => {:message => "Bandwidth exceeded"}.to_json + status: 509, + headers: { + content_type: 'application/json' + }, + body: { message: 'Bandwidth exceeded' }.to_json begin Octokit.get('/user') - rescue Octokit::ServerError => server_error - expect(server_error.context).to be_nil + rescue Octokit::ServerError => e + expect(e.context).to be_nil end end - it "returns context with default data when rate limit error occurs but headers are missing" do + it 'returns context with default data when rate limit error occurs but headers are missing' do stub_get('/user').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", - }, - :body => {:message => "rate limit exceeded"}.to_json + status: 403, + headers: { + content_type: 'application/json' + }, + body: { message: 'rate limit exceeded' }.to_json begin expect_any_instance_of(Faraday::Env).to receive(:headers).at_least(:once).and_return({}) Octokit.get('/user') - rescue Octokit::TooManyRequests => rate_limit_error - expect(rate_limit_error.context).to be_an_instance_of(Octokit::RateLimit) + rescue Octokit::TooManyRequests => e + expect(e.context).to be_an_instance_of(Octokit::RateLimit) end end - it "returns context when non rate limit error occurs but rate limit headers are present" do + it 'returns context when non rate limit error occurs but rate limit headers are present' do stub_get('/user').to_return \ - :status => 403, - :headers => { - 'content_type' => 'application/json' - }, - :body => {:message => "rate limit exceeded"}.to_json + status: 403, + headers: { + 'content_type' => 'application/json' + }, + body: { message: 'rate limit exceeded' }.to_json begin - rate_limit_headers = {'X-RateLimit-Limit' => 60, 'X-RateLimit-Remaining' => 42, 'X-RateLimit-Reset' => (Time.now + 60).to_i} + rate_limit_headers = { 'X-RateLimit-Limit' => 60, 'X-RateLimit-Remaining' => 42, 'X-RateLimit-Reset' => (Time.now + 60).to_i } expect_any_instance_of(Faraday::Env).to receive(:headers).at_least(:once).and_return(rate_limit_headers) Octokit.get('/user') - rescue Octokit::TooManyRequests => rate_limit_error - expect(rate_limit_error.context).to be_an_instance_of(Octokit::RateLimit) - expect(rate_limit_error.context.limit).to eql 60 - expect(rate_limit_error.context.remaining).to eql 42 + rescue Octokit::TooManyRequests => e + expect(e.context).to be_an_instance_of(Octokit::RateLimit) + expect(e.context.limit).to eql 60 + expect(e.context.remaining).to eql 42 end end - it "returns context with default data when rate limit error occurs but headers are missing" do + it 'returns context with default data when rate limit error occurs but headers are missing' do stub_get('/user').to_return \ - :status => 403, - :headers => { - :content_type => "application/json", - }, - :body => {:message => "You have exceeded a secondary rate limit."}.to_json + status: 403, + headers: { + content_type: 'application/json' + }, + body: { message: 'You have exceeded a secondary rate limit.' }.to_json begin expect_any_instance_of(Faraday::Env).to receive(:headers).at_least(:once).and_return({}) Octokit.get('/user') - rescue Octokit::TooManyRequests => rate_limit_error - expect(rate_limit_error.context).to be_an_instance_of(Octokit::RateLimit) + rescue Octokit::TooManyRequests => e + expect(e.context).to be_an_instance_of(Octokit::RateLimit) end end - it "returns context when non rate limit error occurs but rate limit headers are present" do + it 'returns context when non rate limit error occurs but rate limit headers are present' do stub_get('/user').to_return \ - :status => 403, - :headers => { - 'content_type' => 'application/json' - }, - :body => {:message => "You have exceeded a secondary rate limit."}.to_json + status: 403, + headers: { + 'content_type' => 'application/json' + }, + body: { message: 'You have exceeded a secondary rate limit.' }.to_json begin - rate_limit_headers = {'X-RateLimit-Limit' => 60, 'X-RateLimit-Remaining' => 42, 'X-RateLimit-Reset' => (Time.now + 60).to_i} + rate_limit_headers = { 'X-RateLimit-Limit' => 60, 'X-RateLimit-Remaining' => 42, 'X-RateLimit-Reset' => (Time.now + 60).to_i } expect_any_instance_of(Faraday::Env).to receive(:headers).at_least(:once).and_return(rate_limit_headers) Octokit.get('/user') - rescue Octokit::TooManyRequests => rate_limit_error - expect(rate_limit_error.context).to be_an_instance_of(Octokit::RateLimit) - expect(rate_limit_error.context.limit).to eql 60 - expect(rate_limit_error.context.remaining).to eql 42 + rescue Octokit::TooManyRequests => e + expect(e.context).to be_an_instance_of(Octokit::RateLimit) + expect(e.context.limit).to eql 60 + expect(e.context.remaining).to eql 42 end end - describe "module call shortcut" do + describe 'module call shortcut' do before do Octokit.reset! @client = oauth_client @ent_management_console = enterprise_management_console_client end - it "has no method collisions" do + it 'has no method collisions' do client_methods = collect_methods(Octokit::Client) admin_client = collect_methods(Octokit::EnterpriseAdminClient) console_client = collect_methods(Octokit::EnterpriseManagementConsoleClient) @@ -1219,25 +1213,25 @@ expect(admin_client & console_client).to eql [] end - it "uniquely separates method missing calls" do + it 'uniquely separates method missing calls' do expect { @ent_management_console.public_events }.to raise_error NoMethodError end def collect_methods(clazz) clazz.included_modules.select { |m| m.to_s =~ Regexp.new(clazz.to_s) } \ - .collect { |m| m.public_instance_methods }.flatten + .collect(&:public_instance_methods).flatten end end - describe "rels parsing" do + describe 'rels parsing' do before do Octokit.reset! @client = oauth_client end - it "handles git@github ssh URLs", :vcr do - repo = @client.repository("octokit/octokit.rb") - expect(repo.rels[:ssh].href).to eq("git@github.com:octokit/octokit.rb.git") + it 'handles git@github ssh URLs', :vcr do + repo = @client.repository('octokit/octokit.rb') + expect(repo.rels[:ssh].href).to eq('git@github.com:octokit/octokit.rb.git') end end end diff --git a/spec/octokit/enterprise_admin_client/admin_stats_spec.rb b/spec/octokit/enterprise_admin_client/admin_stats_spec.rb index aab3e72a3..9579ce7e0 100644 --- a/spec/octokit/enterprise_admin_client/admin_stats_spec.rb +++ b/spec/octokit/enterprise_admin_client/admin_stats_spec.rb @@ -1,14 +1,15 @@ -require "helper" +# frozen_string_literal: true -describe Octokit::EnterpriseAdminClient::AdminStats do +require 'helper' +describe Octokit::EnterpriseAdminClient::AdminStats do before do Octokit.reset! @admin_client = enterprise_admin_client end - describe ".admin_stats", :vcr do - it "returns all available enterprise stats" do + describe '.admin_stats', :vcr do + it 'returns all available enterprise stats' do admin_stats = @admin_client.admin_stats expect(admin_stats.issues.total_issues).to be_kind_of Integer @@ -22,12 +23,12 @@ expect(admin_stats.pulls.mergeable_pulls).to be_kind_of Integer expect(admin_stats.repos.fork_repos).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/all") + assert_requested :get, github_enterprise_url('enterprise/stats/all') end end # .admin_stats - describe ".admin_repository_stats", :vcr do - it "returns only repository-related stats" do + describe '.admin_repository_stats', :vcr do + it 'returns only repository-related stats' do admin_repository_stats = @admin_client.admin_repository_stats expect(admin_repository_stats.fork_repos).to be_kind_of Integer @@ -37,34 +38,34 @@ expect(admin_repository_stats.org_repos).to be_kind_of Integer expect(admin_repository_stats.total_wikis).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/repos") + assert_requested :get, github_enterprise_url('enterprise/stats/repos') end end # .admin_repository_stats - describe ".admin_hooks_stats", :vcr do - it "returns only hooks-related stats" do + describe '.admin_hooks_stats', :vcr do + it 'returns only hooks-related stats' do admin_hooks_stats = @admin_client.admin_hooks_stats expect(admin_hooks_stats.total_hooks).to be_kind_of Integer expect(admin_hooks_stats.active_hooks).to be_kind_of Integer expect(admin_hooks_stats.inactive_hooks).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/hooks") + assert_requested :get, github_enterprise_url('enterprise/stats/hooks') end end # .admin_hooks_stats - describe ".admin_pages_stats", :vcr do - it "returns only pages-related stats" do + describe '.admin_pages_stats', :vcr do + it 'returns only pages-related stats' do admin_pages_stats = @admin_client.admin_pages_stats expect(admin_pages_stats.total_pages).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/pages") + assert_requested :get, github_enterprise_url('enterprise/stats/pages') end end # .admin_pages_stats - describe ".admin_organization_stats", :vcr do - it "returns only organization-related stats" do + describe '.admin_organization_stats', :vcr do + it 'returns only organization-related stats' do admin_organization_stats = @admin_client.admin_organization_stats expect(admin_organization_stats.total_team_members).to be_kind_of Integer @@ -72,24 +73,24 @@ expect(admin_organization_stats.total_orgs).to be_kind_of Integer expect(admin_organization_stats.total_teams).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/orgs") + assert_requested :get, github_enterprise_url('enterprise/stats/orgs') end end # .admin_organization_stats - describe ".admin_users_stats", :vcr do - it "returns only user-related stats" do + describe '.admin_users_stats', :vcr do + it 'returns only user-related stats' do admin_users_stats = @admin_client.admin_users_stats expect(admin_users_stats.suspended_users).to be_kind_of Integer expect(admin_users_stats.admin_users).to be_kind_of Integer expect(admin_users_stats.total_users).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/users") + assert_requested :get, github_enterprise_url('enterprise/stats/users') end end # .admin_users_stats - describe ".admin_pull_requests_stats", :vcr do - it "returns only pull request-related stats" do + describe '.admin_pull_requests_stats', :vcr do + it 'returns only pull request-related stats' do admin_pull_requests_stats = @admin_client.admin_pull_requests_stats expect(admin_pull_requests_stats.mergeable_pulls).to be_kind_of Integer @@ -97,48 +98,48 @@ expect(admin_pull_requests_stats.unmergeable_pulls).to be_kind_of Integer expect(admin_pull_requests_stats.total_pulls).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/pulls") + assert_requested :get, github_enterprise_url('enterprise/stats/pulls') end end # .admin_pull_requests_stats - describe ".admin_issues_stats", :vcr do - it "returns only issue-related stats" do + describe '.admin_issues_stats', :vcr do + it 'returns only issue-related stats' do admin_issues_stats = @admin_client.admin_issues_stats expect(admin_issues_stats.total_issues).to be_kind_of Integer expect(admin_issues_stats.closed_issues).to be_kind_of Integer expect(admin_issues_stats.open_issues).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/issues") + assert_requested :get, github_enterprise_url('enterprise/stats/issues') end end # .admin_issues_stats - describe ".admin_milestones_stats", :vcr do - it "returns only milestone-related stats" do + describe '.admin_milestones_stats', :vcr do + it 'returns only milestone-related stats' do admin_milestones_stats = @admin_client.admin_milestones_stats expect(admin_milestones_stats.closed_milestones).to be_kind_of Integer expect(admin_milestones_stats.open_milestones).to be_kind_of Integer expect(admin_milestones_stats.total_milestones).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/milestones") + assert_requested :get, github_enterprise_url('enterprise/stats/milestones') end end # .admin_milestones_stats - describe ".admin_gists_stats", :vcr do - it "returns only gist-related stats" do + describe '.admin_gists_stats', :vcr do + it 'returns only gist-related stats' do admin_gists_stats = @admin_client.admin_gists_stats expect(admin_gists_stats.private_gists).to be_kind_of Integer expect(admin_gists_stats.public_gists).to be_kind_of Integer expect(admin_gists_stats.total_gists).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/gists") + assert_requested :get, github_enterprise_url('enterprise/stats/gists') end end # .admin_gists_stats - describe ".admin_comments_stats", :vcr do - it "returns only comment-related stats" do + describe '.admin_comments_stats', :vcr do + it 'returns only comment-related stats' do admin_comments_stats = @admin_client.admin_comments_stats expect(admin_comments_stats.total_gist_comments).to be_kind_of Integer @@ -146,8 +147,7 @@ expect(admin_comments_stats.total_pull_request_comments).to be_kind_of Integer expect(admin_comments_stats.total_issue_comments).to be_kind_of Integer - assert_requested :get, github_enterprise_url("enterprise/stats/comments") + assert_requested :get, github_enterprise_url('enterprise/stats/comments') end end # .admin_comments_stats - end diff --git a/spec/octokit/enterprise_admin_client/license_spec.rb b/spec/octokit/enterprise_admin_client/license_spec.rb index 05c22ff19..f77e51683 100644 --- a/spec/octokit/enterprise_admin_client/license_spec.rb +++ b/spec/octokit/enterprise_admin_client/license_spec.rb @@ -1,14 +1,15 @@ -require "helper" +# frozen_string_literal: true -describe Octokit::EnterpriseAdminClient::License do +require 'helper' +describe Octokit::EnterpriseAdminClient::License do before do Octokit.reset! @admin_client = enterprise_admin_client end - describe ".license_info", :vcr do - it "returns information about the license" do + describe '.license_info', :vcr do + it 'returns information about the license' do license = @admin_client.license_info expect(license.seats_used).to be_kind_of Integer @@ -16,7 +17,7 @@ expect(license.days_until_expiration).to be_kind_of Integer expect(license.expire_at).to be_kind_of Time - assert_requested :get, github_enterprise_url("enterprise/settings/license") + assert_requested :get, github_enterprise_url('enterprise/settings/license') end end # .license end diff --git a/spec/octokit/enterprise_admin_client/orgs_spec.rb b/spec/octokit/enterprise_admin_client/orgs_spec.rb index c37084bd0..f054f1d5b 100644 --- a/spec/octokit/enterprise_admin_client/orgs_spec.rb +++ b/spec/octokit/enterprise_admin_client/orgs_spec.rb @@ -1,17 +1,18 @@ -require "helper" +# frozen_string_literal: true -describe Octokit::EnterpriseAdminClient::Orgs do +require 'helper' +describe Octokit::EnterpriseAdminClient::Orgs do before do Octokit.reset! @admin_client = enterprise_admin_client end - describe ".create_organization", :vcr do - it "creates a new organization" do + describe '.create_organization', :vcr do + it 'creates a new organization' do @admin_client.create_organization('SuchAGreatOrg', 'gjtorikian') expect(@admin_client.last_response.status).to eq(201) - assert_requested :post, github_enterprise_url("admin/organizations") + assert_requested :post, github_enterprise_url('admin/organizations') end end # .create_organization end diff --git a/spec/octokit/enterprise_admin_client/search_indexing_spec.rb b/spec/octokit/enterprise_admin_client/search_indexing_spec.rb index 9b45e75c8..c064fa520 100644 --- a/spec/octokit/enterprise_admin_client/search_indexing_spec.rb +++ b/spec/octokit/enterprise_admin_client/search_indexing_spec.rb @@ -1,94 +1,94 @@ -require "helper" +# frozen_string_literal: true -describe Octokit::EnterpriseAdminClient::SearchIndexing do +require 'helper' +describe Octokit::EnterpriseAdminClient::SearchIndexing do before do Octokit.reset! @admin_client = enterprise_admin_client end - shared_examples "search index queuer" do |expected_target| - context "with a valid target" do + shared_examples 'search index queuer' do |expected_target| + context 'with a valid target' do it "queues #{expected_target} to be indexed" do queue_result = @admin_client.method(subject).call target assert_requested :post, - github_enterprise_url("staff/indexing_jobs"), - :body => { :target => expected_target }.to_json + github_enterprise_url('staff/indexing_jobs'), + body: { target: expected_target }.to_json end end - context "with invalid target" do - it "raises Octokit::NotFound" do - result = @admin_client.method(subject).call("not-a/real-target") + context 'with invalid target' do + it 'raises Octokit::NotFound' do + result = @admin_client.method(subject).call('not-a/real-target') expect(result.message).to be_kind_of String - expect(result.message).to include "Unknown user" + expect(result.message).to include 'Unknown user' end end end - shared_examples "single target queue" do - it "identifies the target being indexed in the return message" do + shared_examples 'single target queue' do + it 'identifies the target being indexed in the return message' do queue_result = @admin_client.method(subject).call target expect(queue_result.message).to be_kind_of String expect(queue_result.message).to include target end end - shared_examples "multiple target queue" do - it "identifies targets that were queued for index in the return message" do + shared_examples 'multiple target queue' do + it 'identifies targets that were queued for index in the return message' do queue_result = @admin_client.method(subject).call target expect(queue_result.message).to be_kind_of Array expect(queue_result.message.first).to include target end end - describe ".index_user", :vcr do + describe '.index_user', :vcr do subject { :index_user } - let(:target) { "api-padawan" } - it_behaves_like "search index queuer", "api-padawan" - it_behaves_like "single target queue" + let(:target) { 'api-padawan' } + it_behaves_like 'search index queuer', 'api-padawan' + it_behaves_like 'single target queue' end - describe ".index_repository", :vcr do + describe '.index_repository', :vcr do subject { :index_repository } - let(:target) { "api-playground/api-sandbox" } - it_behaves_like "search index queuer", "api-playground/api-sandbox" - it_behaves_like "single target queue" + let(:target) { 'api-playground/api-sandbox' } + it_behaves_like 'search index queuer', 'api-playground/api-sandbox' + it_behaves_like 'single target queue' end - describe ".index_repository_issues", :vcr do + describe '.index_repository_issues', :vcr do subject { :index_repository_issues } - let(:target) { "api-playground/api-sandbox" } - it_behaves_like "search index queuer", "api-playground/api-sandbox/issues" - it_behaves_like "single target queue" + let(:target) { 'api-playground/api-sandbox' } + it_behaves_like 'search index queuer', 'api-playground/api-sandbox/issues' + it_behaves_like 'single target queue' end - describe ".index_repository_code", :vcr do + describe '.index_repository_code', :vcr do subject { :index_repository_code } - let(:target) { "api-playground/api-sandbox" } - it_behaves_like "search index queuer", "api-playground/api-sandbox/code" - it_behaves_like "single target queue" + let(:target) { 'api-playground/api-sandbox' } + it_behaves_like 'search index queuer', 'api-playground/api-sandbox/code' + it_behaves_like 'single target queue' end - describe ".index_users_repositories", :vcr do + describe '.index_users_repositories', :vcr do subject { :index_users_repositories } - let(:target) { "api-padawan" } - it_behaves_like "search index queuer", "api-padawan/*" - it_behaves_like "multiple target queue" + let(:target) { 'api-padawan' } + it_behaves_like 'search index queuer', 'api-padawan/*' + it_behaves_like 'multiple target queue' end - describe ".index_users_repositories_issues", :vcr do + describe '.index_users_repositories_issues', :vcr do subject { :index_users_repositories_issues } - let(:target) { "api-padawan" } - it_behaves_like "search index queuer", "api-padawan/*/issues" - it_behaves_like "multiple target queue" + let(:target) { 'api-padawan' } + it_behaves_like 'search index queuer', 'api-padawan/*/issues' + it_behaves_like 'multiple target queue' end - describe ".index_users_repositories_code", :vcr do + describe '.index_users_repositories_code', :vcr do subject { :index_users_repositories_code } - let(:target) { "api-padawan" } - it_behaves_like "search index queuer", "api-padawan/*/code" - it_behaves_like "multiple target queue" + let(:target) { 'api-padawan' } + it_behaves_like 'search index queuer', 'api-padawan/*/code' + it_behaves_like 'multiple target queue' end - end diff --git a/spec/octokit/enterprise_admin_client/users_spec.rb b/spec/octokit/enterprise_admin_client/users_spec.rb index 46ff969d2..d37bd52d4 100644 --- a/spec/octokit/enterprise_admin_client/users_spec.rb +++ b/spec/octokit/enterprise_admin_client/users_spec.rb @@ -1,94 +1,95 @@ -require "helper" +# frozen_string_literal: true -describe Octokit::EnterpriseAdminClient::Users do +require 'helper' +describe Octokit::EnterpriseAdminClient::Users do before do Octokit.reset! @admin_client = enterprise_admin_client end - describe ".create_user", :vcr do - it "creates a new user" do - @admin_client.create_user("foobar", "notreal@foo.bar") + describe '.create_user', :vcr do + it 'creates a new user' do + @admin_client.create_user('foobar', 'notreal@foo.bar') expect(@admin_client.last_response.status).to eq(201) - assert_requested :post, github_enterprise_url("admin/users") + assert_requested :post, github_enterprise_url('admin/users') end end # .create_user - describe ".promote", :vcr do - it "promotes an ordinary user to a site administrator" do - @admin_client.promote("pengwynn") - assert_requested :put, github_enterprise_url("users/pengwynn/site_admin") + describe '.promote', :vcr do + it 'promotes an ordinary user to a site administrator' do + @admin_client.promote('pengwynn') + assert_requested :put, github_enterprise_url('users/pengwynn/site_admin') end end # .promote - describe ".demote", :vcr do - it "demotes a site administrator to an ordinary user" do - @admin_client.demote("pengwynn") - assert_requested :delete, github_enterprise_url("users/pengwynn/site_admin") + describe '.demote', :vcr do + it 'demotes a site administrator to an ordinary user' do + @admin_client.demote('pengwynn') + assert_requested :delete, github_enterprise_url('users/pengwynn/site_admin') end end # .demote - describe ".rename_user", :vcr do - it "rename a user" do - @admin_client.rename_user("foobar", "foofoobar") + describe '.rename_user', :vcr do + it 'rename a user' do + @admin_client.rename_user('foobar', 'foofoobar') expect(@admin_client.last_response.status).to eq(202) - assert_requested :patch, github_enterprise_url("admin/users/foobar") + assert_requested :patch, github_enterprise_url('admin/users/foobar') end end # .rename_user - describe ".suspend", :vcr do - it "suspends a user" do - @admin_client.suspend("pengwynn") - assert_requested :put, github_enterprise_url("users/pengwynn/suspended") + describe '.suspend', :vcr do + it 'suspends a user' do + @admin_client.suspend('pengwynn') + assert_requested :put, github_enterprise_url('users/pengwynn/suspended') end end # .suspend - describe ".unsuspend", :vcr do - it "unsuspends a user" do - @admin_client.unsuspend("pengwynn") - assert_requested :delete, github_enterprise_url("users/pengwynn/suspended") + describe '.unsuspend', :vcr do + it 'unsuspends a user' do + @admin_client.unsuspend('pengwynn') + assert_requested :delete, github_enterprise_url('users/pengwynn/suspended') end end # .unsuspend - describe ".delete_user", :vcr do - it "deletes a user" do - @admin_client.delete_user("afakeperson") + describe '.delete_user', :vcr do + it 'deletes a user' do + @admin_client.delete_user('afakeperson') expect(@admin_client.last_response.status).to eq(204) - assert_requested :delete, github_enterprise_url("admin/users/afakeperson") + assert_requested :delete, github_enterprise_url('admin/users/afakeperson') end end # .delete_user - describe ".create_impersonation_token", :vcr do - it "creates an impersonation token as a user" do + describe '.create_impersonation_token', :vcr do + it 'creates an impersonation token as a user' do @admin_client.create_impersonation_token('mikemcquaid') expect(@admin_client.last_response.status).to eq(201) - assert_requested :post, github_enterprise_url("admin/users/mikemcquaid/authorizations") + assert_requested :post, github_enterprise_url('admin/users/mikemcquaid/authorizations') end end # .create_impersonation_token - describe ".delete_impersonation_token", :vcr do - it "deletes an impersonation token as a user" do + describe '.delete_impersonation_token', :vcr do + it 'deletes an impersonation token as a user' do @admin_client.delete_impersonation_token('foobar') expect(@admin_client.last_response.status).to eq(204) - assert_requested :delete, github_enterprise_url("admin/users/foobar/authorizations") + assert_requested :delete, github_enterprise_url('admin/users/foobar/authorizations') end end # .delete_impersonation_token - describe ".list_all_keys", :vcr do - it "lists all public keys" do + describe '.list_all_keys', :vcr do + it 'lists all public keys' do result = @admin_client.list_all_keys expect(@admin_client.last_response.status).to eq(200) expect(result).to be_kind_of Array - assert_requested :get, github_enterprise_url("admin/keys") + assert_requested :get, github_enterprise_url('admin/keys') end end # .list_all_keys - describe ".delete_key", :vcr do - it "deletes a public keys" do + describe '.delete_key', :vcr do + it 'deletes a public keys' do result = @admin_client.delete_key(1) expect(@admin_client.last_response.status).to eq(204) - assert_requested :delete, github_enterprise_url("admin/keys/1") + assert_requested :delete, github_enterprise_url('admin/keys/1') end end # .delete_key end diff --git a/spec/octokit/enterprise_admin_client_spec.rb b/spec/octokit/enterprise_admin_client_spec.rb index d0608da98..7e01b09e0 100644 --- a/spec/octokit/enterprise_admin_client_spec.rb +++ b/spec/octokit/enterprise_admin_client_spec.rb @@ -1,34 +1,32 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::EnterpriseAdminClient do - - describe "module configuration" do - - it "inherits Octokit::Client" do + describe 'module configuration' do + it 'inherits Octokit::Client' do admin_client = Octokit::EnterpriseAdminClient.new expect admin_client.is_a? Octokit::Client end - describe "with .netrc" do + describe 'with .netrc' do before do - File.chmod(0600, File.join(fixture_path, '.netrc')) + File.chmod(0o600, File.join(fixture_path, '.netrc')) end - it "can read .netrc files" do + it 'can read .netrc files' do Octokit.reset! - admin_client = Octokit::EnterpriseAdminClient.new(:netrc => true, :netrc_file => File.join(fixture_path, '.netrc')) - expect(admin_client.login).to eq("sferik") - expect(admin_client.instance_variable_get(:"@password")).to eq("il0veruby") + admin_client = Octokit::EnterpriseAdminClient.new(netrc: true, netrc_file: File.join(fixture_path, '.netrc')) + expect(admin_client.login).to eq('sferik') + expect(admin_client.instance_variable_get(:"@password")).to eq('il0veruby') end - it "can read non-standard API endpoint creds from .netrc" do + 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") + 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') end end - end - end diff --git a/spec/octokit/enterprise_management_console_client/management_console_spec.rb b/spec/octokit/enterprise_management_console_client/management_console_spec.rb index f66b5bf8e..add60cc35 100644 --- a/spec/octokit/enterprise_management_console_client/management_console_spec.rb +++ b/spec/octokit/enterprise_management_console_client/management_console_spec.rb @@ -1,41 +1,42 @@ -require "helper" +# frozen_string_literal: true -describe Octokit::EnterpriseManagementConsoleClient::ManagementConsole do +require 'helper' +describe Octokit::EnterpriseManagementConsoleClient::ManagementConsole do before do Octokit.reset! @enterprise_management_console_client = enterprise_management_console_client - @license = "spec/fixtures/github-enterprise.ghl" + @license = 'spec/fixtures/github-enterprise.ghl' @api_key = test_github_enterprise_management_console_password end - describe ".upload_license", :vcr do - it "uploads a license for the Enterprise installation" do + describe '.upload_license', :vcr do + it 'uploads a license for the Enterprise installation' do @enterprise_management_console_client.upload_license(@license) expect(@enterprise_management_console_client.last_response.status).to eq(202) - assert_requested :post, github_management_console_url("setup/api/start") + assert_requested :post, github_management_console_url('setup/api/start') end end # .upload_license - describe ".start_configuration", :vcr do - it "starts a configuration process for the Enterprise installation" do + describe '.start_configuration', :vcr do + it 'starts a configuration process for the Enterprise installation' do @enterprise_management_console_client.start_configuration expect(@enterprise_management_console_client.last_response.status).to eq(202) assert_requested :post, github_management_console_url("setup/api/configure?api_key=#{@api_key}") end end # .start_configuration - describe ".upgrade", :vcr do - it "upgrades the Enterprise installation" do + describe '.upgrade', :vcr do + it 'upgrades the Enterprise installation' do resp = @enterprise_management_console_client.upgrade(@license) expect(@enterprise_management_console_client.last_response.status).to eq(202) - assert_requested :post, github_management_console_url("setup/api/upgrade") + assert_requested :post, github_management_console_url('setup/api/upgrade') end end # .upgrade - describe ".config_status", :vcr do - it "returns information about the installation" do + describe '.config_status', :vcr do + it 'returns information about the installation' do config = @enterprise_management_console_client.config_status expect(config.status).to be_kind_of String @@ -47,8 +48,8 @@ end end # .config_status - describe ".settings", :vcr do - it "returns information about the Enterprise settings" do + describe '.settings', :vcr do + it 'returns information about the Enterprise settings' do settings = @enterprise_management_console_client.settings.to_hash expect(settings[:enterprise][:configuration_id]).to be_kind_of Numeric @@ -60,9 +61,9 @@ end end # .settings - describe ".edit_settings", :vcr do - it "edits the Enterprise settings" do - settings = { :enterprise => { :customer => { :name => "Jean-Luc Picard"}}} + describe '.edit_settings', :vcr do + it 'edits the Enterprise settings' do + settings = { enterprise: { customer: { name: 'Jean-Luc Picard' } } } @enterprise_management_console_client.edit_settings settings expect(@enterprise_management_console_client.last_response.status).to eq(204) @@ -70,8 +71,8 @@ end end # .edit_settings - describe ".maintenance_status", :vcr do - it "returns information about the Enterprise maintenance status" do + describe '.maintenance_status', :vcr do + it 'returns information about the Enterprise maintenance status' do maintenance_status = @enterprise_management_console_client.maintenance_status expect(maintenance_status[:status]).to be_kind_of String @@ -81,100 +82,100 @@ end end # .maintenance_status - describe ".set_maintenance_status", :vcr do - it "enables the Enterprise maintenance mode" do - maintenance = { :enabled => true, :when => "now" } + describe '.set_maintenance_status', :vcr do + it 'enables the Enterprise maintenance mode' do + maintenance = { enabled: true, when: 'now' } maintenance_status = @enterprise_management_console_client.set_maintenance_status(maintenance) - expect(maintenance_status[:status]).to match("on") + expect(maintenance_status[:status]).to match('on') assert_requested :post, github_management_console_url("setup/api/maintenance?api_key=#{@api_key}&maintenance=%7B%22enabled%22:true,%22when%22:%22now%22%7D") end end # .set_maintenance_status - describe ".authorized_keys", :vcr do - it "gets the authorized SSH keys " do + describe '.authorized_keys', :vcr do + it 'gets the authorized SSH keys ' do authorized_keys = @enterprise_management_console_client.authorized_keys expect(authorized_keys).to be_kind_of Array - expect(authorized_keys.first["key"]).to be_kind_of String - expect(authorized_keys.first["pretty-print"]).to be_kind_of String + expect(authorized_keys.first['key']).to be_kind_of String + expect(authorized_keys.first['pretty-print']).to be_kind_of String assert_requested :get, github_management_console_url("setup/api/settings/authorized-keys?api_key=#{@api_key}") end end # .authorized_keys - describe ".add_authorized_key", :vcr do - it "adds a new authorized SSH keys (via a file path)" do - key = "spec/fixtures/fake_key.pub" + describe '.add_authorized_key', :vcr do + it 'adds a new authorized SSH keys (via a file path)' do + key = 'spec/fixtures/fake_key.pub' authorized_keys = @enterprise_management_console_client.add_authorized_key(key) expect(authorized_keys).to be_kind_of Array expect(authorized_keys.length).to match(2) - expect(authorized_keys.first["key"]).to be_kind_of String - expect(authorized_keys.first["pretty-print"]).to be_kind_of String + expect(authorized_keys.first['key']).to be_kind_of String + expect(authorized_keys.first['pretty-print']).to be_kind_of String assert_requested :post, github_management_console_url("setup/api/settings/authorized-keys?authorized_key=ssh-rsa%20AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&api_key=#{@api_key}") end - it "adds a new authorized SSH keys (via a File handler)" do - key = File.new("spec/fixtures/fake_key2.pub", "r") + it 'adds a new authorized SSH keys (via a File handler)' do + key = File.new('spec/fixtures/fake_key2.pub', 'r') authorized_keys = @enterprise_management_console_client.add_authorized_key(key) expect(authorized_keys).to be_kind_of Array expect(authorized_keys.length).to match(2) - expect(authorized_keys.first["key"]).to be_kind_of String - expect(authorized_keys.first["pretty-print"]).to be_kind_of String + expect(authorized_keys.first['key']).to be_kind_of String + expect(authorized_keys.first['pretty-print']).to be_kind_of String assert_requested :post, github_management_console_url("setup/api/settings/authorized-keys?api_key=#{@api_key}&authorized_key=ssh-rsa%20AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") end - it "adds a new authorized SSH keys (via a string contents)" do - key = "ssh-rsa AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + it 'adds a new authorized SSH keys (via a string contents)' do + key = 'ssh-rsa AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' authorized_keys = @enterprise_management_console_client.add_authorized_key(key) expect(authorized_keys).to be_kind_of Array expect(authorized_keys.length).to match(3) - expect(authorized_keys.first["key"]).to be_kind_of String - expect(authorized_keys.first["pretty-print"]).to be_kind_of String + expect(authorized_keys.first['key']).to be_kind_of String + expect(authorized_keys.first['pretty-print']).to be_kind_of String assert_requested :post, github_management_console_url("setup/api/settings/authorized-keys?api_key=#{@api_key}&authorized_key=ssh-rsa%20AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA") end end # .add_authorized_key - describe ".remove_authorized_key", :vcr do - it "removes a new authorized SSH keys (via a file path)" do - key = "spec/fixtures/fake_key.pub" + describe '.remove_authorized_key', :vcr do + it 'removes a new authorized SSH keys (via a file path)' do + key = 'spec/fixtures/fake_key.pub' authorized_keys = @enterprise_management_console_client.remove_authorized_key(key) expect(authorized_keys).to be_kind_of Array expect(authorized_keys.length).to match(3) - expect(authorized_keys.first["key"]).to be_kind_of String - expect(authorized_keys.first["pretty-print"]).to be_kind_of String + expect(authorized_keys.first['key']).to be_kind_of String + expect(authorized_keys.first['pretty-print']).to be_kind_of String assert_requested :delete, github_management_console_url("setup/api/settings/authorized-keys?authorized_key=ssh-rsa%20AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&api_key=#{@api_key}") end - it "removes a new authorized SSH keys (via a File handler)" do - key = File.new("spec/fixtures/fake_key2.pub", "r") + it 'removes a new authorized SSH keys (via a File handler)' do + key = File.new('spec/fixtures/fake_key2.pub', 'r') authorized_keys = @enterprise_management_console_client.remove_authorized_key(key) expect(authorized_keys).to be_kind_of Array expect(authorized_keys.length).to match(2) - expect(authorized_keys.first["key"]).to be_kind_of String - expect(authorized_keys.first["pretty-print"]).to be_kind_of String + expect(authorized_keys.first['key']).to be_kind_of String + expect(authorized_keys.first['pretty-print']).to be_kind_of String assert_requested :delete, github_management_console_url("setup/api/settings/authorized-keys?authorized_key=ssh-rsa%20AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&api_key=#{@api_key}") end - it "removes a new authorized SSH keys (via a string contents)" do - key = "ssh-rsa AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA" + it 'removes a new authorized SSH keys (via a string contents)' do + key = 'ssh-rsa AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' authorized_keys = @enterprise_management_console_client.remove_authorized_key(key) expect(authorized_keys).to be_kind_of Array expect(authorized_keys.length).to match(2) - expect(authorized_keys.first["key"]).to be_kind_of String - expect(authorized_keys.first["pretty-print"]).to be_kind_of String + expect(authorized_keys.first['key']).to be_kind_of String + expect(authorized_keys.first['pretty-print']).to be_kind_of String assert_requested :delete, github_management_console_url("setup/api/settings/authorized-keys?authorized_key=ssh-rsa%20AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA&api_key=#{@api_key}") end diff --git a/spec/octokit/enterprise_management_console_spec.rb b/spec/octokit/enterprise_management_console_spec.rb index 162215e36..c4f5489ef 100644 --- a/spec/octokit/enterprise_management_console_spec.rb +++ b/spec/octokit/enterprise_management_console_spec.rb @@ -1,14 +1,12 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::EnterpriseManagementConsoleClient do - - describe "module configuration" do - - it "inherits Octokit::Client" do + describe 'module configuration' do + it 'inherits Octokit::Client' do admin_client = Octokit::EnterpriseManagementConsoleClient.new expect admin_client.is_a? Octokit::Client end - end - end diff --git a/spec/octokit/gist_spec.rb b/spec/octokit/gist_spec.rb index 9af848f00..8ca9a4a69 100644 --- a/spec/octokit/gist_spec.rb +++ b/spec/octokit/gist_spec.rb @@ -1,49 +1,48 @@ -# -*- encoding: utf-8 -*- +# frozen_string_literal: true + require 'helper' describe Octokit::Gist do - - context "when given a URL" do - it "sets the id" do - gist = Octokit::Gist.from_url("https://gist.github.com/12345") + context 'when given a URL' do + it 'sets the id' do + gist = Octokit::Gist.from_url('https://gist.github.com/12345') expect(gist.id).to eq('12345') end end - context "when passed a string ID" do + context 'when passed a string ID' do before do @gist = Octokit::Gist.new('12345') end - it "sets the gist ID" do + it 'sets the gist ID' do expect(@gist.id).to eq('12345') end - it "sets the url" do + it 'sets the url' do expect(@gist.url).to eq('https://gist.github.com/12345') end - it "renders id as string" do + it 'renders id as string' do expect(@gist.to_s).to eq(@gist.id) end end - context "when passed a Integer ID" do + context 'when passed a Integer ID' do before do - @gist = Octokit::Gist.new(12345) + @gist = Octokit::Gist.new(12_345) end - it "sets the gist ID as a string" do + it 'sets the gist ID as a string' do expect(@gist.id).to eq('12345') end - it "sets the url" do + it 'sets the url' do expect(@gist.url).to eq('https://gist.github.com/12345') end - it "renders id as string" do + it 'renders id as string' do expect(@gist.to_s).to eq(@gist.id) end end - end diff --git a/spec/octokit/organization_spec.rb b/spec/octokit/organization_spec.rb index 266e971b0..3e2f71326 100644 --- a/spec/octokit/organization_spec.rb +++ b/spec/octokit/organization_spec.rb @@ -1,17 +1,19 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::Organization do - describe ".path" do - context "with name" do - it "returns name api path" do + describe '.path' do + context 'with name' do + it 'returns name api path' do path = Octokit::Organization.path 'octokit' expect(path).to eq 'orgs/octokit' end end # with login - context "with id" do - it "returns id api path" do - path = Octokit::Organization.path 3430433 + context 'with id' do + it 'returns id api path' do + path = Octokit::Organization.path 3_430_433 expect(path).to eq 'organizations/3430433' end end # with id diff --git a/spec/octokit/rate_limit_spec.rb b/spec/octokit/rate_limit_spec.rb index b2d9486d7..5543c15d3 100644 --- a/spec/octokit/rate_limit_spec.rb +++ b/spec/octokit/rate_limit_spec.rb @@ -1,23 +1,24 @@ +# frozen_string_literal: true + require 'helper' require 'octokit/rate_limit' describe Octokit::RateLimit do - - describe ".from_response" do + describe '.from_response' do let(:response_headers) do { - "X-RateLimit-Limit" => 60, - "X-RateLimit-Remaining" => 42, - "X-RateLimit-Reset" => (Time.now + 60).to_i + 'X-RateLimit-Limit' => 60, + 'X-RateLimit-Remaining' => 42, + 'X-RateLimit-Reset' => (Time.now + 60).to_i } end - let(:response) { double("response") } + let(:response) { double('response') } - it "parses rate limit info from response headers" do - expect(response).to receive(:headers). - at_least(:once). - and_return(response_headers) + it 'parses rate limit info from response headers' do + expect(response).to receive(:headers) + .at_least(:once) + .and_return(response_headers) info = described_class.from_response(response) expect(info.limit).to eq(60) expect(info.remaining).to eq(42) @@ -25,10 +26,10 @@ expect(info.resets_at).to be_kind_of(Time) end - it "returns a positive rate limit for Enterprise" do - expect(response).to receive(:headers). - at_least(:once). - and_return({ }) + it 'returns a positive rate limit for Enterprise' do + expect(response).to receive(:headers) + .at_least(:once) + .and_return({}) info = described_class.from_response(response) expect(info.limit).to eq(1) expect(info.remaining).to eq(1) @@ -36,7 +37,7 @@ expect(info.resets_at).to be_kind_of(Time) end - it "handles nil responses" do + it 'handles nil responses' do info = described_class.from_response(nil) expect(info.limit).to be_nil expect(info.remaining).to be_nil @@ -44,11 +45,11 @@ expect(info.resets_at).to be_nil end - it "handles resets_in time in past" do - expect(response).to receive(:headers). - at_least(:once). - and_return( - response_headers.merge("X-RateLimit-Reset" => (Time.now - 60).to_i) + it 'handles resets_in time in past' do + expect(response).to receive(:headers) + .at_least(:once) + .and_return( + response_headers.merge('X-RateLimit-Reset' => (Time.now - 60).to_i) ) info = described_class.from_response(response) expect(info.limit).to eq(60) diff --git a/spec/octokit/repository_spec.rb b/spec/octokit/repository_spec.rb index 2c8eff6ac..c0cebd376 100644 --- a/spec/octokit/repository_spec.rb +++ b/spec/octokit/repository_spec.rb @@ -1,179 +1,180 @@ -# -*- encoding: utf-8 -*- +# frozen_string_literal: true + require 'helper' describe Octokit::Repository do - context "when passed a string containg a slash" do + context 'when passed a string containg a slash' do before do - @repository = Octokit::Repository.new("sferik/octokit") + @repository = Octokit::Repository.new('sferik/octokit') end - it "sets the repository name and username" do - expect(@repository.name).to eq("octokit") - expect(@repository.username).to eq("sferik") + it 'sets the repository name and username' do + expect(@repository.name).to eq('octokit') + expect(@repository.username).to eq('sferik') end - it "responds to repo and user" do - expect(@repository.repo).to eq("octokit") - expect(@repository.user).to eq("sferik") + it 'responds to repo and user' do + expect(@repository.repo).to eq('octokit') + expect(@repository.user).to eq('sferik') end - it "renders slug as string" do - expect(@repository.slug).to eq("sferik/octokit") + it 'renders slug as string' do + expect(@repository.slug).to eq('sferik/octokit') expect(@repository.to_s).to eq(@repository.slug) end - it "renders url as string" do + it 'renders url as string' do expect(@repository.url).to eq('https://github.com/sferik/octokit') end end - context "when passed a string without a slash" do - it "raises ArgumentError" do - expect { Octokit::Repository.new('raise-error') }. - to raise_error Octokit::InvalidRepository, '"raise-error" is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' + context 'when passed a string without a slash' do + it 'raises ArgumentError' do + expect { Octokit::Repository.new('raise-error') } + .to raise_error Octokit::InvalidRepository, '"raise-error" is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' end end - context "when passed a string with more than 1 slash" do - it "raises ArgumentError" do - expect { Octokit::Repository.new('more_than/one/slash') }. - to raise_error Octokit::InvalidRepository, '"more_than/one/slash" is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' + context 'when passed a string with more than 1 slash' do + it 'raises ArgumentError' do + expect { Octokit::Repository.new('more_than/one/slash') } + .to raise_error Octokit::InvalidRepository, '"more_than/one/slash" is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' end end - context "when passed an invalid path" do - it "raises ArgumentError" do - expect { Octokit::Repository.new('invalid / path') }. - to raise_error Octokit::InvalidRepository, '"invalid / path" is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' + context 'when passed an invalid path' do + it 'raises ArgumentError' do + expect { Octokit::Repository.new('invalid / path') } + .to raise_error Octokit::InvalidRepository, '"invalid / path" is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' end end - context "when passed a boolean true" do - it "raises ArgumentError" do - expect { Octokit::Repository.new(true) }. - to raise_error Octokit::InvalidRepository, "true is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." + context 'when passed a boolean true' do + it 'raises ArgumentError' do + expect { Octokit::Repository.new(true) } + .to raise_error Octokit::InvalidRepository, 'true is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' end end - context "when passed a boolean false" do - it "false raises ArgumentError" do - expect { Octokit::Repository.new(false) }. - to raise_error Octokit::InvalidRepository, "false is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." + context 'when passed a boolean false' do + it 'false raises ArgumentError' do + expect { Octokit::Repository.new(false) } + .to raise_error Octokit::InvalidRepository, 'false is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' end end - context "when passed nil" do - it "raises ArgumentError" do - expect { Octokit::Repository.new(nil) }. - to raise_error Octokit::InvalidRepository, "nil is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." + context 'when passed nil' do + it 'raises ArgumentError' do + expect { Octokit::Repository.new(nil) } + .to raise_error Octokit::InvalidRepository, 'nil is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' end end - describe ".path" do - context "with named repository" do - it "returns the url path" do + describe '.path' do + context 'with named repository' do + it 'returns the url path' do repository = Octokit::Repository.new('sferik/octokit') expect(repository.path).to eq 'repos/sferik/octokit' end end - context "with repository id" do - it "returns theu url path" do - repository = Octokit::Repository.new(12345) + context 'with repository id' do + it 'returns theu url path' do + repository = Octokit::Repository.new(12_345) expect(repository.path).to eq 'repositories/12345' end end end # .path - describe "self.path" do - it "returns the api path" do + describe 'self.path' do + it 'returns the api path' do expect(Octokit::Repository.path('sferik/octokit')).to eq 'repos/sferik/octokit' - expect(Octokit::Repository.path(12345)).to eq 'repositories/12345' + expect(Octokit::Repository.path(12_345)).to eq 'repositories/12345' end end - context "when passed an integer" do - it "sets the repository id" do - repository = Octokit::Repository.new(12345) - expect(repository.id).to eq 12345 + context 'when passed an integer' do + it 'sets the repository id' do + repository = Octokit::Repository.new(12_345) + expect(repository.id).to eq 12_345 end end - context "when passed a hash" do - it "sets the repository name and username" do - repository = Octokit::Repository.new({:username => 'sferik', :name => 'octokit'}) - expect(repository.name).to eq("octokit") - expect(repository.username).to eq("sferik") + context 'when passed a hash' do + it 'sets the repository name and username' do + repository = Octokit::Repository.new({ username: 'sferik', name: 'octokit' }) + expect(repository.name).to eq('octokit') + expect(repository.username).to eq('sferik') end end - context "when passed a frozen hash" do - it "sets the repository name and username" do - repository = Octokit::Repository.new({:username => 'sferik', :name => 'octokit'}.freeze) - expect(repository.name).to eq("octokit") - expect(repository.username).to eq("sferik") + context 'when passed a frozen hash' do + it 'sets the repository name and username' do + repository = Octokit::Repository.new({ username: 'sferik', name: 'octokit' }.freeze) + expect(repository.name).to eq('octokit') + expect(repository.username).to eq('sferik') end end - context "when passed a hash with invalid username" do - it "raises ArgumentError" do - expect { Octokit::Repository.new({:username => 'invalid username!', :name => 'octokit'}) }. - to raise_error Octokit::InvalidRepository, "#{{:username => 'invalid username!', :name => 'octokit'}.inspect} is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." + context 'when passed a hash with invalid username' do + it 'raises ArgumentError' do + expect { Octokit::Repository.new({ username: 'invalid username!', name: 'octokit' }) } + .to raise_error Octokit::InvalidRepository, "#{{ username: 'invalid username!', name: 'octokit' }.inspect} is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." end end - context "when passed a hash with a username that contains a slash" do - it "raises ArgumentError" do - expect { Octokit::Repository.new({:username => 'invalid/username', :name => 'octokit'}) }. - to raise_error Octokit::InvalidRepository, "#{{:username => 'invalid/username', :name => 'octokit'}.inspect} is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." + context 'when passed a hash with a username that contains a slash' do + it 'raises ArgumentError' do + expect { Octokit::Repository.new({ username: 'invalid/username', name: 'octokit' }) } + .to raise_error Octokit::InvalidRepository, "#{{ username: 'invalid/username', name: 'octokit' }.inspect} is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." end end - context "when passed a hash with invalid repo" do - it "raises ArgumentError" do - expect { Octokit::Repository.new({:username => 'sferik', :name => 'invalid repo!'}) }. - to raise_error Octokit::InvalidRepository, "#{{:username => 'sferik', :name => 'invalid repo!'}.inspect} is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." + context 'when passed a hash with invalid repo' do + it 'raises ArgumentError' do + expect { Octokit::Repository.new({ username: 'sferik', name: 'invalid repo!' }) } + .to raise_error Octokit::InvalidRepository, "#{{ username: 'sferik', name: 'invalid repo!' }.inspect} is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." end end - context "when passed a hash with a repo that contains a slash" do - it "raises ArgumentError" do - expect { Octokit::Repository.new({:username => 'sferik', :name => 'invalid/repo'}) }. - to raise_error Octokit::InvalidRepository, "#{{:username => 'sferik', :name => 'invalid/repo'}.inspect} is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." + context 'when passed a hash with a repo that contains a slash' do + it 'raises ArgumentError' do + expect { Octokit::Repository.new({ username: 'sferik', name: 'invalid/repo' }) } + .to raise_error Octokit::InvalidRepository, "#{{ username: 'sferik', name: 'invalid/repo' }.inspect} is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys." end end - context "when passed a Repo" do - it "sets the repository name and username" do + context 'when passed a Repo' do + it 'sets the repository name and username' do repository = Octokit::Repository.new(Octokit::Repository.new('sferik/octokit')) - expect(repository.name).to eq("octokit") - expect(repository.username).to eq("sferik") + expect(repository.name).to eq('octokit') + expect(repository.username).to eq('sferik') expect(repository.url).to eq('https://github.com/sferik/octokit') end end - context "when given a URL" do - it "sets the repository name and username" do - repository = Octokit::Repository.from_url("https://github.com/sferik/octokit") - expect(repository.name).to eq("octokit") - expect(repository.username).to eq("sferik") + context 'when given a URL' do + it 'sets the repository name and username' do + repository = Octokit::Repository.from_url('https://github.com/sferik/octokit') + expect(repository.name).to eq('octokit') + expect(repository.username).to eq('sferik') end - it "parses api urls" do - repo_from_url = Octokit::Repository.from_url("https://api.github.com/repos/sferik/octokit-repos/issues/21") - expect(repo_from_url.name).to eq("octokit-repos") - expect(repo_from_url.username).to eq("sferik") + it 'parses api urls' do + repo_from_url = Octokit::Repository.from_url('https://api.github.com/repos/sferik/octokit-repos/issues/21') + expect(repo_from_url.name).to eq('octokit-repos') + expect(repo_from_url.username).to eq('sferik') end - it "parses html urls" do - repo_from_url = Octokit::Repository.from_url("https://github.com/sferik/octokit/issues/132") - expect(repo_from_url.name).to eq("octokit") - expect(repo_from_url.username).to eq("sferik") + it 'parses html urls' do + repo_from_url = Octokit::Repository.from_url('https://github.com/sferik/octokit/issues/132') + expect(repo_from_url.name).to eq('octokit') + expect(repo_from_url.username).to eq('sferik') end - it "raises InvalidRepository error for unsupported url" do - expect { Octokit::Repository.new("https://api.github.com/gists/0083ae") }. - to raise_error Octokit::InvalidRepository, '"https://api.github.com/gists/0083ae" is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' + it 'raises InvalidRepository error for unsupported url' do + expect { Octokit::Repository.new('https://api.github.com/gists/0083ae') } + .to raise_error Octokit::InvalidRepository, '"https://api.github.com/gists/0083ae" is invalid as a repository identifier. Use the user/repo (String) format, or the repository ID (Integer), or a hash containing :repo and :user keys.' end end end diff --git a/spec/octokit/user_spec.rb b/spec/octokit/user_spec.rb index 22fd2c003..e5531b1f2 100644 --- a/spec/octokit/user_spec.rb +++ b/spec/octokit/user_spec.rb @@ -1,23 +1,25 @@ +# frozen_string_literal: true + require 'helper' describe Octokit::User do - describe ".path" do - context "with no user passed" do - it "returns default path" do + describe '.path' do + context 'with no user passed' do + it 'returns default path' do path = Octokit::User.path nil expect(path).to eq 'user' end end - context "with login" do - it "returns login api path" do + context 'with login' do + it 'returns login api path' do path = Octokit::User.path 'pengwynn' expect(path).to eq 'users/pengwynn' end end # with login - context "with id" do - it "returns id api path" do + context 'with id' do + it 'returns id api path' do path = Octokit::User.path 865 expect(path).to eq 'user/865' end diff --git a/spec/octokit_spec.rb b/spec/octokit_spec.rb index 47e1fa2aa..705bb19bf 100644 --- a/spec/octokit_spec.rb +++ b/spec/octokit_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'helper' describe Octokit do @@ -9,22 +11,22 @@ Octokit.reset! end - it "sets defaults" do - Octokit::Configurable.keys.each do |key| + it 'sets defaults' do + Octokit::Configurable.each_key do |key| expect(Octokit.instance_variable_get(:"@#{key}")).to eq(Octokit::Default.send(key)) end end - describe ".client" do - it "creates an Octokit::Client" do + describe '.client' do + it 'creates an Octokit::Client' do expect(Octokit.client).to be_kind_of Octokit::Client end - it "caches the client when the same options are passed" do + it 'caches the client when the same options are passed' do expect(Octokit.client).to eq(Octokit.client) end - it "returns a fresh client when options are not the same" do + it 'returns a fresh client when options are not the same' do client = Octokit.client - Octokit.access_token = "87614b09dd141c22800f96f11737ade5226d7ba8" + Octokit.access_token = '87614b09dd141c22800f96f11737ade5226d7ba8' client_two = Octokit.client client_three = Octokit.client expect(client).not_to eq(client_two) @@ -32,8 +34,8 @@ end end - describe ".configure" do - Octokit::Configurable.keys.each do |key| + describe '.configure' do + Octokit::Configurable.each_key do |key| it "sets the #{key.to_s.gsub('_', ' ')}" do Octokit.configure do |config| config.send("#{key}=", key) @@ -42,5 +44,4 @@ end end end - end diff --git a/yard/default/layout/html/setup.rb b/yard/default/layout/html/setup.rb index 8aecfc319..1a42e3add 100644 --- a/yard/default/layout/html/setup.rb +++ b/yard/default/layout/html/setup.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + def diskfile @file.attributes[:markup] ||= markup_for_file('', @file.filename) data = htmlify(@file.contents, @file.attributes[:markup]) @@ -7,11 +9,11 @@ def diskfile # generates them as #Some_thing so this makes the necessary # changes to the generate docs so the links work both on # GitHub and in the documentation. - if @file.name == "README" + if @file.name == 'README' data.scan(/href\=\"\#(.+)\"/).each do |bad_link| data.gsub!(bad_link.first, bad_link.first.capitalize.gsub('-', '_')) end end - "

" + data + "
" + "
" + data + '
' end From 415c2d8f0f0614867d6d99b90ce892dd8d4e08f4 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Tue, 7 Jun 2022 13:13:00 +0100 Subject: [PATCH 07/13] Revert problematic `Configurable#each_key` Rubocop autocorrects --- lib/octokit/client.rb | 9 ++++++++- lib/octokit/configurable.rb | 8 +++++++- lib/octokit/enterprise_admin_client.rb | 9 ++++++++- .../enterprise_management_console_client.rb | 8 +++++++- spec/octokit/client_spec.rb | 16 ++++++++++++++-- spec/octokit_spec.rb | 16 ++++++++++++++-- 6 files changed, 58 insertions(+), 8 deletions(-) diff --git a/lib/octokit/client.rb b/lib/octokit/client.rb index 43c8947f5..4f9ccb382 100644 --- a/lib/octokit/client.rb +++ b/lib/octokit/client.rb @@ -132,7 +132,14 @@ class Client def initialize(options = {}) # Use options passed in, but fall back to module defaults - Octokit::Configurable.each_key do |key| + # + # rubocop:disable Style/HashEachMethods + # + # This may look like a `.keys.each` which should be replaced with `#each_key`, but + # this doesn't actually work, since `#keys` is just a method we've defined ourselves. + # The class doesn't fulfill the whole `Enumerable` contract. + Octokit::Configurable.keys.each do |key| + # rubocop:enable Style/HashEachMethods value = options[key].nil? ? Octokit.instance_variable_get(:"@#{key}") : options[key] instance_variable_set(:"@#{key}", value) end diff --git a/lib/octokit/configurable.rb b/lib/octokit/configurable.rb index b84832d4d..52410f826 100644 --- a/lib/octokit/configurable.rb +++ b/lib/octokit/configurable.rb @@ -97,7 +97,13 @@ def configure # Reset configuration options to default values def reset! - Octokit::Configurable.each_key do |key| + # rubocop:disable Style/HashEachMethods + # + # This may look like a `.keys.each` which should be replaced with `#each_key`, but + # this doesn't actually work, since `#keys` is just a method we've defined ourselves. + # The class doesn't fulfill the whole `Enumerable` contract. + Octokit::Configurable.keys.each do |key| + # rubocop:enable Style/HashEachMethods instance_variable_set(:"@#{key}", Octokit::Default.options[key]) end self diff --git a/lib/octokit/enterprise_admin_client.rb b/lib/octokit/enterprise_admin_client.rb index 4da56bb11..8b334ee31 100644 --- a/lib/octokit/enterprise_admin_client.rb +++ b/lib/octokit/enterprise_admin_client.rb @@ -29,7 +29,14 @@ class EnterpriseAdminClient def initialize(options = {}) # Use options passed in, but fall back to module defaults - Octokit::Configurable.each_key do |key| + # + # rubocop:disable Style/HashEachMethods + # + # This may look like a `.keys.each` which should be replaced with `#each_key`, but + # this doesn't actually work, since `#keys` is just a method we've defined ourselves. + # The class doesn't fulfill the whole `Enumerable` contract. + Octokit::Configurable.keys.each do |key| + # rubocop:enable Style/HashEachMethods instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}")) end diff --git a/lib/octokit/enterprise_management_console_client.rb b/lib/octokit/enterprise_management_console_client.rb index 641c495da..244e16e4a 100644 --- a/lib/octokit/enterprise_management_console_client.rb +++ b/lib/octokit/enterprise_management_console_client.rb @@ -20,7 +20,13 @@ class EnterpriseManagementConsoleClient def initialize(options = {}) # Use options passed in, but fall back to module defaults - Octokit::Configurable.each_key do |key| + # rubocop:disable Style/HashEachMethods + # + # This may look like a `.keys.each` which should be replaced with `#each_key`, but + # this doesn't actually work, since `#keys` is just a method we've defined ourselves. + # The class doesn't fulfill the whole `Enumerable` contract. + Octokit::Configurable.keys.each do |key| + # rubocop:enable Style/HashEachMethods instance_variable_set(:"@#{key}", options[key] || Octokit.instance_variable_get(:"@#{key}")) end end diff --git a/spec/octokit/client_spec.rb b/spec/octokit/client_spec.rb index 0ed2d0e1c..592b81227 100644 --- a/spec/octokit/client_spec.rb +++ b/spec/octokit/client_spec.rb @@ -16,7 +16,13 @@ before do Octokit.reset! Octokit.configure do |config| - Octokit::Configurable.each_key do |key| + # rubocop:disable Style/HashEachMethods + # + # This may look like a `.keys.each` which should be replaced with `#each_key`, but + # this doesn't actually work, since `#keys` is just a method we've defined ourselves. + # The class doesn't fulfill the whole `Enumerable` contract. + Octokit::Configurable.keys.each do |key| + # rubocop:enable Style/HashEachMethods config.send("#{key}=", "Some #{key}") end end @@ -28,7 +34,13 @@ it 'inherits the module configuration' do client = Octokit::Client.new - Octokit::Configurable.each_key do |key| + # rubocop:disable Style/HashEachMethods + # + # This may look like a `.keys.each` which should be replaced with `#each_key`, but + # this doesn't actually work, since `#keys` is just a method we've defined ourselves. + # The class doesn't fulfill the whole `Enumerable` contract. + Octokit::Configurable.keys.each do |key| + # rubocop:enable Style/HashEachMethods expect(client.instance_variable_get(:"@#{key}")).to eq("Some #{key}") end end diff --git a/spec/octokit_spec.rb b/spec/octokit_spec.rb index 705bb19bf..375b4bc59 100644 --- a/spec/octokit_spec.rb +++ b/spec/octokit_spec.rb @@ -12,7 +12,13 @@ end it 'sets defaults' do - Octokit::Configurable.each_key do |key| + # rubocop:disable Style/HashEachMethods + # + # This may look like a `.keys.each` which should be replaced with `#each_key`, but + # this doesn't actually work, since `#keys` is just a method we've defined ourselves. + # The class doesn't fulfill the whole `Enumerable` contract. + Octokit::Configurable.keys.each do |key| + # rubocop:enable Style/HashEachMethods expect(Octokit.instance_variable_get(:"@#{key}")).to eq(Octokit::Default.send(key)) end end @@ -35,7 +41,13 @@ end describe '.configure' do - Octokit::Configurable.each_key do |key| + # rubocop:disable Style/HashEachMethods + # + # This may look like a `.keys.each` which should be replaced with `#each_key`, but + # this doesn't actually work, since `#keys` is just a method we've defined ourselves. + # The class doesn't fulfill the whole `Enumerable` contract. + Octokit::Configurable.keys.each do |key| + # rubocop:enable Style/HashEachMethods it "sets the #{key.to_s.gsub('_', ' ')}" do Octokit.configure do |config| config.send("#{key}=", key) From ab1b73f55b3846277df3747872b05dfcb6363a64 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Tue, 7 Jun 2022 18:42:13 +0100 Subject: [PATCH 08/13] Disable the Layout/BlockAlignment cop for Guardfile, since it is erroring --- .rubocop.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 15b38d111..a28d17b65 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -3,6 +3,11 @@ AllCops: Metrics/BlockLength: Exclude: - spec/**/*_spec.rb +Layout/BlockAlignment: + Exclude: + # This file is causing Rubocop to error - see + # for an example + - Guardfile Lint/RaiseException: Enabled: true Lint/StructNewOverride: From 0fa2e756e97fb879cd98670fc44fcfc3bb1c3566 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Tue, 7 Jun 2022 18:42:49 +0100 Subject: [PATCH 09/13] Generate Rubocop todo list from changes which can't be autocorrected --- .rubocop.yml | 2 + .rubocop_todo.yml | 239 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 241 insertions(+) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index a28d17b65..f1632a42f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,3 +1,5 @@ +inherit_from: .rubocop_todo.yml + AllCops: TargetRubyVersion: 2.3 Metrics/BlockLength: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 000000000..b0a93abae --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,239 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2022-06-07 18:42:36 +0100 using RuboCop version 0.81.0. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Configuration parameters: Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'octokit.gemspec' + +# Offense count: 4 +Lint/AmbiguousOperator: + Exclude: + - 'lib/octokit/client.rb' + - 'lib/octokit/client/pub_sub_hubbub.rb' + - 'lib/octokit/connection.rb' + +# Offense count: 13 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Exclude: + - 'lib/octokit/client/contents.rb' + - 'lib/octokit/client/feeds.rb' + - 'lib/octokit/client/gists.rb' + - 'lib/octokit/client/organizations.rb' + - 'lib/octokit/client/releases.rb' + - 'lib/octokit/client/stats.rb' + - 'lib/octokit/connection.rb' + - 'lib/octokit/error.rb' + - 'lib/octokit/response/raise_error.rb' + +# Offense count: 20 +# Configuration parameters: AllowComments. +Lint/SuppressedException: + Exclude: + - 'Rakefile' + - 'spec/helper.rb' + - 'spec/octokit/client/actions_secrets_spec.rb' + - 'spec/octokit/client/commits_spec.rb' + - 'spec/octokit/client/deployments_spec.rb' + - 'spec/octokit/client/hooks_spec.rb' + - 'spec/octokit/client/issues_spec.rb' + - 'spec/octokit/client/reactions_spec.rb' + - 'spec/octokit/client/refs_spec.rb' + - 'spec/octokit/client/repositories_spec.rb' + - 'spec/octokit/client/repository_invitations_spec.rb' + - 'spec/octokit/client/source_import_spec.rb' + +# Offense count: 31 +Lint/UselessAssignment: + Exclude: + - 'spec/octokit/client/actions_secrets_spec.rb' + - 'spec/octokit/client/actions_workflow_runs_spec.rb' + - 'spec/octokit/client/apps_spec.rb' + - 'spec/octokit/client/hooks_spec.rb' + - 'spec/octokit/client/organizations_spec.rb' + - 'spec/octokit/client/rate_limit_spec.rb' + - 'spec/octokit/client/releases_spec.rb' + - 'spec/octokit/client/repositories_spec.rb' + - 'spec/octokit/client/stats_spec.rb' + - 'spec/octokit/client_spec.rb' + - 'spec/octokit/enterprise_admin_client/search_indexing_spec.rb' + - 'spec/octokit/enterprise_admin_client/users_spec.rb' + - 'spec/octokit/enterprise_management_console_client/management_console_spec.rb' + +# Offense count: 1 +# Configuration parameters: CheckForMethodsWithNoSideEffects. +Lint/Void: + Exclude: + - 'lib/octokit/repo_arguments.rb' + +# Offense count: 16 +# Configuration parameters: IgnoredMethods. +Metrics/AbcSize: + Max: 33 + +# Offense count: 1 +# Configuration parameters: CountComments, ExcludedMethods. +# ExcludedMethods: refine +Metrics/BlockLength: + Max: 102 + +# Offense count: 1 +# Configuration parameters: CountBlocks. +Metrics/BlockNesting: + Max: 4 + +# Offense count: 2 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 160 + +# Offense count: 7 +# Configuration parameters: IgnoredMethods. +Metrics/CyclomaticComplexity: + Max: 18 + +# Offense count: 29 +# Configuration parameters: CountComments, ExcludedMethods. +Metrics/MethodLength: + Max: 26 + +# Offense count: 4 +# Configuration parameters: CountComments. +Metrics/ModuleLength: + Max: 217 + +# Offense count: 4 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 9 + +# Offense count: 6 +# Configuration parameters: IgnoredMethods. +Metrics/PerceivedComplexity: + Max: 13 + +# Offense count: 1 +Naming/AccessorMethodName: + Exclude: + - 'lib/octokit/enterprise_management_console_client/management_console.rb' + +# Offense count: 1 +# Configuration parameters: ForbiddenDelimiters. +# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$)) +Naming/HeredocDelimiterNaming: + Exclude: + - 'lib/octokit/preview.rb' + +# Offense count: 1 +# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. +# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp +Naming/MethodParameterName: + Exclude: + - 'lib/octokit/client/legacy_search.rb' + +# Offense count: 9 +# Configuration parameters: AllowedChars. +Style/AsciiComments: + Exclude: + - 'lib/octokit/client/contents.rb' + - 'lib/octokit/client/gists.rb' + - 'lib/octokit/client/licenses.rb' + - 'lib/octokit/client/organizations.rb' + - 'lib/octokit/client/repositories.rb' + - 'lib/octokit/client/stats.rb' + - 'lib/octokit/client/users.rb' + - 'lib/octokit/middleware/follow_redirects.rb' + +# Offense count: 484 +Style/CommentedKeyword: + Enabled: false + +# Offense count: 3 +Style/Documentation: + Exclude: + - 'spec/**/*' + - 'test/**/*' + - 'lib/octokit/client/actions_workflow_runs.rb' + - 'lib/octokit/client/users.rb' + - 'lib/octokit/enterprise_management_console_client/management_console.rb' + +# Offense count: 7 +Style/DoubleNegation: + Exclude: + - 'lib/octokit/authentication.rb' + - 'lib/octokit/client/repositories.rb' + - 'lib/octokit/configurable.rb' + - 'spec/helper.rb' + +# Offense count: 7 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Exclude: + - 'lib/octokit.rb' + - 'lib/octokit/client/feeds.rb' + - 'lib/octokit/error.rb' + - 'lib/octokit/repository.rb' + - 'lib/octokit/response/feed_parser.rb' + - 'lib/octokit/response/raise_error.rb' + +# Offense count: 1 +# Configuration parameters: AllowIfModifier. +Style/IfInsideElse: + Exclude: + - 'lib/octokit/connection.rb' + +# Offense count: 22 +# Cop supports --auto-correct. +Style/IfUnlessModifier: + Exclude: + - 'lib/octokit.rb' + - 'lib/octokit/client.rb' + - 'lib/octokit/client/authorizations.rb' + - 'lib/octokit/client/commits.rb' + - 'lib/octokit/client/organizations.rb' + - 'lib/octokit/client/repositories.rb' + - 'lib/octokit/default.rb' + - 'lib/octokit/enterprise_management_console_client/management_console.rb' + - 'lib/octokit/error.rb' + - 'lib/octokit/repository.rb' + - 'spec/helper.rb' + +# Offense count: 1 +Style/MultilineTernaryOperator: + Exclude: + - 'lib/octokit/client/contents.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, EnforcedStyle, IgnoredMethods. +# SupportedStyles: predicate, comparison +Style/NumericPredicate: + Exclude: + - 'spec/**/*' + - 'lib/octokit/connection.rb' + +# Offense count: 1 +Style/StructInheritance: + Exclude: + - 'lib/octokit/rate_limit.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/WhileUntilModifier: + Exclude: + - 'spec/octokit/client/source_import_spec.rb' + +# Offense count: 1290 +# Cop supports --auto-correct. +# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 517 From dc6eaeb9b9a1fd02ac69d9f6ea09bef988ccf856 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Wed, 1 Jun 2022 19:57:36 +0100 Subject: [PATCH 10/13] Test against Ruby 2.3 and Ruby 2.4 in CI --- .github/workflows/octokit.yml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/octokit.yml b/.github/workflows/octokit.yml index 2c3cbaa49..1bc30d3ef 100644 --- a/.github/workflows/octokit.yml +++ b/.github/workflows/octokit.yml @@ -20,11 +20,18 @@ jobs: fail-fast: false matrix: os: [ ubuntu ] - ruby: [ 2.5, 2.6, 2.7, '3.0', '3.1', head ] + ruby: [ 2.3, 2.4, 2.5, 2.6, 2.7, '3.0', '3.1', head ] faraday: [ '~> 1.0', '~> 2.0' ] exclude: + # Faraday 2.x only works with Ruby versions 2.6 onwards. + # Fortunately, the gem supports Faraday 1.x, so we can just + # test against that. - ruby: 2.5 faraday: '~> 2.0' + - ruby: 2.4 + faraday: '~> 2.0' + - ruby: 2.3 + faraday: '~> 2.0' env: FARADAY_VERSION: ${{ matrix.faraday }} From f2a11a9944a2c7c5b9511dc9c54904da01c6dfa7 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Wed, 1 Jun 2022 20:34:12 +0100 Subject: [PATCH 11/13] Only install faraday-retry and faraday-multipart in CI when running Faraday 2.x --- Gemfile | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 695cd6fe1..911d5ddee 100644 --- a/Gemfile +++ b/Gemfile @@ -32,9 +32,14 @@ group :test do gem 'webmock', '~> 3.8', '>= 3.8.2' end -gem 'faraday', ENV.fetch('FARADAY_VERSION', '~> 2.0') -gem 'faraday-multipart' -gem 'faraday-retry' +faraday_version = ENV.fetch('FARADAY_VERSION', '~> 2.0') + +gem 'faraday', faraday_version + +if faraday_version.start_with?('~> 2') + gem 'faraday-multipart' + gem 'faraday-retry' +end group :test, :development do gem 'pry-byebug' From 64c95b4330901691ddd2cfd7dc82bc0c21964e6e Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Wed, 8 Jun 2022 12:08:16 +0100 Subject: [PATCH 12/13] Update RubyGems in CI on Ruby 2.3 and 2.4, as well as 2.5 --- .github/workflows/octokit.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/octokit.yml b/.github/workflows/octokit.yml index 1bc30d3ef..fe7c22d9d 100644 --- a/.github/workflows/octokit.yml +++ b/.github/workflows/octokit.yml @@ -50,8 +50,8 @@ jobs: ruby-version: ${{ matrix.ruby }} - name: Setup .netrc run: chmod 600 spec/fixtures/.netrc - - name: Ruby 2.5 needs a newer RubyGems to support frozen-string-literal - if: ${{ matrix.ruby == '2.5' }} + - name: Ruby 2.5 and earlier need a newer RubyGems to support frozen-string-literal + if: ${{ matrix.ruby == '2.5' || matrix.ruby == '2.4' || matrix.ruby == '2.3' }} run: gem update --system 2.7.11 - name: Install dependencies run: | From fa00889974d82a0b3cd12f55fdbd32bb499fb449 Mon Sep 17 00:00:00 2001 From: Tim Rogers Date: Wed, 8 Jun 2022 12:10:50 +0100 Subject: [PATCH 13/13] Don't test with frozen string literals on Ruby 2.3 ERB in Ruby 2.3 doesn't seem to be frozen string literal compatible - at least under certain cases. I observed a number of test failures in GitHub Actions when working with templates, generating an error like this: ``` (erb):1:in `concat': can't modify frozen String (RuntimeError) ``` You can see an example [here][1]. It seems prudent just to ignore this since (a) people are unlikely to use Ruby 2.3, (b) we are set to drop support for it and (c) it's even more unlikely that people use Ruby 2.3 *and* frozen string literals. [1]: https://github.com/octokit/octokit.rb/runs/6792298625?check_suite_focus=true --- .github/workflows/octokit.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/octokit.yml b/.github/workflows/octokit.yml index fe7c22d9d..1f92b61c3 100644 --- a/.github/workflows/octokit.yml +++ b/.github/workflows/octokit.yml @@ -58,11 +58,17 @@ jobs: bundle config set path .bundle/gems bundle config set without development bundle install --jobs 4 --retry 3 - - name: Test with RSpec + - name: Test with RSpec with frozen string literals enabled env: GITHUB_CI: 1 RUBYOPT: --enable-frozen-string-literal run: bundle exec rspec -w + if: ${{ matrix.ruby != '2.3' }} + - name: Test with RSpec without frozen string literals enabled + env: + GITHUB_CI: 1 + run: bundle exec rspec -w + if: ${{ matrix.ruby == '2.3' }} - name: Lint with Rubocop env: GITHUB_CI: 1