Skip to content

Commit

Permalink
Merge pull request #9914 from openSUSE/depfu/update/srcapi/rubocop-0.…
Browse files Browse the repository at this point in the history
…88.0

[src/api] Update rubocop: 0.87.1 → 0.88.0 (major)
  • Loading branch information
saraycp committed Jul 21, 2020
2 parents 13405cc + 6909ea7 commit 4187ef3
Show file tree
Hide file tree
Showing 32 changed files with 108 additions and 84 deletions.
2 changes: 1 addition & 1 deletion src/api/Gemfile.lock
Expand Up @@ -335,7 +335,7 @@ GEM
rspec-support (3.9.3)
rspec_junit_formatter (0.4.1)
rspec-core (>= 2, < 4, != 2.12.0)
rubocop (0.87.1)
rubocop (0.88.0)
parallel (~> 1.10)
parser (>= 2.7.1.1)
rainbow (>= 2.2.2, < 4.0)
Expand Down
7 changes: 4 additions & 3 deletions src/api/app/controllers/group_controller.rb
Expand Up @@ -70,11 +70,12 @@ def command

user = User.find_by_login!(params[:userid]) if params[:userid]

if params[:cmd] == 'add_user'
case params[:cmd]
when 'add_user'
group.add_user(user)
elsif params[:cmd] == 'remove_user'
when 'remove_user'
group.remove_user(user)
elsif params[:cmd] == 'set_email'
when 'set_email'
group.set_email(params[:email])
else
raise UnknownCommandError, 'cmd must be set to add_user or remove_user'
Expand Down
7 changes: 4 additions & 3 deletions src/api/app/controllers/public_controller.rb
Expand Up @@ -48,7 +48,8 @@ def project_index
# project visible/known ?
@project = Project.get_by_name(params[:project])
path = unshift_public(request.path_info)
if params[:view] == 'info'
case params[:view]
when 'info'
# nofilename since a package may have no source access
if params[:nofilename] && params[:nofilename] != '1'
render_error status: 400, errorcode: 'parameter_error', message: 'nofilename is not allowed as parameter'
Expand All @@ -57,11 +58,11 @@ def project_index
# path has multiple package= parameters
path += '?' + request.query_string
path += '&nofilename=1' unless params[:nofilename]
elsif params[:view] == 'verboseproductlist'
when 'verboseproductlist'
@products = Product.all_products(@project, params[:expand])
render 'source/verboseproductlist'
return
elsif params[:view] == 'productlist'
when 'productlist'
@products = Product.all_products(@project, params[:expand])
render 'source/productlist'
return
Expand Down
7 changes: 4 additions & 3 deletions src/api/app/controllers/source_project_controller.rb
Expand Up @@ -22,15 +22,16 @@ def show

# we let the backend list the packages after we verified the project is visible
if params.key?(:view)
if params[:view] == 'verboseproductlist'
case params[:view]
when 'verboseproductlist'
@products = Product.all_products(@project, params[:expand])
render 'source/verboseproductlist'
return
elsif params[:view] == 'productlist'
when 'productlist'
@products = Product.all_products(@project, params[:expand])
render 'source/productlist'
return
elsif params[:view] == 'issues'
when 'issues'
render_project_issues
else
pass_to_backend
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/webui/kiwi/images_controller.rb
Expand Up @@ -132,7 +132,7 @@ def image_params
package_groups_attributes = [
:id,
:_destroy,
packages_attributes: [:id, :name, :arch, :replaces, :bootdelete, :bootinclude, :_destroy]
{ packages_attributes: [:id, :name, :arch, :replaces, :bootdelete, :bootinclude, :_destroy] }
]

