diff options
author | Stan Hu <stanhu@gmail.com> | 2019-03-13 18:03:12 +0000 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2019-03-13 18:03:12 +0000 |
commit | c048422fa23b988ecdb87858cd58766870347bbe (patch) | |
tree | c07a1507ff5192f911704fcc77026d7f4043dd0e /app | |
parent | 42b7f53bb8c456e2a88f6abff1ea8fc5dc5c4b2e (diff) | |
parent | 9f05e97aad33a0cd70862f67101bdcb3fddc639a (diff) | |
download | gitlab-ce-c048422fa23b988ecdb87858cd58766870347bbe.tar.gz |
Merge branch 'update-rubocop' into 'master'
Update rubocop target ruby version
See merge request gitlab-org/gitlab-ce!24804
Diffstat (limited to 'app')
-rw-r--r-- | app/models/merge_request_diff.rb | 10 | ||||
-rw-r--r-- | app/models/merge_request_diff_file.rb | 2 | ||||
-rw-r--r-- | app/models/project.rb | 8 | ||||
-rw-r--r-- | app/models/project_services/jira_service.rb | 10 | ||||
-rw-r--r-- | app/models/repository.rb | 14 | ||||
-rw-r--r-- | app/models/user_interacted_project.rb | 18 | ||||
-rw-r--r-- | app/serializers/detailed_status_entity.rb | 16 | ||||
-rw-r--r-- | app/services/projects/lfs_pointers/lfs_download_link_list_service.rb | 16 | ||||
-rw-r--r-- | app/services/projects/lfs_pointers/lfs_download_service.rb | 20 | ||||
-rw-r--r-- | app/workers/concerns/waitable_worker.rb | 8 | ||||
-rw-r--r-- | app/workers/create_gpg_signature_worker.rb | 8 | ||||
-rw-r--r-- | app/workers/emails_on_push_worker.rb | 34 | ||||
-rw-r--r-- | app/workers/object_storage/migrate_uploads_worker.rb | 8 | ||||
-rw-r--r-- | app/workers/pipeline_schedule_worker.rb | 19 | ||||
-rw-r--r-- | app/workers/remove_expired_members_worker.rb | 8 |
15 files changed, 86 insertions, 113 deletions
diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index 351a662ae83..e53e2c8fc43 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -286,13 +286,11 @@ class MergeRequestDiff < ActiveRecord::Base return yield(@external_diff_file) if @external_diff_file external_diff.open do |file| - begin - @external_diff_file = file + @external_diff_file = file - yield(@external_diff_file) - ensure - @external_diff_file = nil - end + yield(@external_diff_file) + ensure + @external_diff_file = nil end end diff --git a/app/models/merge_request_diff_file.rb b/app/models/merge_request_diff_file.rb index e8d936e265c..16ec4ed470f 100644 --- a/app/models/merge_request_diff_file.rb +++ b/app/models/merge_request_diff_file.rb @@ -23,6 +23,6 @@ class MergeRequestDiffFile < ActiveRecord::Base super end - binary? ? content.unpack('m0').first : content + binary? ? content.unpack1('m0') : content end end diff --git a/app/models/project.rb b/app/models/project.rb index aba63032cdf..59b139e5986 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1209,11 +1209,9 @@ class Project < ActiveRecord::Base def repo_exists? strong_memoize(:repo_exists) do - begin - repository.exists? - rescue - false - end + repository.exists? + rescue + false end end diff --git a/app/models/project_services/jira_service.rb b/app/models/project_services/jira_service.rb index f7064d5aaea..81302c516c2 100644 --- a/app/models/project_services/jira_service.rb +++ b/app/models/project_services/jira_service.rb @@ -205,12 +205,10 @@ class JiraService < IssueTrackerService # if any transition fails it will log the error message and stop the transition sequence def transition_issue(issue) jira_issue_transition_id.scan(Gitlab::Regex.jira_transition_id_regex).each do |transition_id| - begin - issue.transitions.build.save!(transition: { id: transition_id }) - rescue => error - log_error("Issue transition failed", error: error.message, client_url: client_url) - return false - end + issue.transitions.build.save!(transition: { id: transition_id }) + rescue => error + log_error("Issue transition failed", error: error.message, client_url: client_url) + return false end end diff --git a/app/models/repository.rb b/app/models/repository.rb index 285fce1e6dd..ff355295862 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -265,16 +265,14 @@ class Repository # to avoid unnecessary syncing. def keep_around(*shas) shas.each do |sha| - begin - next unless sha.present? && commit_by(oid: sha) + next unless sha.present? && commit_by(oid: sha) - next if kept_around?(sha) + next if kept_around?(sha) - # This will still fail if the file is corrupted (e.g. 0 bytes) - raw_repository.write_ref(keep_around_ref_name(sha), sha) - rescue Gitlab::Git::CommandError => ex - Rails.logger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}" - end + # This will still fail if the file is corrupted (e.g. 0 bytes) + raw_repository.write_ref(keep_around_ref_name(sha), sha) + rescue Gitlab::Git::CommandError => ex + Rails.logger.error "Unable to create keep-around reference for repository #{disk_path}: #{ex}" end end diff --git a/app/models/user_interacted_project.rb b/app/models/user_interacted_project.rb index ae6778e49be..5fc59b274f5 100644 --- a/app/models/user_interacted_project.rb +++ b/app/models/user_interacted_project.rb @@ -26,16 +26,14 @@ class UserInteractedProject < ActiveRecord::Base cached_exists?(attributes) do transaction(requires_new: true) do - begin - where(attributes).select(1).first || create!(attributes) - true # not caching the whole record here for now - rescue ActiveRecord::RecordNotUnique - # Note, above queries are not atomic and prone - # to race conditions (similar like #find_or_create!). - # In the case where we hit this, the record we want - # already exists - shortcut and return. - true - end + where(attributes).select(1).first || create!(attributes) + true # not caching the whole record here for now + rescue ActiveRecord::RecordNotUnique + # Note, above queries are not atomic and prone + # to race conditions (similar like #find_or_create!). + # In the case where we hit this, the record we want + # already exists - shortcut and return. + true end end end diff --git a/app/serializers/detailed_status_entity.rb b/app/serializers/detailed_status_entity.rb index da994d78286..4f23ef0ed82 100644 --- a/app/serializers/detailed_status_entity.rb +++ b/app/serializers/detailed_status_entity.rb @@ -9,16 +9,14 @@ class DetailedStatusEntity < Grape::Entity expose :details_path expose :illustration do |status| - begin - illustration = { - image: ActionController::Base.helpers.image_path(status.illustration[:image]) - } - illustration = status.illustration.merge(illustration) + illustration = { + image: ActionController::Base.helpers.image_path(status.illustration[:image]) + } + illustration = status.illustration.merge(illustration) - illustration - rescue NotImplementedError - # ignored - end + illustration + rescue NotImplementedError + # ignored end expose :favicon do |status| diff --git a/app/services/projects/lfs_pointers/lfs_download_link_list_service.rb b/app/services/projects/lfs_pointers/lfs_download_link_list_service.rb index 7998976b00a..a9570176e81 100644 --- a/app/services/projects/lfs_pointers/lfs_download_link_list_service.rb +++ b/app/services/projects/lfs_pointers/lfs_download_link_list_service.rb @@ -42,17 +42,15 @@ module Projects def parse_response_links(objects_response) objects_response.each_with_object([]) do |entry, link_list| - begin - link = entry.dig('actions', DOWNLOAD_ACTION, 'href') + link = entry.dig('actions', DOWNLOAD_ACTION, 'href') - raise DownloadLinkNotFound unless link + raise DownloadLinkNotFound unless link - link_list << LfsDownloadObject.new(oid: entry['oid'], - size: entry['size'], - link: add_credentials(link)) - rescue DownloadLinkNotFound, Addressable::URI::InvalidURIError - log_error("Link for Lfs Object with oid #{entry['oid']} not found or invalid.") - end + link_list << LfsDownloadObject.new(oid: entry['oid'], + size: entry['size'], + link: add_credentials(link)) + rescue DownloadLinkNotFound, Addressable::URI::InvalidURIError + log_error("Link for Lfs Object with oid #{entry['oid']} not found or invalid.") end end diff --git a/app/services/projects/lfs_pointers/lfs_download_service.rb b/app/services/projects/lfs_pointers/lfs_download_service.rb index 398f00a598d..a009f479d5d 100644 --- a/app/services/projects/lfs_pointers/lfs_download_service.rb +++ b/app/services/projects/lfs_pointers/lfs_download_service.rb @@ -75,17 +75,15 @@ module Projects create_tmp_storage_dir File.open(tmp_filename, 'wb') do |file| - begin - yield file - rescue StandardError => e - # If the lfs file is successfully downloaded it will be removed - # when it is added to the project's lfs files. - # Nevertheless if any excetion raises the file would remain - # in the file system. Here we ensure to remove it - File.unlink(file) if File.exist?(file) - - raise e - end + yield file + rescue StandardError => e + # If the lfs file is successfully downloaded it will be removed + # when it is added to the project's lfs files. + # Nevertheless if any excetion raises the file would remain + # in the file system. Here we ensure to remove it + File.unlink(file) if File.exist?(file) + + raise e end end diff --git a/app/workers/concerns/waitable_worker.rb b/app/workers/concerns/waitable_worker.rb index 27b94a82444..17946bbc5ca 100644 --- a/app/workers/concerns/waitable_worker.rb +++ b/app/workers/concerns/waitable_worker.rb @@ -25,11 +25,9 @@ module WaitableWorker failed = [] args_list.each do |args| - begin - new.perform(*args) - rescue - failed << args - end + new.perform(*args) + rescue + failed << args end bulk_perform_async(failed) if failed.present? diff --git a/app/workers/create_gpg_signature_worker.rb b/app/workers/create_gpg_signature_worker.rb index 49c7a403838..2827529cc1c 100644 --- a/app/workers/create_gpg_signature_worker.rb +++ b/app/workers/create_gpg_signature_worker.rb @@ -20,11 +20,9 @@ class CreateGpgSignatureWorker # This calculates and caches the signature in the database commits.each do |commit| - begin - Gitlab::Gpg::Commit.new(commit).signature - rescue => e - Rails.logger.error("Failed to create signature for commit #{commit.id}. Error: #{e.message}") - end + Gitlab::Gpg::Commit.new(commit).signature + rescue => e + Rails.logger.error("Failed to create signature for commit #{commit.id}. Error: #{e.message}") end end # rubocop: enable CodeReuse/ActiveRecord diff --git a/app/workers/emails_on_push_worker.rb b/app/workers/emails_on_push_worker.rb index 17ad1d5ab88..ed3e354e4c2 100644 --- a/app/workers/emails_on_push_worker.rb +++ b/app/workers/emails_on_push_worker.rb @@ -52,24 +52,22 @@ class EmailsOnPushWorker end valid_recipients(recipients).each do |recipient| - begin - send_email( - recipient, - project_id, - author_id: author_id, - ref: ref, - action: action, - compare: compare, - reverse_compare: reverse_compare, - diff_refs: diff_refs, - send_from_committer_email: send_from_committer_email, - disable_diffs: disable_diffs - ) - - # These are input errors and won't be corrected even if Sidekiq retries - rescue Net::SMTPFatalError, Net::SMTPSyntaxError => e - logger.info("Failed to send e-mail for project '#{project.full_name}' to #{recipient}: #{e}") - end + send_email( + recipient, + project_id, + author_id: author_id, + ref: ref, + action: action, + compare: compare, + reverse_compare: reverse_compare, + diff_refs: diff_refs, + send_from_committer_email: send_from_committer_email, + disable_diffs: disable_diffs + ) + + # These are input errors and won't be corrected even if Sidekiq retries + rescue Net::SMTPFatalError, Net::SMTPSyntaxError => e + logger.info("Failed to send e-mail for project '#{project.full_name}' to #{recipient}: #{e}") end ensure @email = nil diff --git a/app/workers/object_storage/migrate_uploads_worker.rb b/app/workers/object_storage/migrate_uploads_worker.rb index fe5d27b087d..206eb71b898 100644 --- a/app/workers/object_storage/migrate_uploads_worker.rb +++ b/app/workers/object_storage/migrate_uploads_worker.rb @@ -126,11 +126,9 @@ module ObjectStorage def process_uploader(uploader) MigrationResult.new(uploader.upload).tap do |result| - begin - uploader.migrate!(@to_store) - rescue => e - result.error = e - end + uploader.migrate!(@to_store) + rescue => e + result.error = e end end end diff --git a/app/workers/pipeline_schedule_worker.rb b/app/workers/pipeline_schedule_worker.rb index ac4e9710f33..02a69ea3b54 100644 --- a/app/workers/pipeline_schedule_worker.rb +++ b/app/workers/pipeline_schedule_worker.rb @@ -8,16 +8,15 @@ class PipelineScheduleWorker def perform Ci::PipelineSchedule.active.where("next_run_at < ?", Time.now) .preload(:owner, :project).find_each do |schedule| - begin - Ci::CreatePipelineService.new(schedule.project, - schedule.owner, - ref: schedule.ref) - .execute!(:schedule, ignore_skip_ci: true, save_on_errors: true, schedule: schedule) - rescue => e - error(schedule, e) - ensure - schedule.schedule_next_run! - end + + Ci::CreatePipelineService.new(schedule.project, + schedule.owner, + ref: schedule.ref) + .execute!(:schedule, ignore_skip_ci: true, save_on_errors: true, schedule: schedule) + rescue => e + error(schedule, e) + ensure + schedule.schedule_next_run! end end # rubocop: enable CodeReuse/ActiveRecord diff --git a/app/workers/remove_expired_members_worker.rb b/app/workers/remove_expired_members_worker.rb index 41913900571..3497a1f9280 100644 --- a/app/workers/remove_expired_members_worker.rb +++ b/app/workers/remove_expired_members_worker.rb @@ -6,11 +6,9 @@ class RemoveExpiredMembersWorker def perform Member.expired.find_each do |member| - begin - Members::DestroyService.new.execute(member, skip_authorization: true) - rescue => ex - logger.error("Expired Member ID=#{member.id} cannot be removed - #{ex}") - end + Members::DestroyService.new.execute(member, skip_authorization: true) + rescue => ex + logger.error("Expired Member ID=#{member.id} cannot be removed - #{ex}") end end end |