+
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions lib/gitlab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/gitlab/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -18,5 +19,6 @@ def initialize(options = {})
request_defaults(sudo)
self.class.headers 'User-Agent' => user_agent
end
# rubocop:enable Lint/MissingSuper
end
end
4 changes: 2 additions & 2 deletions lib/gitlab/cli_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/gitlab/client/commits.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/gitlab/client/container_registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/gitlab/client/group_labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/gitlab/client/labels.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/gitlab/client/pipeline_schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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<Gitlab::ObjectifiedHash>]
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.
Expand All @@ -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<Gitlab::ObjectifiedHash>] 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.
Expand Down Expand Up @@ -101,7 +101,7 @@ def delete_pipeline_schedule(project, pipeline_schedule_id)
# @option options [String] :value The value of a variable
# @return [Array<Gitlab::ObjectifiedHash>] 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.
Expand All @@ -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<Gitlab::ObjectifiedHash>] 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
Expand Down
2 changes: 2 additions & 0 deletions lib/gitlab/file_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/gitlab/objectified_hash.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions lib/gitlab/paginated_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/gitlab/shell_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/gitlab/client/commits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions spec/gitlab/client/container_registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions spec/gitlab/client/group_labels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions spec/gitlab/client/labels_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions spec/gitlab/client/pipeline_schedules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载