summaryrefslogtreecommitdiff
path: root/lib/api/helpers
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/helpers')
-rw-r--r--lib/api/helpers/badges_helpers.rb10
-rw-r--r--lib/api/helpers/custom_attributes.rb4
-rw-r--r--lib/api/helpers/custom_validators.rb2
-rw-r--r--lib/api/helpers/headers_helpers.rb2
-rw-r--r--lib/api/helpers/internal_helpers.rb8
-rw-r--r--lib/api/helpers/label_helpers.rb8
-rw-r--r--lib/api/helpers/members_helpers.rb6
-rw-r--r--lib/api/helpers/notes_helpers.rb2
-rw-r--r--lib/api/helpers/pagination.rb62
-rw-r--r--lib/api/helpers/projects_helpers.rb40
-rw-r--r--lib/api/helpers/related_resources_helpers.rb2
-rw-r--r--lib/api/helpers/runner.rb16
-rw-r--r--lib/api/helpers/version.rb4
13 files changed, 83 insertions, 83 deletions
diff --git a/lib/api/helpers/badges_helpers.rb b/lib/api/helpers/badges_helpers.rb
index 46ce5b4e7b5..2f63a6ac37e 100644
--- a/lib/api/helpers/badges_helpers.rb
+++ b/lib/api/helpers/badges_helpers.rb
@@ -18,12 +18,12 @@ module API
def badge_source_params(source)
project = if source.is_a?(Project)
- source
- else
- GroupProjectsFinder.new(group: source, current_user: current_user).execute.first
- end
+ source
+ else
+ GroupProjectsFinder.new(group: source, current_user: current_user).execute.first
+ end
- { project: project }
+ {project: project}
end
end
end
diff --git a/lib/api/helpers/custom_attributes.rb b/lib/api/helpers/custom_attributes.rb
index 88208226c40..7e5775f115c 100644
--- a/lib/api/helpers/custom_attributes.rb
+++ b/lib/api/helpers/custom_attributes.rb
@@ -8,10 +8,10 @@ module API
included do
helpers do
params :with_custom_attributes do
- optional :with_custom_attributes, type: Boolean, default: false, desc: 'Include custom attributes in the response'
+ optional :with_custom_attributes, type: Boolean, default: false, desc: "Include custom attributes in the response"
optional :custom_attributes, type: Hash,
- desc: 'Filter with custom attributes'
+ desc: "Filter with custom attributes"
end
# rubocop: disable CodeReuse/ActiveRecord
diff --git a/lib/api/helpers/custom_validators.rb b/lib/api/helpers/custom_validators.rb
index 1058f4e8a5e..6c62501cbc9 100644
--- a/lib/api/helpers/custom_validators.rb
+++ b/lib/api/helpers/custom_validators.rb
@@ -16,7 +16,7 @@ module API
value = params[attr_name]
return if value.is_a?(Integer) ||
- [IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value.to_s.downcase)
+ [IssuableFinder::FILTER_NONE, IssuableFinder::FILTER_ANY].include?(value.to_s.downcase)
raise Grape::Exceptions::Validation, params: [@scope.full_name(attr_name)],
message: "should be an integer, 'None' or 'Any'"
diff --git a/lib/api/helpers/headers_helpers.rb b/lib/api/helpers/headers_helpers.rb
index 7553af9d156..3af44a230b3 100644
--- a/lib/api/helpers/headers_helpers.rb
+++ b/lib/api/helpers/headers_helpers.rb
@@ -9,7 +9,7 @@ module API
raise ArgumentError.new("Header value should be a string")
end
- header "X-Gitlab-#{key.to_s.split('_').collect(&:capitalize).join('-')}", value.to_s
+ header "X-Gitlab-#{key.to_s.split("_").collect(&:capitalize).join("-")}", value.to_s
end
end
end
diff --git a/lib/api/helpers/internal_helpers.rb b/lib/api/helpers/internal_helpers.rb
index fe78049af87..1e5e22417c9 100644
--- a/lib/api/helpers/internal_helpers.rb
+++ b/lib/api/helpers/internal_helpers.rb
@@ -19,7 +19,7 @@ module API
[
:read_project,
:download_code,
- :push_code
+ :push_code,
]
end
@@ -34,7 +34,7 @@ module API
def log_user_activity(actor)
commands = Gitlab::GitAccess::DOWNLOAD_COMMANDS
- ::Users::ActivityService.new(actor, 'Git SSH').execute if commands.include?(params[:action])
+ ::Users::ActivityService.new(actor, "Git SSH").execute if commands.include?(params[:action])
end
def merge_request_urls
@@ -44,7 +44,7 @@ module API
def redis_ping
result = Gitlab::Redis::SharedState.with { |redis| redis.ping }
- result == 'PONG'
+ result == "PONG"
rescue => e
Rails.logger.warn("GitLab: An unexpected error occurred in pinging to Redis: #{e}")
false
@@ -106,7 +106,7 @@ module API
{
repository: repository.gitaly_repository,
address: Gitlab::GitalyClient.address(project.repository_storage),
- token: Gitlab::GitalyClient.token(project.repository_storage)
+ token: Gitlab::GitalyClient.token(project.repository_storage),
}
end
end
diff --git a/lib/api/helpers/label_helpers.rb b/lib/api/helpers/label_helpers.rb
index c11e7d614ab..69cdc25aa00 100644
--- a/lib/api/helpers/label_helpers.rb
+++ b/lib/api/helpers/label_helpers.rb
@@ -6,16 +6,16 @@ module API
extend Grape::API::Helpers
params :label_create_params do
- requires :name, type: String, desc: 'The name of the label to be created'
+ requires :name, type: String, desc: "The name of the label to be created"
requires :color, type: String, desc: "The color of the label given in 6-digit hex notation with leading '#' sign (e.g. #FFAABB) or one of the allowed CSS color names"
- optional :description, type: String, desc: 'The description of label to be created'
+ optional :description, type: String, desc: "The description of label to be created"
end
def find_label(parent, id, include_ancestor_groups: true)
labels = available_labels_for(parent, include_ancestor_groups: include_ancestor_groups)
label = labels.find_by_id(id) || labels.find_by_title(id)
- label || not_found!('Label')
+ label || not_found!("Label")
end
def get_labels(parent, entity)
@@ -26,7 +26,7 @@ module API
authorize! :admin_label, parent
label = available_labels_for(parent).find_by_title(params[:name])
- conflict!('Label already exists') if label
+ conflict!("Label already exists") if label
priority = params.delete(:priority)
label_params = declared_params(include_missing: false)
diff --git a/lib/api/helpers/members_helpers.rb b/lib/api/helpers/members_helpers.rb
index 73d58ee7f37..93b14278fb4 100644
--- a/lib/api/helpers/members_helpers.rb
+++ b/lib/api/helpers/members_helpers.rb
@@ -14,7 +14,7 @@ module API
end
def find_all_members(source_type, source)
- members = source_type == 'project' ? find_all_members_for_project(source) : find_all_members_for_group(source)
+ members = source_type == "project" ? find_all_members_for_project(source) : find_all_members_for_group(source)
members.non_invite
.non_request
end
@@ -28,7 +28,7 @@ module API
.compact
Member.includes(:user)
.joins(user: :project_authorizations)
- .where(project_authorizations: { project_id: project.id })
+ .where(project_authorizations: {project_id: project.id})
.where(source_id: source_ids)
end
# rubocop: enable CodeReuse/ActiveRecord
@@ -38,7 +38,7 @@ module API
source_ids = group.self_and_ancestors.pluck(:id)
Member.includes(:user)
.where(source_id: source_ids)
- .where(source_type: 'Namespace')
+ .where(source_type: "Namespace")
end
# rubocop: enable CodeReuse/ActiveRecord
end
diff --git a/lib/api/helpers/notes_helpers.rb b/lib/api/helpers/notes_helpers.rb
index 216b2c45741..0d8aeb30d6a 100644
--- a/lib/api/helpers/notes_helpers.rb
+++ b/lib/api/helpers/notes_helpers.rb
@@ -9,7 +9,7 @@ module API
authorize! :admin_note, note
opts = {
- note: params[:body]
+ note: params[:body],
}
parent = noteable_parent(noteable)
project = parent if parent.is_a?(Project)
diff --git a/lib/api/helpers/pagination.rb b/lib/api/helpers/pagination.rb
index d00e61678b5..a125020d6eb 100644
--- a/lib/api/helpers/pagination.rb
+++ b/lib/api/helpers/pagination.rb
@@ -4,11 +4,11 @@ module API
module Helpers
module Pagination
def paginate(relation)
- strategy = if params[:pagination] == 'keyset' && Feature.enabled?('api_keyset_pagination')
- KeysetPaginationStrategy
- else
- DefaultPaginationStrategy
- end
+ strategy = if params[:pagination] == "keyset" && Feature.enabled?("api_keyset_pagination")
+ KeysetPaginationStrategy
+ else
+ DefaultPaginationStrategy
+ end
strategy.new(self).paginate(relation)
end
@@ -66,12 +66,12 @@ module API
# Sort direction (`:asc` or `:desc`)
def sort
@sort ||= if order_by_primary_key?
- # Default order is by id DESC
- :desc
- else
- # API defaults to DESC order if param `sort` not present
- request_context.params[:sort]&.to_sym || :desc
- end
+ # Default order is by id DESC
+ :desc
+ else
+ # API defaults to DESC order if param `sort` not present
+ request_context.params[:sort]&.to_sym || :desc
+ end
end
# Do we only sort by primary key?
@@ -100,9 +100,9 @@ module API
# All values present in request parameters that correspond to #keys.
def values
- @values ||= keys.map do |key|
+ @values ||= keys.map { |key|
request_context.params["ks_prev_#{key}".to_sym]
- end
+ }
end
# All keys relevant to pagination.
@@ -151,30 +151,30 @@ module API
return nil if fields.empty?
- placeholder = fields.map { '?' }
+ placeholder = fields.map { "?" }
comp = if pagination.sort_ascending?
- '>'
- else
- '<'
- end
+ ">"
+ else
+ "<"
+ end
[
# Row value comparison:
# (A, B) < (a, b) <=> (A < a) OR (A = a AND B < b)
# <=> A <= a AND ((A < a) OR (A = a AND B < b))
- "(#{fields.keys.join(',')}) #{comp} (#{placeholder.join(',')})",
- *fields.values
+ "(#{fields.keys.join(",")}) #{comp} (#{placeholder.join(",")})",
+ *fields.values,
]
end
def add_default_pagination_headers
- header 'X-Per-Page', per_page.to_s
+ header "X-Per-Page", per_page.to_s
end
def add_navigation_links(next_page_params)
- header 'X-Next-Page', page_href(next_page_params)
- header 'Link', link_for('next', next_page_params)
+ header "X-Next-Page", page_href(next_page_params)
+ header "Link", link_for("next", next_page_params)
end
def link_for(rel, next_page_params)
@@ -220,16 +220,16 @@ module API
end
def add_pagination_headers(paginated_data)
- header 'X-Per-Page', paginated_data.limit_value.to_s
- header 'X-Page', paginated_data.current_page.to_s
- header 'X-Next-Page', paginated_data.next_page.to_s
- header 'X-Prev-Page', paginated_data.prev_page.to_s
- header 'Link', pagination_links(paginated_data)
+ header "X-Per-Page", paginated_data.limit_value.to_s
+ header "X-Page", paginated_data.current_page.to_s
+ header "X-Next-Page", paginated_data.next_page.to_s
+ header "X-Prev-Page", paginated_data.prev_page.to_s
+ header "Link", pagination_links(paginated_data)
return if data_without_counts?(paginated_data)
- header 'X-Total', paginated_data.total_count.to_s
- header 'X-Total-Pages', total_pages(paginated_data).to_s
+ header "X-Total", paginated_data.total_count.to_s
+ header "X-Total-Pages", total_pages(paginated_data).to_s
end
def pagination_links(paginated_data)
@@ -239,7 +239,7 @@ module API
links << %(<#{page_href(page: 1)}>; rel="first")
links << %(<#{page_href(page: total_pages(paginated_data))}>; rel="last") unless data_without_counts?(paginated_data)
- end.join(', ')
+ end.join(", ")
end
def total_pages(paginated_data)
diff --git a/lib/api/helpers/projects_helpers.rb b/lib/api/helpers/projects_helpers.rb
index e6a72b949f9..07eb7f4a5d7 100644
--- a/lib/api/helpers/projects_helpers.rb
+++ b/lib/api/helpers/projects_helpers.rb
@@ -8,26 +8,26 @@ module API
included do
helpers do
params :optional_project_params_ce do
- optional :description, type: String, desc: 'The description of the project'
- optional :ci_config_path, type: String, desc: 'The path to CI config file. Defaults to `.gitlab-ci.yml`'
- optional :issues_enabled, type: Boolean, desc: 'Flag indication if the issue tracker is enabled'
- optional :merge_requests_enabled, type: Boolean, desc: 'Flag indication if merge requests are enabled'
- optional :wiki_enabled, type: Boolean, desc: 'Flag indication if the wiki is enabled'
- optional :jobs_enabled, type: Boolean, desc: 'Flag indication if jobs are enabled'
- optional :snippets_enabled, type: Boolean, desc: 'Flag indication if snippets are enabled'
- optional :shared_runners_enabled, type: Boolean, desc: 'Flag indication if shared runners are enabled for that project'
- optional :resolve_outdated_diff_discussions, type: Boolean, desc: 'Automatically resolve merge request diffs discussions on lines changed with a push'
- optional :container_registry_enabled, type: Boolean, desc: 'Flag indication if the container registry is enabled for that project'
- optional :lfs_enabled, type: Boolean, desc: 'Flag indication if Git LFS is enabled for that project'
- optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: 'The visibility of the project.'
- optional :public_builds, type: Boolean, desc: 'Perform public builds'
- optional :request_access_enabled, type: Boolean, desc: 'Allow users to request member access'
- optional :only_allow_merge_if_pipeline_succeeds, type: Boolean, desc: 'Only allow to merge if builds succeed'
- optional :only_allow_merge_if_all_discussions_are_resolved, type: Boolean, desc: 'Only allow to merge if all discussions are resolved'
- optional :tag_list, type: Array[String], desc: 'The list of tags for a project'
- optional :avatar, type: File, desc: 'Avatar image for project'
- optional :printing_merge_request_link_enabled, type: Boolean, desc: 'Show link to create/view merge request when pushing from the command line'
- optional :merge_method, type: String, values: %w(ff rebase_merge merge), desc: 'The merge method used when merging merge requests'
+ optional :description, type: String, desc: "The description of the project"
+ optional :ci_config_path, type: String, desc: "The path to CI config file. Defaults to `.gitlab-ci.yml`"
+ optional :issues_enabled, type: Boolean, desc: "Flag indication if the issue tracker is enabled"
+ optional :merge_requests_enabled, type: Boolean, desc: "Flag indication if merge requests are enabled"
+ optional :wiki_enabled, type: Boolean, desc: "Flag indication if the wiki is enabled"
+ optional :jobs_enabled, type: Boolean, desc: "Flag indication if jobs are enabled"
+ optional :snippets_enabled, type: Boolean, desc: "Flag indication if snippets are enabled"
+ optional :shared_runners_enabled, type: Boolean, desc: "Flag indication if shared runners are enabled for that project"
+ optional :resolve_outdated_diff_discussions, type: Boolean, desc: "Automatically resolve merge request diffs discussions on lines changed with a push"
+ optional :container_registry_enabled, type: Boolean, desc: "Flag indication if the container registry is enabled for that project"
+ optional :lfs_enabled, type: Boolean, desc: "Flag indication if Git LFS is enabled for that project"
+ optional :visibility, type: String, values: Gitlab::VisibilityLevel.string_values, desc: "The visibility of the project."
+ optional :public_builds, type: Boolean, desc: "Perform public builds"
+ optional :request_access_enabled, type: Boolean, desc: "Allow users to request member access"
+ optional :only_allow_merge_if_pipeline_succeeds, type: Boolean, desc: "Only allow to merge if builds succeed"
+ optional :only_allow_merge_if_all_discussions_are_resolved, type: Boolean, desc: "Only allow to merge if all discussions are resolved"
+ optional :tag_list, type: Array[String], desc: "The list of tags for a project"
+ optional :avatar, type: File, desc: "Avatar image for project"
+ optional :printing_merge_request_link_enabled, type: Boolean, desc: "Show link to create/view merge request when pushing from the command line"
+ optional :merge_method, type: String, values: %w[ff rebase_merge merge], desc: "The merge method used when merging merge requests"
optional :initialize_with_readme, type: Boolean, desc: "Initialize a project with a README.md"
end
diff --git a/lib/api/helpers/related_resources_helpers.rb b/lib/api/helpers/related_resources_helpers.rb
index 793ae11b41d..7c4934da73b 100644
--- a/lib/api/helpers/related_resources_helpers.rb
+++ b/lib/api/helpers/related_resources_helpers.rb
@@ -20,7 +20,7 @@ module API
# Using a blank component at the beginning of the join we ensure
# that the resulted path will start with '/'. If the resulted path
# does not start with '/', URI::Generic#build will fail
- path_with_script_name = File.join('', [script_name, path].select(&:present?))
+ path_with_script_name = File.join("", [script_name, path].select(&:present?))
URI::Generic.build(scheme: protocol, host: host, port: port, path: path_with_script_name).to_s
end
diff --git a/lib/api/helpers/runner.rb b/lib/api/helpers/runner.rb
index ff73a49d5e8..4afa8183d89 100644
--- a/lib/api/helpers/runner.rb
+++ b/lib/api/helpers/runner.rb
@@ -3,12 +3,12 @@
module API
module Helpers
module Runner
- JOB_TOKEN_HEADER = 'HTTP_JOB_TOKEN'.freeze
+ JOB_TOKEN_HEADER = "HTTP_JOB_TOKEN"
JOB_TOKEN_PARAM = :token
def runner_registration_token_valid?
ActiveSupport::SecurityUtils.variable_size_secure_compare(params[:token],
- Gitlab::CurrentSettings.runners_registration_token)
+ Gitlab::CurrentSettings.runners_registration_token)
end
def authenticate_runner!
@@ -19,14 +19,14 @@ module API
end
def get_runner_details_from_request
- return get_runner_ip unless params['info'].present?
+ return get_runner_ip unless params["info"].present?
- attributes_for_keys(%w(name version revision platform architecture), params['info'])
+ attributes_for_keys(%w[name version revision platform architecture], params["info"])
.merge(get_runner_ip)
end
def get_runner_ip
- { ip_address: env["action_dispatch.remote_ip"].to_s || request.ip }
+ {ip_address: env["action_dispatch.remote_ip"].to_s || request.ip}
end
def current_runner
@@ -39,8 +39,8 @@ module API
yield if block_given?
project = job.project
- forbidden!('Project has been deleted!') if project.nil? || project.pending_delete?
- forbidden!('Job has been erased!') if job.erased?
+ forbidden!("Project has been deleted!") if project.nil? || project.pending_delete?
+ forbidden!("Job has been erased!") if job.erased?
end
def authenticate_job!
@@ -63,7 +63,7 @@ module API
end
def job_forbidden!(job, reason)
- header 'Job-Status', job.status
+ header "Job-Status", job.status
forbidden!(reason)
end
end
diff --git a/lib/api/helpers/version.rb b/lib/api/helpers/version.rb
index 7f53094e90c..2a80d5e71f5 100644
--- a/lib/api/helpers/version.rb
+++ b/lib/api/helpers/version.rb
@@ -9,12 +9,12 @@ module API
@version = version.to_s
unless API.versions.include?(version)
- raise ArgumentError, 'Unknown API version!'
+ raise ArgumentError, "Unknown API version!"
end
end
def root_path
- File.join('/', API.prefix.to_s, @version)
+ File.join("/", API.prefix.to_s, @version)
end
def root_url