profiles_attributes = [
Expand Down
5 changes: 3 additions & 2 deletions src/api/app/controllers/webui/package_controller.rb
Expand Up @@ -476,9 +476,10 @@ def update_build_log
rescue Timeout::Error, IOError
@log_chunk = ''
rescue Backend::Error => e
if %r{Logfile is not that big}.match?(e.summary)
case e.summary
when %r{Logfile is not that big}
@log_chunk = ''
elsif /start out of range/.match?(e.summary)
when /start out of range/
# probably build compare has cut log and offset is wrong, reset offset
@log_chunk = ''
@offset = old_offset
Expand Down
7 changes: 4 additions & 3 deletions src/api/app/controllers/webui/repositories_controller.rb
Expand Up @@ -194,11 +194,12 @@ def change_flag
def follow_change_flag_command(flag_type)
architecture = Architecture.from_cache!(params[:architecture]) if params[:architecture]

if params[:command] == 'remove'
case params[:command]
when 'remove'
@main_object.flags.of_type(flag_type).where(repo: params[:repository], architecture: architecture).delete_all
elsif %r{^set-(?<status>disable|enable)$} =~ params[:command]
when /^set-(?<status>disable|enable)$/
flag = @main_object.flags.find_or_create_by(flag: flag_type, repo: params[:repository], architecture: architecture)
flag.update(status: status)
flag.update(status: $LAST_MATCH_INFO['status'])
end
@main_object.store
end
Expand Down
5 changes: 3 additions & 2 deletions src/api/app/controllers/webui/sitemaps_controller.rb
Expand Up @@ -15,9 +15,10 @@ def packages
projects_table = Project.arel_table

predication =
if %r{home}.match?(project_name)
case project_name
when %r{home}
projects_table[:name].matches("#{project_name}%")
elsif project_name == 'opensuse'
when 'opensuse'
projects_table[:name].matches('openSUSE:%')
else
projects_table[:name].does_not_match_all(['home:%', 'DISCONTINUED:%', 'openSUSE:%'])
Expand Down
21 changes: 8 additions & 13 deletions src/api/app/controllers/webui/webui_controller.rb
Expand Up @@ -51,9 +51,10 @@ class Webui::WebuiController < ActionController::Base

rescue_from Backend::Error, Timeout::Error do |exception|
Airbrake.notify(exception)
message = if exception.is_a?(Backend::Error)
message = case exception
when Backend::Error
'There has been an internal error. Please try again.'
elsif exception.is_a?(Timeout::Error)
when Timeout::Error
'The request timed out. Please try again.'
end

Expand Down Expand Up @@ -246,17 +247,11 @@ def require_package
private

def send_login_information_rabbitmq(msg)
message = case msg
when :success
'login,access_point=webui value=1'
when :disabled
'login,access_point=webui,failure=disabled value=1'
when :logout
'logout,access_point=webui value=1'
when :unauthenticated
'login,access_point=webui,failure=unauthenticated value=1'
end
RabbitmqBus.send_to_bus('metrics', message)
message_mapping = { success: 'login,access_point=webui value=1',
disabled: 'login,access_point=webui,failure=disabled value=1',
logout: 'logout,access_point=webui value=1',
unauthenticated: 'login,access_point=webui,failure=unauthenticated value=1' }
RabbitmqBus.send_to_bus('metrics', message_mapping[msg])
end

def authenticator
Expand Down
12 changes: 12 additions & 0 deletions src/api/app/helpers/webui/buildresult_helper.rb
Expand Up @@ -64,4 +64,16 @@ def collapse_link(expanded, main_name, repository_name = nil)
end
end
end

# Paints an rpmlog line green-ish when the line has a Warning and red when it has an error.
def colorize_line(line)
case line
when /\w+(?:\.\w+)+: W: /
tag.span(line.strip, style: 'color: olive;')
when /\w+(?:\.\w+)+: E: /
tag.span(line.strip, style: 'color: red;')
else
line.strip
end
end
end
5 changes: 3 additions & 2 deletions src/api/app/lib/suse/permission.rb
Expand Up @@ -21,9 +21,10 @@ def project_change?(project = nil)
# is the owner of the project
logger.debug "User #{@user.login} wants to change the project"

if project.is_a?(Project)
case project
when Project
prj = project
elsif project.is_a?(String)
when String
prj = Project.find_by_name(project)
# avoid remote projects
return false unless prj.is_a?(Project)
Expand Down
7 changes: 4 additions & 3 deletions src/api/app/models/bs_request.rb
Expand Up @@ -748,16 +748,17 @@ def change_review_state(new_review_state, opts = {})
self.comment = review.reason
self.state = new_request_state
self.commenter = User.session!.login
if new_request_state == :new
case new_request_state
when :new
self.comment = 'All reviewers accepted request'
save!
Event::RequestReviewsDone.create(event_parameters)
HistoryElement::RequestAllReviewsApproved.create(history_parameters)
# pre-approved requests can be processed
BsRequestAutoAcceptJob.perform_later(id) if approver
elsif new_request_state == :review
when :review
save!
elsif new_request_state == :declined
when :declined
HistoryElement::RequestDeclined.create(history_parameters)
save!
end
Expand Down
10 changes: 6 additions & 4 deletions src/api/app/models/event_subscription.rb
Expand Up @@ -31,9 +31,10 @@ class EventSubscription < ApplicationRecord
scope :for_eventtype, ->(eventtype) { where(eventtype: eventtype) }
scope :defaults, -> { where(user_id: nil, group_id: nil) }
scope :for_subscriber, lambda { |subscriber|
if subscriber.is_a?(User)
case subscriber
when User
where(user: subscriber)
elsif subscriber.is_a?(Group)
when Group
where(group: subscriber)
else
defaults
Expand All @@ -49,9 +50,10 @@ def subscriber
end

def subscriber=(subscriber)
if subscriber.is_a?(User)
case subscriber
when User
self.user = subscriber
elsif subscriber.is_a?(Group)
when Group
self.group = subscriber
end
end
Expand Down
5 changes: 3 additions & 2 deletions src/api/app/models/event_subscription/find_for_event.rb
Expand Up @@ -54,10 +54,11 @@ def filter_and_convert_groups_without_emails_to_users(receivers)
new_receivers = []

receivers.each do |receiver|
if receiver.is_a?(User)
case receiver
when User
new_receivers << receiver

elsif receiver.is_a?(Group)
when Group

if receiver.email.present?
new_receivers << receiver
Expand Down
5 changes: 3 additions & 2 deletions src/api/app/models/project.rb
Expand Up @@ -367,9 +367,10 @@ def validate_remote_permissions(request_data)
end

def has_dod_elements?(request_data)
if request_data.is_a?(Array)
case request_data
when Array
request_data.any? { |r| r['download'] }
elsif request_data.is_a?(Hash)
when Hash
request_data['download'].present?
end
end
Expand Down
7 changes: 4 additions & 3 deletions src/api/app/models/review.rb
Expand Up @@ -233,11 +233,12 @@ def change_state(new_state, comment)
Event::ReviewChanged.create(bs_request.event_parameters)

arguments = { review: self, comment: comment, user: User.session! }
if new_state == :accepted
case new_state
when :accepted
HistoryElement::ReviewAccepted.create(arguments)
elsif new_state == :declined
when :declined
HistoryElement::ReviewDeclined.create(arguments)
elsif new_state == :new
else
HistoryElement::ReviewReopened.create(arguments)
end
true
Expand Down
5 changes: 3 additions & 2 deletions src/api/app/views/statistics/highest_rated.xml.builder
@@ -1,13 +1,14 @@
xml.highest_rated do
@ratings.each do |rating|
if rating.object_type == 'Package'
case rating.object_type
when 'Package'
xml.package(
score: rating.score_calculated,
count: rating.count,
project: rating.packages.project.name,
name: rating.packages.name
)
elsif rating.object_type == 'Project'
when 'Project'
xml.project(
score: rating.score_calculated,
count: rating.count,
Expand Down
8 changes: 1 addition & 7 deletions src/api/app/views/webui/package/_rpmlint_log.html.haml
@@ -1,8 +1,2 @@
-# FIXME: move this into a helper
- @log.lines.each do |line|
- if /\w+(?:\.\w+)+: W: /.match?(line)
= tag.span(line.strip, style: 'color: olive;')
- elsif /\w+(?:\.\w+)+: E: /.match?(line)
= tag.span(line.strip, style: 'color: red;')
- else
= line.strip
= colorize_line(line)
2 changes: 1 addition & 1 deletion src/api/config/application.rb
Expand Up @@ -4,7 +4,7 @@

# Assets should be precompiled for production (so we don't need the gems loaded then)
Bundler.require(*Rails.groups(assets: ['development', 'test']))
require_relative '../lib/rabbitmq_bus.rb'
require_relative '../lib/rabbitmq_bus'

module OBSApi
class Application < Rails::Application
Expand Down
Expand Up @@ -41,10 +41,11 @@ def traverse(&block)
private

def traverse_value(value, &block)
if value.is_a?(Hash)
case value
when Hash
value.each { |key, sub_value| value[key] = traverse_value(sub_value, &block) }

elsif value.is_a?(Array)
when Array
value.map { |element| traverse_value(element, &block) }

else
Expand Down
5 changes: 3 additions & 2 deletions src/api/lib/tasks/statistics/github/code_frequency.rake
Expand Up @@ -7,9 +7,10 @@ namespace :statistics do

# The first time you make this request to github, it returns an empty json response with status 202
# because github generates the statistics asynchronously. Once they are generated will be 200.
if response.code == '202'
case response.code
when '202'
puts 'Statistics are being generated in the background by github. Please re-run this task in a minute to get the results.'
elsif response.code == '200'
when '200'
weeks = JSON.parse(response.body)

File.open('code_frequency.csv', 'w') do |file|
Expand Down
5 changes: 3 additions & 2 deletions src/api/lib/tasks/statistics/github/commit_activity.rake
Expand Up @@ -7,9 +7,10 @@ namespace :statistics do

# The first time you make this request to github, it returns an empty json response with status 202
# because github generates the statistics asynchronously. Once they are generated will be 200.
if response.code == '202'
case response.code
when '202'
puts 'Statistics are being generated in the background by github. Please re-run this task in a minute to get the results.'
elsif response.code == '200'
when '200'
weeks = JSON.parse(response.body)

File.open('commit_activity.csv', 'w') do |file|
Expand Down
5 changes: 3 additions & 2 deletions src/api/lib/xpath_engine.rb
Expand Up @@ -389,7 +389,8 @@ def parse_predicate(root, stack)
__send__(fname_int, root, *stack.shift)
when :child
qtype = stack.shift
if qtype == :qname
case qtype
when :qname
stack.shift
root << stack.shift
qtype = stack.shift
Expand All @@ -404,7 +405,7 @@ def parse_predicate(root, stack)
parse_predicate(root, qtype)
end
root.pop
elsif qtype == :any
when :any
# noop, already shifted
else
raise IllegalXpathError, "unhandled token '#{t.inspect}'"
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/controllers/webui/users_controller_spec.rb
Expand Up @@ -369,7 +369,7 @@

it 'returns user token as array of hash' do
get :tokens, params: { q: 'foo', format: :json }
expect(JSON.parse(response.body)).to match_array(['name' => 'foobaz'])
expect(JSON.parse(response.body)).to match_array([{ 'name' => 'foobaz' }])
end
end

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/db/data/project_log_entry_user_name_spec.rb
@@ -1,5 +1,5 @@
require 'rails_helper'
require_relative '../../../db/data/20180214132015_project_log_entry_user_name.rb'
require_relative '../../../db/data/20180214132015_project_log_entry_user_name'

RSpec.describe ProjectLogEntryUserName, type: :model do
let(:user) { create(:confirmed_user) }
Expand Down

0 comments on commit 4187ef3

Please sign in to comment.