diff options
32 files changed, 49 insertions, 71 deletions
diff --git a/.rubocop.yml b/.rubocop.yml index 05b8ecc3b00..11e4502849a 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -932,7 +932,7 @@ Lint/UselessAccessModifier: Lint/UselessAssignment: Description: 'Checks for useless assignment to a local variable.' StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#underscore-unused-vars' - Enabled: false + Enabled: true Lint/UselessComparison: Description: 'Checks for comparison of something with itself.' diff --git a/app/controllers/ci/lints_controller.rb b/app/controllers/ci/lints_controller.rb index a81e4e319ff..24dd1b5c93a 100644 --- a/app/controllers/ci/lints_controller.rb +++ b/app/controllers/ci/lints_controller.rb @@ -18,7 +18,7 @@ module Ci rescue Ci::GitlabCiYamlProcessor::ValidationError => e @error = e.message @status = false - rescue Exception => e + rescue Exception @error = "Undefined error" @status = false end diff --git a/app/controllers/omniauth_callbacks_controller.rb b/app/controllers/omniauth_callbacks_controller.rb index 523264b8ea9..f809fa7500a 100644 --- a/app/controllers/omniauth_callbacks_controller.rb +++ b/app/controllers/omniauth_callbacks_controller.rb @@ -71,7 +71,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController redirect_to omniauth_error_path(oauth['provider'], error: error_message) and return end end - rescue Gitlab::OAuth::SignupDisabledError => e + rescue Gitlab::OAuth::SignupDisabledError label = Gitlab::OAuth::Provider.label_for(oauth['provider']) message = "Signing in using your #{label} account without a pre-existing GitLab account is not allowed." @@ -80,7 +80,7 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController end flash[:notice] = message - + redirect_to new_user_session_path end diff --git a/app/controllers/projects/wikis_controller.rb b/app/controllers/projects/wikis_controller.rb index 51c26a6a465..88fccfed509 100644 --- a/app/controllers/projects/wikis_controller.rb +++ b/app/controllers/projects/wikis_controller.rb @@ -98,7 +98,7 @@ class Projects::WikisController < Projects::ApplicationController # Call #wiki to make sure the Wiki Repo is initialized @project_wiki.wiki - rescue ProjectWiki::CouldNotCreateWikiError => ex + rescue ProjectWiki::CouldNotCreateWikiError flash[:notice] = "Could not create Wiki Repository at this time. Please try again later." redirect_to project_path(@project) return false diff --git a/app/finders/issuable_finder.rb b/app/finders/issuable_finder.rb index ab89aa2c53a..6aa16673d63 100644 --- a/app/finders/issuable_finder.rb +++ b/app/finders/issuable_finder.rb @@ -39,7 +39,7 @@ class IssuableFinder items = by_assignee(items) items = by_author(items) items = by_label(items) - items = sort(items) + sort(items) end def group diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 39ab83ccf12..3ab44719d9f 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -35,7 +35,7 @@ module ApplicationHelper def project_icon(project_id, options = {}) project = if project_id.is_a?(Project) - project = project_id + project_id else Project.find_with_namespace(project_id) end diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index 19f957eb965..645ad68e1b3 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -26,7 +26,7 @@ module Ci class Build < ActiveRecord::Base extend Ci::Model - + LAZY_ATTRIBUTES = ['trace'] belongs_to :commit, class_name: 'Ci::Commit' @@ -140,7 +140,7 @@ module Ci def trace_html html = Ci::Ansi2html::convert(trace) if trace.present? - html ||= '' + html || '' end def started? @@ -211,7 +211,7 @@ module Ci if coverage.present? coverage.to_f end - rescue => ex + rescue # if bad regex or something goes wrong we dont want to interrupt transition # so we just silentrly ignore error for now end diff --git a/app/models/ci/project.rb b/app/models/ci/project.rb index 24f70171094..88ba933a434 100644 --- a/app/models/ci/project.rb +++ b/app/models/ci/project.rb @@ -184,7 +184,7 @@ module Ci # If service is available but missing in db # we should create an instance. Ex `create_gitlab_ci_service` - service = self.send :"create_#{service_name}_service" if service.nil? + self.send :"create_#{service_name}_service" if service.nil? end end diff --git a/app/models/merge_request_diff.rb b/app/models/merge_request_diff.rb index f75f999b0d0..c9ef8023aea 100644 --- a/app/models/merge_request_diff.rb +++ b/app/models/merge_request_diff.rb @@ -144,12 +144,10 @@ class MergeRequestDiff < ActiveRecord::Base # Collect array of Git::Diff objects # between target and source branches def unmerged_diffs - diffs = compare_result.diffs - diffs ||= [] - diffs - rescue Gitlab::Git::Diff::TimeoutError => ex + compare_result.diffs || [] + rescue Gitlab::Git::Diff::TimeoutError self.state = :timeout - diffs = [] + [] end def repository diff --git a/app/models/project.rb b/app/models/project.rb index fa7690d8fd5..b90a82da9f2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -413,7 +413,7 @@ class Project < ActiveRecord::Base if template.nil? # If no template, we should create an instance. Ex `create_gitlab_ci_service` - service = self.send :"create_#{service_name}_service" + self.send :"create_#{service_name}_service" else Service.create_from_template(self.id, template) end @@ -738,7 +738,7 @@ class Project < ActiveRecord::Base def create_wiki ProjectWiki.new(self, self.owner).wiki true - rescue ProjectWiki::CouldNotCreateWikiError => ex + rescue ProjectWiki::CouldNotCreateWikiError errors.add(:base, 'Failed create wiki') false end diff --git a/app/models/project_services/hipchat_service.rb b/app/models/project_services/hipchat_service.rb index 7a15a861abc..af2840a57f0 100644 --- a/app/models/project_services/hipchat_service.rb +++ b/app/models/project_services/hipchat_service.rb @@ -85,17 +85,16 @@ class HipchatService < Service def create_message(data) object_kind = data[:object_kind] - message = \ - case object_kind - when "push", "tag_push" - create_push_message(data) - when "issue" - create_issue_message(data) unless is_update?(data) - when "merge_request" - create_merge_request_message(data) unless is_update?(data) - when "note" - create_note_message(data) - end + case object_kind + when "push", "tag_push" + create_push_message(data) + when "issue" + create_issue_message(data) unless is_update?(data) + when "merge_request" + create_merge_request_message(data) unless is_update?(data) + when "note" + create_note_message(data) + end end def create_push_message(push) @@ -167,8 +166,6 @@ class HipchatService < Service obj_attr = data[:object_attributes] obj_attr = HashWithIndifferentAccess.new(obj_attr) merge_request_id = obj_attr[:iid] - source_branch = obj_attr[:source_branch] - target_branch = obj_attr[:target_branch] state = obj_attr[:state] description = obj_attr[:description] title = obj_attr[:title] @@ -194,8 +191,6 @@ class HipchatService < Service data = HashWithIndifferentAccess.new(data) user_name = data[:user][:name] - repo_attr = HashWithIndifferentAccess.new(data[:repository]) - obj_attr = HashWithIndifferentAccess.new(data[:object_attributes]) note = obj_attr[:note] note_url = obj_attr[:url] diff --git a/app/models/repository.rb b/app/models/repository.rb index 79b48ebfedf..2c5ab62d22c 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -549,7 +549,7 @@ class Repository # Run GitLab post receive hook post_receive_hook = Gitlab::Git::Hook.new('post-receive', path_to_repo) - status = post_receive_hook.trigger(gl_id, oldrev, newrev, ref) + post_receive_hook.trigger(gl_id, oldrev, newrev, ref) else # Remove tmp ref and return error to user rugged.references.delete(tmp_ref) diff --git a/app/models/user.rb b/app/models/user.rb index d627b591370..1069f8e3664 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -705,13 +705,7 @@ class User < ActiveRecord::Base end def manageable_namespaces - @manageable_namespaces ||= - begin - namespaces = [] - namespaces << namespace - namespaces += owned_groups - namespaces += masters_groups - end + @manageable_namespaces ||= [namespace] + owned_groups + masters_groups end def namespaces diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb index 7aecee217d8..008833eed80 100644 --- a/app/services/files/base_service.rb +++ b/app/services/files/base_service.rb @@ -21,7 +21,7 @@ module Files create_target_branch end - if sha = commit + if commit success else error("Something went wrong. Your changes were not committed") diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index e54a13ed6c5..faf1ee008e7 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -62,7 +62,7 @@ module Projects after_create_actions if @project.persisted? @project - rescue => ex + rescue @project.errors.add(:base, "Can't save project. Please try again later") @project end diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 7fada98fcdc..549b1f9e9a7 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -63,11 +63,11 @@ module API user_project.build_missing_services service_method = "#{underscored_service}_service" - + send_service(service_method) end end - + @project_service || not_found!("Service") end @@ -149,7 +149,6 @@ module API end def attributes_for_keys(keys, custom_params = nil) - params_hash = custom_params || params attrs = {} keys.each do |key| if params[key].present? or (params.has_key?(key) and params[key] == false) diff --git a/lib/event_filter.rb b/lib/event_filter.rb index 163937c02cf..f15b2cfd231 100644 --- a/lib/event_filter.rb +++ b/lib/event_filter.rb @@ -47,7 +47,7 @@ class EventFilter actions << Event::COMMENTED if filter.include? 'comments' - events = events.where(action: actions) + events.where(action: actions) end def options(key) diff --git a/lib/gitlab/contributions_calendar.rb b/lib/gitlab/contributions_calendar.rb index 45bb904ed7a..8a7f8dc5003 100644 --- a/lib/gitlab/contributions_calendar.rb +++ b/lib/gitlab/contributions_calendar.rb @@ -12,7 +12,6 @@ module Gitlab @timestamps = {} date_from = 1.year.ago - date_to = Date.today events = Event.reorder(nil).contributions.where(author_id: user.id). where("created_at > ?", date_from).where(project_id: projects). diff --git a/lib/gitlab/diff/parser.rb b/lib/gitlab/diff/parser.rb index c1d9520ddf1..7015fe36c3d 100644 --- a/lib/gitlab/diff/parser.rb +++ b/lib/gitlab/diff/parser.rb @@ -14,8 +14,6 @@ module Gitlab lines_arr = ::Gitlab::InlineDiff.processing lines lines_arr.each do |line| - raw_line = line.dup - next if filename?(line) full_line = html_escape(line.gsub(/\n/, '')) diff --git a/lib/gitlab/fogbugz_import/project_creator.rb b/lib/gitlab/fogbugz_import/project_creator.rb index f02ea43910f..8b1b6f48ed5 100644 --- a/lib/gitlab/fogbugz_import/project_creator.rb +++ b/lib/gitlab/fogbugz_import/project_creator.rb @@ -23,7 +23,7 @@ module Gitlab import_url: Project::UNKNOWN_IMPORT_URL ).execute - import_data = project.create_import_data( + project.create_import_data( data: { 'repo' => repo.raw_data, 'user_map' => user_map, diff --git a/lib/gitlab/google_code_import/project_creator.rb b/lib/gitlab/google_code_import/project_creator.rb index 0cfeaf9d61c..1cb7d16aeb3 100644 --- a/lib/gitlab/google_code_import/project_creator.rb +++ b/lib/gitlab/google_code_import/project_creator.rb @@ -23,7 +23,7 @@ module Gitlab import_url: repo.import_url ).execute - import_data = project.create_import_data( + project.create_import_data( data: { "repo" => repo.raw_data, "user_map" => user_map diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb index 8ab72151a69..d80748f23a4 100644 --- a/spec/models/broadcast_message_spec.rb +++ b/spec/models/broadcast_message_spec.rb @@ -27,12 +27,12 @@ describe BroadcastMessage do end it "should return nil if time not come" do - broadcast_message = create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days) + create(:broadcast_message, starts_at: Time.now.tomorrow, ends_at: Time.now + 2.days) expect(BroadcastMessage.current).to be_nil end it "should return nil if time has passed" do - broadcast_message = create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday) + create(:broadcast_message, starts_at: Time.now - 2.days, ends_at: Time.now.yesterday) expect(BroadcastMessage.current).to be_nil end end diff --git a/spec/models/ci/commit_spec.rb b/spec/models/ci/commit_spec.rb index 5429151c8d9..c04bbcbadc7 100644 --- a/spec/models/ci/commit_spec.rb +++ b/spec/models/ci/commit_spec.rb @@ -228,13 +228,13 @@ describe Ci::Commit do it "returns finished_at of latest build" do build = FactoryGirl.create :ci_build, commit: commit, finished_at: Time.now - 60 - build1 = FactoryGirl.create :ci_build, commit: commit, finished_at: Time.now - 120 + FactoryGirl.create :ci_build, commit: commit, finished_at: Time.now - 120 expect(commit.finished_at.to_i).to eq(build.finished_at.to_i) end it "returns nil if there is no finished build" do - build = FactoryGirl.create :ci_not_started_build, commit: commit + FactoryGirl.create :ci_not_started_build, commit: commit expect(commit.finished_at).to be_nil end diff --git a/spec/models/hooks/project_hook_spec.rb b/spec/models/hooks/project_hook_spec.rb index dae7e399cfb..a2dc66fce3e 100644 --- a/spec/models/hooks/project_hook_spec.rb +++ b/spec/models/hooks/project_hook_spec.rb @@ -22,7 +22,7 @@ describe ProjectHook do describe '.push_hooks' do it 'should return hooks for push events only' do hook = create(:project_hook, push_events: true) - hook2 = create(:project_hook, push_events: false) + create(:project_hook, push_events: false) expect(ProjectHook.push_hooks).to eq([hook]) end end @@ -30,7 +30,7 @@ describe ProjectHook do describe '.tag_push_hooks' do it 'should return hooks for tag push events only' do hook = create(:project_hook, tag_push_events: true) - hook2 = create(:project_hook, tag_push_events: false) + create(:project_hook, tag_push_events: false) expect(ProjectHook.tag_push_hooks).to eq([hook]) end end diff --git a/spec/models/hooks/service_hook_spec.rb b/spec/models/hooks/service_hook_spec.rb index 4c8b8910ae7..16641c12124 100644 --- a/spec/models/hooks/service_hook_spec.rb +++ b/spec/models/hooks/service_hook_spec.rb @@ -39,8 +39,6 @@ describe ServiceHook do end it "POSTs the data as JSON" do - json = @data.to_json - @service_hook.execute(@data) expect(WebMock).to have_requested(:post, @service_hook.url).with( headers: { 'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Service Hook' } diff --git a/spec/models/hooks/web_hook_spec.rb b/spec/models/hooks/web_hook_spec.rb index 23f30881d99..2fdc49f02ee 100644 --- a/spec/models/hooks/web_hook_spec.rb +++ b/spec/models/hooks/web_hook_spec.rb @@ -60,8 +60,6 @@ describe ProjectHook do end it "POSTs the data as JSON" do - json = @data.to_json - @project_hook.execute(@data, 'push_hooks') expect(WebMock).to have_requested(:post, @project_hook.url).with( headers: { 'Content-Type'=>'application/json', 'X-Gitlab-Event'=>'Push Hook' } diff --git a/spec/models/milestone_spec.rb b/spec/models/milestone_spec.rb index 36352e1ecce..c88d5349663 100644 --- a/spec/models/milestone_spec.rb +++ b/spec/models/milestone_spec.rb @@ -111,8 +111,8 @@ describe Milestone do describe :is_empty? do before do - issue = create :closed_issue, milestone: milestone - merge_request = create :merge_request, milestone: milestone + create :closed_issue, milestone: milestone + create :merge_request, milestone: milestone end it 'Should return total count of issues and merge requests assigned to milestone' do @@ -125,7 +125,7 @@ describe Milestone do milestone = create :milestone create :closed_issue, milestone: milestone - issue = create :issue + create :issue end it 'should be true if milestone active and all nested issues closed' do diff --git a/spec/models/project_services/gitlab_ci_service_spec.rb b/spec/models/project_services/gitlab_ci_service_spec.rb index 989cfe09167..683a403a907 100644 --- a/spec/models/project_services/gitlab_ci_service_spec.rb +++ b/spec/models/project_services/gitlab_ci_service_spec.rb @@ -49,7 +49,6 @@ describe GitlabCiService do let(:push_sample_data) { Gitlab::PushDataBuilder.build_sample(project, user) } it "calls ci_yaml_file" do - service_hook = double expect(@service).to receive(:ci_yaml_file).with(push_sample_data[:checkout_sha]) @service.execute(push_sample_data) diff --git a/spec/models/project_services/hipchat_service_spec.rb b/spec/models/project_services/hipchat_service_spec.rb index 65d16beef91..f67d7b30980 100644 --- a/spec/models/project_services/hipchat_service_spec.rb +++ b/spec/models/project_services/hipchat_service_spec.rb @@ -87,7 +87,7 @@ describe HipchatService do it "should create a push message" do message = hipchat.send(:create_push_message, push_sample_data) - obj_attr = push_sample_data[:object_attributes] + push_sample_data[:object_attributes] branch = push_sample_data[:ref].gsub('refs/heads/', '') expect(message).to include("#{user.name} pushed to branch " \ "<a href=\"#{project.web_url}/commits/#{branch}\">#{branch}</a> of " \ @@ -107,7 +107,7 @@ describe HipchatService do it "should create a tag push message" do message = hipchat.send(:create_push_message, push_sample_data) - obj_attr = push_sample_data[:object_attributes] + push_sample_data[:object_attributes] expect(message).to eq("#{user.name} pushed new tag " \ "<a href=\"#{project.web_url}/commits/test\">test</a> to " \ "<a href=\"#{project.web_url}\">#{project_name}</a>\n") diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 1c3f5374a24..8b5d2c3a1c1 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -140,7 +140,7 @@ describe Project do describe 'last_activity_date' do it 'returns the creation date of the project\'s last event if present' do - last_activity_event = create(:event, project: project) + create(:event, project: project) expect(project.last_activity_at.to_i).to eq(last_event.created_at.to_i) end diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index f785203af7d..94802dcfb79 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -231,7 +231,7 @@ describe ProjectWiki do end def commit_details - commit = { name: user.name, email: user.email, message: "test commit" } + { name: user.name, email: user.email, message: "test commit" } end def create_page(name, content) diff --git a/spec/models/wiki_page_spec.rb b/spec/models/wiki_page_spec.rb index dc84a14bb40..d7802d1734f 100644 --- a/spec/models/wiki_page_spec.rb +++ b/spec/models/wiki_page_spec.rb @@ -196,7 +196,7 @@ describe WikiPage do end def commit_details - commit = { name: user.name, email: user.email, message: "test commit" } + { name: user.name, email: user.email, message: "test commit" } end def create_page(name, content) |