GitLab steht aufgrund wichtiger Wartungsarbeiten am Montag, den 8. März, zwischen 17:00 und 19:00 Uhr nicht zur Verfügung.

Commit 181cd299 authored by Jacopo's avatar Jacopo

Adds Rubocop rule for line break after guard clause

Adds a rubocop rule (with autocorrect) to ensure line break after guard clauses.
parent f2997af4
...@@ -97,6 +97,7 @@ def append_info_to_payload(payload) ...@@ -97,6 +97,7 @@ def append_info_to_payload(payload)
# (e.g. tokens) to authenticate the user, whereas Devise sets current_user # (e.g. tokens) to authenticate the user, whereas Devise sets current_user
def auth_user def auth_user
return current_user if current_user.present? return current_user if current_user.present?
return try(:authenticated_user) return try(:authenticated_user)
end end
......
...@@ -44,6 +44,7 @@ def load_group ...@@ -44,6 +44,7 @@ def load_group
if @project.blank? && params[:group_id].present? if @project.blank? && params[:group_id].present?
group = Group.find(params[:group_id]) group = Group.find(params[:group_id])
return render_404 unless can?(current_user, :read_group, group) return render_404 unless can?(current_user, :read_group, group)
group group
end end
end end
...@@ -54,6 +55,7 @@ def load_project ...@@ -54,6 +55,7 @@ def load_project
if params[:project_id].present? if params[:project_id].present?
project = Project.find(params[:project_id]) project = Project.find(params[:project_id])
return render_404 unless can?(current_user, :read_project, project) return render_404 unless can?(current_user, :read_project, project)
project project
end end
end end
......
...@@ -4,6 +4,7 @@ class Import::GitlabProjectsController < Import::BaseController ...@@ -4,6 +4,7 @@ class Import::GitlabProjectsController < Import::BaseController
def new def new
@namespace = Namespace.find(project_params[:namespace_id]) @namespace = Namespace.find(project_params[:namespace_id])
return render_404 unless current_user.can?(:create_projects, @namespace) return render_404 unless current_user.can?(:create_projects, @namespace)
@path = project_params[:path] @path = project_params[:path]
end end
......
...@@ -12,6 +12,7 @@ def index ...@@ -12,6 +12,7 @@ def index
def metrics def metrics
return render_404 unless deployment.has_metrics? return render_404 unless deployment.has_metrics?
@metrics = deployment.metrics @metrics = deployment.metrics
if @metrics&.any? if @metrics&.any?
render json: @metrics, status: :ok render json: @metrics, status: :ok
......
...@@ -12,6 +12,7 @@ def create ...@@ -12,6 +12,7 @@ def create
if group if group
return render_404 unless can?(current_user, :read_group, group) return render_404 unless can?(current_user, :read_group, group)
Projects::GroupLinks::CreateService.new(project, current_user, group_link_create_params).execute(group) Projects::GroupLinks::CreateService.new(project, current_user, group_link_create_params).execute(group)
else else
flash[:alert] = 'Please select a group.' flash[:alert] = 'Please select a group.'
......
...@@ -171,6 +171,7 @@ def create_merge_request ...@@ -171,6 +171,7 @@ def create_merge_request
def issue def issue
return @issue if defined?(@issue) return @issue if defined?(@issue)
# The Sortable default scope causes performance issues when used with find_by # The Sortable default scope causes performance issues when used with find_by
@issuable = @noteable = @issue ||= @project.issues.where(iid: params[:id]).reorder(nil).take! @issuable = @noteable = @issue ||= @project.issues.where(iid: params[:id]).reorder(nil).take!
@note = @project.notes.new(noteable: @issuable) @note = @project.notes.new(noteable: @issuable)
......
...@@ -111,6 +111,7 @@ def promote ...@@ -111,6 +111,7 @@ def promote
begin begin
return render_404 unless promote_service.execute(@label) return render_404 unless promote_service.execute(@label)
respond_to do |format| respond_to do |format|
format.html do format.html do
redirect_to(project_labels_path(@project), redirect_to(project_labels_path(@project),
......
...@@ -54,6 +54,7 @@ def tmp_filename ...@@ -54,6 +54,7 @@ def tmp_filename
name = request.headers['X-Gitlab-Lfs-Tmp'] name = request.headers['X-Gitlab-Lfs-Tmp']
return if name.include?('/') return if name.include?('/')
return unless oid.present? && name.start_with?(oid) return unless oid.present? && name.start_with?(oid)
name name
end end
......
...@@ -76,6 +76,7 @@ def authorize_resolve_note! ...@@ -76,6 +76,7 @@ def authorize_resolve_note!
def authorize_create_note! def authorize_create_note!
return unless noteable.lockable? return unless noteable.lockable?
access_denied! unless can?(current_user, :create_note, noteable) access_denied! unless can?(current_user, :create_note, noteable)
end end
end end
...@@ -28,6 +28,7 @@ def show ...@@ -28,6 +28,7 @@ def show
) )
else else
return render('empty') unless can?(current_user, :create_wiki, @project) return render('empty') unless can?(current_user, :create_wiki, @project)
@page = WikiPage.new(@project_wiki) @page = WikiPage.new(@project_wiki)
@page.title = params[:id] @page.title = params[:id]
......
...@@ -269,6 +269,7 @@ def refs ...@@ -269,6 +269,7 @@ def refs
def render_landing_page def render_landing_page
if can?(current_user, :download_code, @project) if can?(current_user, :download_code, @project)
return render 'projects/no_repo' unless @project.repository_exists? return render 'projects/no_repo' unless @project.repository_exists?
render 'projects/empty' if @project.empty_repo? render 'projects/empty' if @project.empty_repo?
else else
if @project.wiki_enabled? if @project.wiki_enabled?
......
...@@ -18,6 +18,7 @@ def execute ...@@ -18,6 +18,7 @@ def execute
def by_user(tokens) def by_user(tokens)
return tokens unless @params[:user] return tokens unless @params[:user]
tokens.where(user: @params[:user]) tokens.where(user: @params[:user])
end end
......
...@@ -111,6 +111,7 @@ def diff_file_blob_raw_path(diff_file) ...@@ -111,6 +111,7 @@ def diff_file_blob_raw_path(diff_file)
def diff_file_old_blob_raw_path(diff_file) def diff_file_old_blob_raw_path(diff_file)
sha = diff_file.old_content_sha sha = diff_file.old_content_sha
return unless sha return unless sha
project_raw_path(@project, tree_join(diff_file.old_content_sha, diff_file.old_path)) project_raw_path(@project, tree_join(diff_file.old_content_sha, diff_file.old_path))
end end
......
...@@ -24,6 +24,7 @@ def email_action(url) ...@@ -24,6 +24,7 @@ def email_action(url)
def action_title(url) def action_title(url)
return unless url return unless url
%w(merge_requests issues commit).each do |action| %w(merge_requests issues commit).each do |action|
if url.split("/").include?(action) if url.split("/").include?(action)
return "View #{action.humanize.singularize}" return "View #{action.humanize.singularize}"
......
...@@ -53,6 +53,7 @@ def link_to_html(redacted, url, html_options = {}) ...@@ -53,6 +53,7 @@ def link_to_html(redacted, url, html_options = {})
# text, wrapping anything found in the requested link # text, wrapping anything found in the requested link
fragment.children.each do |node| fragment.children.each do |node|
next unless node.text? next unless node.text?
node.replace(link_to(node.text, url, html_options)) node.replace(link_to(node.text, url, html_options))
end end
end end
......
...@@ -78,6 +78,7 @@ def notifications_menu_identifier(type, notification_setting) ...@@ -78,6 +78,7 @@ def notifications_menu_identifier(type, notification_setting)
# Create hidden field to send notification setting source to controller # Create hidden field to send notification setting source to controller
def hidden_setting_source_input(notification_setting) def hidden_setting_source_input(notification_setting)
return unless notification_setting.source_type return unless notification_setting.source_type
hidden_field_tag "#{notification_setting.source_type.downcase}_id", notification_setting.source_id hidden_field_tag "#{notification_setting.source_type.downcase}_id", notification_setting.source_id
end end
......
...@@ -88,6 +88,7 @@ def path_breadcrumbs(max_links = 6) ...@@ -88,6 +88,7 @@ def path_breadcrumbs(max_links = 6)
part_path = part if part_path.empty? part_path = part if part_path.empty?
next if parts.count > max_links && !parts.last(2).include?(part) next if parts.count > max_links && !parts.last(2).include?(part)
yield(part, part_path) yield(part, part_path)
end end
end end
......
...@@ -150,6 +150,7 @@ def visibility_level_label(level) ...@@ -150,6 +150,7 @@ def visibility_level_label(level)
def restricted_visibility_levels(show_all = false) def restricted_visibility_levels(show_all = false)
return [] if current_user.admin? && !show_all return [] if current_user.admin? && !show_all
current_application_settings.restricted_visibility_levels || [] current_application_settings.restricted_visibility_levels || []
end end
...@@ -159,6 +160,7 @@ def restricted_visibility_levels(show_all = false) ...@@ -159,6 +160,7 @@ def restricted_visibility_levels(show_all = false)
def disallowed_visibility_level?(form_model, level) def disallowed_visibility_level?(form_model, level)
return false unless form_model.respond_to?(:visibility_level_allowed?) return false unless form_model.respond_to?(:visibility_level_allowed?)
!form_model.visibility_level_allowed?(level) !form_model.visibility_level_allowed?(level)
end end
......
...@@ -317,6 +317,7 @@ def stuck? ...@@ -317,6 +317,7 @@ def stuck?
def execute_hooks def execute_hooks
return unless project return unless project
build_data = Gitlab::DataBuilder::Build.build(self) build_data = Gitlab::DataBuilder::Build.build(self)
project.execute_hooks(build_data.dup, :job_hooks) project.execute_hooks(build_data.dup, :job_hooks)
project.execute_services(build_data.dup, :job_hooks) project.execute_services(build_data.dup, :job_hooks)
......
...@@ -300,8 +300,10 @@ def mark_as_processable_after_stage(stage_idx) ...@@ -300,8 +300,10 @@ def mark_as_processable_after_stage(stage_idx)
def latest? def latest?
return false unless ref return false unless ref
commit = project.commit(ref) commit = project.commit(ref)
return false unless commit return false unless commit
commit.sha == sha commit.sha == sha
end end
......
...@@ -56,6 +56,7 @@ class Gcp < ActiveRecord::Base ...@@ -56,6 +56,7 @@ class Gcp < ActiveRecord::Base
before_transition any => [:creating] do |provider, transition| before_transition any => [:creating] do |provider, transition|
operation_id = transition.args.first operation_id = transition.args.first
raise ArgumentError.new('operation_id is required') unless operation_id.present? raise ArgumentError.new('operation_id is required') unless operation_id.present?
provider.operation_id = operation_id provider.operation_id = operation_id
end end
......
...@@ -98,6 +98,7 @@ def awarded_emoji?(emoji_name, current_user) ...@@ -98,6 +98,7 @@ def awarded_emoji?(emoji_name, current_user)
def create_award_emoji(name, current_user) def create_award_emoji(name, current_user)
return unless emoji_awardable? return unless emoji_awardable?
award_emoji.create(name: normalize_name(name), user: current_user) award_emoji.create(name: normalize_name(name), user: current_user)
end end
......
...@@ -65,6 +65,7 @@ def has_intermediates? ...@@ -65,6 +65,7 @@ def has_intermediates?
def expired? def expired?
return false unless x509 return false unless x509
current = Time.new current = Time.new
current < x509.not_before || x509.not_after < current current < x509.not_before || x509.not_after < current
end end
...@@ -75,6 +76,7 @@ def expiration ...@@ -75,6 +76,7 @@ def expiration
def subject def subject
return unless x509 return unless x509
x509.subject.to_s x509.subject.to_s
end end
...@@ -102,6 +104,7 @@ def validate_intermediates ...@@ -102,6 +104,7 @@ def validate_intermediates
def validate_pages_domain def validate_pages_domain
return unless domain return unless domain
if domain.downcase.ends_with?(Settings.pages.host.downcase) if domain.downcase.ends_with?(Settings.pages.host.downcase)
self.errors.add(:domain, "*.#{Settings.pages.host} is restricted") self.errors.add(:domain, "*.#{Settings.pages.host} is restricted")
end end
...@@ -109,6 +112,7 @@ def validate_pages_domain ...@@ -109,6 +112,7 @@ def validate_pages_domain
def x509 def x509
return unless certificate return unless certificate
@x509 ||= OpenSSL::X509::Certificate.new(certificate) @x509 ||= OpenSSL::X509::Certificate.new(certificate)
rescue OpenSSL::X509::CertificateError rescue OpenSSL::X509::CertificateError
nil nil
...@@ -116,6 +120,7 @@ def x509 ...@@ -116,6 +120,7 @@ def x509
def pkey def pkey
return unless key return unless key
@pkey ||= OpenSSL::PKey::RSA.new(key) @pkey ||= OpenSSL::PKey::RSA.new(key)
rescue OpenSSL::PKey::PKeyError, OpenSSL::Cipher::CipherError rescue OpenSSL::PKey::PKeyError, OpenSSL::Cipher::CipherError
nil nil
......
...@@ -51,8 +51,10 @@ def self.supported_events ...@@ -51,8 +51,10 @@ def self.supported_events
def execute(data) def execute(data)
return unless supported_events.include?(data[:object_kind]) return unless supported_events.include?(data[:object_kind])
message = create_message(data) message = create_message(data)
return unless message.present? return unless message.present?
gate[room].send('GitLab', message, message_options(data)) # rubocop:disable GitlabSecurity/PublicSend gate[room].send('GitLab', message, message_options(data)) # rubocop:disable GitlabSecurity/PublicSend
end end
......
...@@ -176,6 +176,7 @@ def test_data(user = nil, project = nil) ...@@ -176,6 +176,7 @@ def test_data(user = nil, project = nil)
def test_settings def test_settings
return unless client_url.present? return unless client_url.present?
# Test settings by getting the project # Test settings by getting the project
jira_request { client.ServerInfo.all.attrs } jira_request { client.ServerInfo.all.attrs }
end end
......
...@@ -182,6 +182,7 @@ def read_pods ...@@ -182,6 +182,7 @@ def read_pods
kubeclient.get_pods(namespace: actual_namespace).as_json kubeclient.get_pods(namespace: actual_namespace).as_json
rescue KubeException => err rescue KubeException => err
raise err unless err.error_code == 404 raise err unless err.error_code == 404
[] []
end end
......
...@@ -242,6 +242,7 @@ def keep_around(sha) ...@@ -242,6 +242,7 @@ def keep_around(sha)
Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}" Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
rescue Rugged::OSError => ex rescue Rugged::OSError => ex
raise unless ex.message =~ /Failed to create locked file/ && ex.message =~ /File exists/ raise unless ex.message =~ /Failed to create locked file/ && ex.message =~ /File exists/
Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}" Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
end end
end end
...@@ -662,6 +663,7 @@ def last_commit_id_for_path(sha, path) ...@@ -662,6 +663,7 @@ def last_commit_id_for_path(sha, path)
def next_branch(name, opts = {}) def next_branch(name, opts = {})
branch_ids = self.branch_names.map do |n| branch_ids = self.branch_names.map do |n|
next 1 if n == name next 1 if n == name
result = n.match(/\A#{name}-([0-9]+)\z/) result = n.match(/\A#{name}-([0-9]+)\z/)
result[1].to_i if result result[1].to_i if result
end.compact end.compact
......
...@@ -1119,6 +1119,7 @@ def lock_access! ...@@ -1119,6 +1119,7 @@ def lock_access!
# override, from Devise::Validatable # override, from Devise::Validatable
def password_required? def password_required?
return false if internal? return false if internal?
super super
end end
...@@ -1136,6 +1137,7 @@ def ci_projects_union ...@@ -1136,6 +1137,7 @@ def ci_projects_union
# Added according to https://github.com/plataformatec/devise/blob/7df57d5081f9884849ca15e4fde179ef164a575f/README.md#activejob-integration # Added according to https://github.com/plataformatec/devise/blob/7df57d5081f9884849ca15e4fde179ef164a575f/README.md#activejob-integration
def send_devise_notification(notification, *args) def send_devise_notification(notification, *args)
return true unless can?(:receive_notifications) return true unless can?(:receive_notifications)
devise_mailer.__send__(notification, self, *args).deliver_later # rubocop:disable GitlabSecurity/PublicSend devise_mailer.__send__(notification, self, *args).deliver_later # rubocop:disable GitlabSecurity/PublicSend
end end
......
...@@ -34,6 +34,7 @@ def read_secrets ...@@ -34,6 +34,7 @@ def read_secrets
kubeclient.get_secrets.as_json kubeclient.get_secrets.as_json
rescue KubeException => err rescue KubeException => err
raise err unless err.error_code == 404 raise err unless err.error_code == 404
[] []
end end
......
...@@ -19,6 +19,7 @@ def execute(label) ...@@ -19,6 +19,7 @@ def execute(label)
# We skipped validations during creation. Let's run them now, after deleting conflicting labels # We skipped validations during creation. Let's run them now, after deleting conflicting labels
raise ActiveRecord::RecordInvalid.new(new_label) unless new_label.valid? raise ActiveRecord::RecordInvalid.new(new_label) unless new_label.valid?
new_label new_label
end end
end end
......
...@@ -28,6 +28,7 @@ def find_source_project ...@@ -28,6 +28,7 @@ def find_source_project
def find_target_project def find_target_project
return target_project if target_project.present? && can?(current_user, :read_project, target_project) return target_project if target_project.present? && can?(current_user, :read_project, target_project)
project.default_merge_request_target project.default_merge_request_target
end end
......
...@@ -3,6 +3,7 @@ module GroupLinks ...@@ -3,6 +3,7 @@ module GroupLinks
class DestroyService < BaseService class DestroyService < BaseService
def execute(group_link) def execute(group_link)
return false unless group_link return false unless group_link
group_link.destroy group_link.destroy
end end
end end
......
...@@ -208,6 +208,7 @@ def update_todos_state(todos, current_user, state) ...@@ -208,6 +208,7 @@ def update_todos_state(todos, current_user, state)
def create_todos(users, attributes) def create_todos(users, attributes)
Array(users).map do |user| Array(users).map do |user|
next if pending_todos(user, attributes).exists? next if pending_todos(user, attributes).exists?
todo = Todo.create(attributes.merge(user_id: user.id)) todo = Todo.create(attributes.merge(user_id: user.id))
user.update_todos_count_cache user.update_todos_count_cache
todo todo
......
...@@ -17,6 +17,7 @@ def validate_each(record, attribute, value) ...@@ -17,6 +17,7 @@ def validate_each(record, attribute, value)
def valid_private_key_pem?(value) def valid_private_key_pem?(value)
return false unless value return false unless value
pkey = OpenSSL::PKey::RSA.new(value) pkey = OpenSSL::PKey::RSA.new(value)
pkey.private? pkey.private?
rescue OpenSSL::PKey::PKeyError rescue OpenSSL::PKey::PKeyError
......
...@@ -17,6 +17,7 @@ def validate_each(record, attribute, value) ...@@ -17,6 +17,7 @@ def validate_each(record, attribute, value)
def valid_certificate_pem?(value) def valid_certificate_pem?(value)
return false unless value return false unless value