diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d9e1a9a10..59af8fc54 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,18 +1,16 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-06-28 04:00:53 UTC using RuboCop version 0.86.0. +# on 2020-09-12 21:24:48 +0530 using RuboCop version 0.75.1. # 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: 4 -# Configuration parameters: IgnoredMethods. Metrics/AbcSize: - Max: 34 + Max: 35 # Offense count: 3 -# Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: Max: 13 @@ -32,9 +30,8 @@ Metrics/ParameterLists: Max: 6 # Offense count: 1 -# Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: - Max: 10 + Max: 11 # Offense count: 1 # Cop supports --auto-correct. diff --git a/lib/gitlab.rb b/lib/gitlab.rb index 0a875bb0d..c4a0ead67 100644 --- a/lib/gitlab.rb +++ b/lib/gitlab.rb @@ -29,9 +29,11 @@ def self.method_missing(method, *args, &block) end # Delegate to Gitlab::Client + # rubocop:disable Style/OptionalBooleanParameter def self.respond_to_missing?(method_name, include_private = false) client.respond_to?(method_name) || super end + # rubocop:enable Style/OptionalBooleanParameter # Delegate to HTTParty.http_proxy def self.http_proxy(address = nil, port = nil, username = nil, password = nil) diff --git a/lib/gitlab/api.rb b/lib/gitlab/api.rb index cc8c2b7b6..509f1ddd3 100644 --- a/lib/gitlab/api.rb +++ b/lib/gitlab/api.rb @@ -10,6 +10,7 @@ class API < Request # Creates a new API. # @raise [Error:MissingCredentials] + # rubocop:disable Lint/MissingSuper def initialize(options = {}) options = Gitlab.options.merge(options) (Configuration::VALID_OPTIONS_KEYS + [:auth_token]).each do |key| @@ -18,5 +19,6 @@ def initialize(options = {}) request_defaults(sudo) self.class.headers 'User-Agent' => user_agent end + # rubocop:enable Lint/MissingSuper end end diff --git a/lib/gitlab/cli_helpers.rb b/lib/gitlab/cli_helpers.rb index 97b072388..08a3b46d2 100644 --- a/lib/gitlab/cli_helpers.rb +++ b/lib/gitlab/cli_helpers.rb @@ -111,7 +111,7 @@ def output_json(cmd, args, data) else hash_result = case data when Gitlab::ObjectifiedHash, Gitlab::FileResponse - record_hash([data], cmd, args, true) + record_hash([data], cmd, args, single_value: true) when Gitlab::PaginatedResponse record_hash(data, cmd, args) else @@ -162,7 +162,7 @@ def record_table(data, cmd, args) # @param [Array] args Options passed to the API call # @param [bool] single_value If set to true, a single result should be returned # @return [Hash] Result hash - def record_hash(data, cmd, args, single_value = false) + def record_hash(data, cmd, args, single_value: false) if data.empty? result = nil else diff --git a/lib/gitlab/client/commits.rb b/lib/gitlab/client/commits.rb index ca9792926..77a44dd28 100644 --- a/lib/gitlab/client/commits.rb +++ b/lib/gitlab/client/commits.rb @@ -166,7 +166,7 @@ def commit_status(project, sha, options = {}) # @option options [String] :name Filter by status name, eg. jenkins # @option options [String] :target_url The target URL to associate with this status def update_commit_status(project, sha, state, options = {}) - post("/projects/#{url_encode project}/statuses/#{sha}", query: options.merge(state: state)) + post("/projects/#{url_encode project}/statuses/#{sha}", body: options.merge(state: state)) end alias repo_update_commit_status update_commit_status diff --git a/lib/gitlab/client/container_registry.rb b/lib/gitlab/client/container_registry.rb index ff8caf733..dc9a5eaf6 100644 --- a/lib/gitlab/client/container_registry.rb +++ b/lib/gitlab/client/container_registry.rb @@ -79,7 +79,7 @@ def delete_registry_repository_tag(project, repository_id, tag_name) # @option options [String] :older_than(required) Tags to delete that are older than the given time, written in human readable form 1h, 1d, 1month. # @return [void] This API call returns an empty response body. def bulk_delete_registry_repository_tags(project, repository_id, options = {}) - delete("/projects/#{url_encode project}/registry/repositories/#{repository_id}/tags", query: options) + delete("/projects/#{url_encode project}/registry/repositories/#{repository_id}/tags", body: options) end end end diff --git a/lib/gitlab/client/group_labels.rb b/lib/gitlab/client/group_labels.rb index 9cca4bbdc..eecd2a32c 100644 --- a/lib/gitlab/client/group_labels.rb +++ b/lib/gitlab/client/group_labels.rb @@ -58,7 +58,7 @@ def edit_group_label(group, name, options = {}) # @param [String] name The name of a label. # @return [Gitlab::ObjectifiedHash] Information about deleted label. def delete_group_label(group, name) - delete("/groups/#{url_encode group}/labels", body: { name: name }) + delete("/groups/#{url_encode group}/labels/#{name}") end # Subscribes the user to a group label to receive notifications diff --git a/lib/gitlab/client/labels.rb b/lib/gitlab/client/labels.rb index 7373121d3..39dba8660 100644 --- a/lib/gitlab/client/labels.rb +++ b/lib/gitlab/client/labels.rb @@ -58,7 +58,7 @@ def edit_label(project, name, options = {}) # @param [String] name The name of a label. # @return [Gitlab::ObjectifiedHash] Information about deleted label. def delete_label(project, name) - delete("/projects/#{url_encode project}/labels", body: { name: name }) + delete("/projects/#{url_encode project}/labels/#{name}") end # Subscribes the user to a label to receive notifications diff --git a/lib/gitlab/client/pipeline_schedules.rb b/lib/gitlab/client/pipeline_schedules.rb index 9e9fe1efd..2b6d2f658 100644 --- a/lib/gitlab/client/pipeline_schedules.rb +++ b/lib/gitlab/client/pipeline_schedules.rb @@ -44,7 +44,7 @@ def pipeline_schedule(project, id) # @option options [Boolean] :active The activation of pipeline schedule. If false is set, the pipeline schedule will deactivated initially (default: true). # @return [Array] def create_pipeline_schedule(project, options = {}) - post("/projects/#{url_encode project}/pipeline_schedules", query: options) + post("/projects/#{url_encode project}/pipeline_schedules", body: options) end # Updates the pipeline schedule of a project. @@ -62,7 +62,7 @@ def create_pipeline_schedule(project, options = {}) # @option options [Boolean] :active The activation of pipeline schedule. If false is set, the pipeline schedule will deactivated initially (default: true). # @return [Array] The updated pipeline schedule. def edit_pipeline_schedule(project, pipeline_schedule_id, options = {}) - put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}", query: options) + put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}", body: options) end # Take ownership of a pipeline schedule. @@ -101,7 +101,7 @@ def delete_pipeline_schedule(project, pipeline_schedule_id) # @option options [String] :value The value of a variable # @return [Array] The created pipeline schedule variable. def create_pipeline_schedule_variable(project, pipeline_schedule_id, options = {}) - post("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables", query: options) + post("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables", body: options) end # Updates the variable of a pipeline schedule. @@ -116,7 +116,7 @@ def create_pipeline_schedule_variable(project, pipeline_schedule_id, options = { # @option options [String] :value The value of a variable. # @return [Array] The updated pipeline schedule variable. def edit_pipeline_schedule_variable(project, pipeline_schedule_id, key, options = {}) - put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables/#{url_encode key}", query: options) + put("/projects/#{url_encode project}/pipeline_schedules/#{pipeline_schedule_id}/variables/#{url_encode key}", body: options) end # Delete the variable of a pipeline schedule diff --git a/lib/gitlab/file_response.rb b/lib/gitlab/file_response.rb index eecd3fef8..48a11deb1 100644 --- a/lib/gitlab/file_response.rb +++ b/lib/gitlab/file_response.rb @@ -35,9 +35,11 @@ def method_missing(name, *args, &block) end end + # rubocop:disable Style/OptionalBooleanParameter def respond_to_missing?(method_name, include_private = false) super || @file.respond_to?(method_name, include_private) end + # rubocop:enable Style/OptionalBooleanParameter # Parse filename from the 'Content Disposition' header. def parse_headers!(headers) diff --git a/lib/gitlab/objectified_hash.rb b/lib/gitlab/objectified_hash.rb index e2f12c514..56ad85f47 100644 --- a/lib/gitlab/objectified_hash.rb +++ b/lib/gitlab/objectified_hash.rb @@ -44,8 +44,10 @@ def method_missing(method_name, *args, &block) end end + # rubocop:disable Style/OptionalBooleanParameter def respond_to_missing?(method_name, include_private = false) hash.keys.map(&:to_sym).include?(method_name.to_sym) || super end + # rubocop:enable Style/OptionalBooleanParameter end end diff --git a/lib/gitlab/paginated_response.rb b/lib/gitlab/paginated_response.rb index 07b7e91f9..519a757fe 100644 --- a/lib/gitlab/paginated_response.rb +++ b/lib/gitlab/paginated_response.rb @@ -25,9 +25,11 @@ def method_missing(name, *args, &block) end end + # rubocop:disable Style/OptionalBooleanParameter def respond_to_missing?(method_name, include_private = false) super || @array.respond_to?(method_name, include_private) end + # rubocop:enable Style/OptionalBooleanParameter def parse_headers!(headers) @links = PageLinks.new headers diff --git a/lib/gitlab/shell_history.rb b/lib/gitlab/shell_history.rb index 55a404f1b..dc419809b 100644 --- a/lib/gitlab/shell_history.rb +++ b/lib/gitlab/shell_history.rb @@ -42,10 +42,10 @@ def history_file_path File.expand_path(@file_path) end - def read_from_file + def read_from_file(&block) path = history_file_path - File.foreach(path) { |line| yield(line) } if File.exist?(path) + File.foreach(path, &block) if File.exist?(path) rescue StandardError => e warn "History file not loaded: #{e.message}" end diff --git a/spec/gitlab/client/commits_spec.rb b/spec/gitlab/client/commits_spec.rb index d59b60540..f261c7478 100644 --- a/spec/gitlab/client/commits_spec.rb +++ b/spec/gitlab/client/commits_spec.rb @@ -224,13 +224,13 @@ describe '.update_commit_status' do before do stub_post('/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8', 'project_update_commit_status') - .with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' }) + .with(body: { name: 'test', ref: 'decreased-spec', state: 'failed' }) @status = Gitlab.update_commit_status(6, '7d938cb8ac15788d71f4b67c035515a160ea76d8', 'failed', name: 'test', ref: 'decreased-spec') end it 'gets the correct resource' do expect(a_post('/projects/6/statuses/7d938cb8ac15788d71f4b67c035515a160ea76d8') - .with(query: { name: 'test', ref: 'decreased-spec', state: 'failed' })) + .with(body: { name: 'test', ref: 'decreased-spec', state: 'failed' })) end it 'returns information about the newly created status' do diff --git a/spec/gitlab/client/container_registry_spec.rb b/spec/gitlab/client/container_registry_spec.rb index 8ece648cf..eb728037d 100644 --- a/spec/gitlab/client/container_registry_spec.rb +++ b/spec/gitlab/client/container_registry_spec.rb @@ -73,25 +73,25 @@ describe '.bulk_delete_registry_repository_tags' do context 'when just name_regex provided for deletion' do before do - stub_delete('/projects/3/registry/repositories/1/tags', 'empty').with(query: { name_regex: '.*' }) + stub_delete('/projects/3/registry/repositories/1/tags', 'empty').with(body: { name_regex: '.*' }) Gitlab.bulk_delete_registry_repository_tags(3, 1, name_regex: '.*') end it 'gets the correct resource' do expect(a_delete('/projects/3/registry/repositories/1/tags') - .with(query: { name_regex: '.*' })).to have_been_made + .with(body: { name_regex: '.*' })).to have_been_made end end context 'when all options provided for deletion' do before do - stub_delete('/projects/3/registry/repositories/1/tags', 'empty').with(query: { name_regex: '[0-9a-z]{40}', keep_n: 5, older_than: '1d' }) + stub_delete('/projects/3/registry/repositories/1/tags', 'empty').with(body: { name_regex: '[0-9a-z]{40}', keep_n: 5, older_than: '1d' }) Gitlab.bulk_delete_registry_repository_tags(3, 1, name_regex: '[0-9a-z]{40}', keep_n: 5, older_than: '1d') end it 'gets the correct resource' do expect(a_delete('/projects/3/registry/repositories/1/tags') - .with(query: { name_regex: '[0-9a-z]{40}', keep_n: 5, older_than: '1d' })).to have_been_made + .with(body: { name_regex: '[0-9a-z]{40}', keep_n: 5, older_than: '1d' })).to have_been_made end end end diff --git a/spec/gitlab/client/group_labels_spec.rb b/spec/gitlab/client/group_labels_spec.rb index e8d443642..36350d6da 100644 --- a/spec/gitlab/client/group_labels_spec.rb +++ b/spec/gitlab/client/group_labels_spec.rb @@ -54,13 +54,12 @@ describe '.delete_group_label' do before do - stub_delete('/groups/3/labels', 'label') + stub_delete('/groups/3/labels/Backlog', 'label') @label = Gitlab.delete_group_label(3, 'Backlog') end it 'gets the correct resource' do - expect(a_delete('/groups/3/labels') - .with(body: { name: 'Backlog' })).to have_been_made + expect(a_delete('/groups/3/labels/Backlog')).to have_been_made end it 'returns information about a deleted snippet' do diff --git a/spec/gitlab/client/labels_spec.rb b/spec/gitlab/client/labels_spec.rb index 52651a743..e093ee56f 100644 --- a/spec/gitlab/client/labels_spec.rb +++ b/spec/gitlab/client/labels_spec.rb @@ -21,13 +21,12 @@ describe '.delete' do before do - stub_delete('/projects/3/labels', 'label') + stub_delete('/projects/3/labels/Backlog', 'label') @label = Gitlab.delete_label(3, 'Backlog') end it 'gets the correct resource' do - expect(a_delete('/projects/3/labels') - .with(body: { name: 'Backlog' })).to have_been_made + expect(a_delete('/projects/3/labels/Backlog')).to have_been_made end it 'returns information about a deleted snippet' do diff --git a/spec/gitlab/client/pipeline_schedules_spec.rb b/spec/gitlab/client/pipeline_schedules_spec.rb index 9117b3ddd..bb04f976f 100644 --- a/spec/gitlab/client/pipeline_schedules_spec.rb +++ b/spec/gitlab/client/pipeline_schedules_spec.rb @@ -108,14 +108,16 @@ describe '.create_pipeline_schedule_variable' do before do - stub_post('/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value', 'pipeline_schedule_variable') + stub_post('/projects/3/pipeline_schedules/13/variables', 'pipeline_schedule_variable') + .with(body: { key: 'NEW VARIABLE', value: 'new value' }) @pipeline_schedule_variable = Gitlab.create_pipeline_schedule_variable(3, 13, key: 'NEW VARIABLE', value: 'new value') end it 'gets the correct resource' do - expect(a_post('/projects/3/pipeline_schedules/13/variables?key=NEW%20VARIABLE&value=new%20value')).to have_been_made + expect(a_post('/projects/3/pipeline_schedules/13/variables') + .with(body: { key: 'NEW VARIABLE', value: 'new value' })).to have_been_made end it 'returns a single variable' do @@ -129,7 +131,8 @@ describe '.edit_pipeline_schedule_variable' do before do - stub_put('/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE?value=update%20value', 'pipeline_schedule_variable_update') + stub_put('/projects/3/pipeline_schedules/13/variables/NEW%20VARIABLE', 'pipeline_schedule_variable_update') + .with(body: { value: 'update value' }) @pipeline_schedule_variable = Gitlab.edit_pipeline_schedule_variable(3, 13, 'NEW VARIABLE', value: 'update value') end