Skip to content

Commit

Permalink
Merge pull request #4257 from DavidKang/feature/rubocop/string
Browse files Browse the repository at this point in the history
Rubocop is really your friend
  • Loading branch information
Moisés Déniz Alemán committed Dec 20, 2017
2 parents a1a3286 + 716bd93 commit 2f66b8a
Show file tree
Hide file tree
Showing 417 changed files with 6,845 additions and 6,852 deletions.
7 changes: 0 additions & 7 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -675,13 +675,6 @@ Style/StderrPuts:
Exclude:
- 'src/api/test/functional/webui/spider_test.rb'

# Offense count: 9358
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Style/StringLiterals:
Enabled: false

# Offense count: 272
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, MinSize, SupportedStyles.
Expand Down
56 changes: 28 additions & 28 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,94 +4,94 @@ namespace :docker do
desc 'Build our development environment'
task :build do
begin
sh "echo \"# This file is generated by our Rakefile. Do not change it!\" > docker-compose.override.yml"
sh 'echo "# This file is generated by our Rakefile. Do not change it!" > docker-compose.override.yml'
# rubocop:disable Metrics/LineLength
sh "echo \"version: \'2\'\nservices:\n frontend:\n build:\n args:\n CONTAINER_USERID: #{CONTAINER_USERID}\" >> docker-compose.override.yml"
# rubocop:enable Metrics/LineLength
# Build the frontend container
sh "docker-compose build frontend"
sh 'docker-compose build frontend'
# Bootstrap the app
sh "docker-compose up -d db"
sh "docker-compose run --no-deps --rm frontend bundle exec rake dev:bootstrap RAILS_ENV=development"
sh 'docker-compose up -d db'
sh 'docker-compose run --no-deps --rm frontend bundle exec rake dev:bootstrap RAILS_ENV=development'
ensure
sh "docker-compose stop"
sh 'docker-compose stop'
end
end

namespace :test do
desc 'Run our frontend tests in the docker container'
task :frontend do
begin
sh "docker-compose -f docker-compose.ci.yml up --abort-on-container-exit"
sh 'docker-compose -f docker-compose.ci.yml up --abort-on-container-exit'
ensure
sh "docker-compose -f docker-compose.ci.yml stop"
sh 'docker-compose -f docker-compose.ci.yml stop'
end
end

desc 'Run our backend tests in the docker container'
task :backend do
begin
sh "docker-compose run --rm -w /obs backend make -C src/backend test"
sh 'docker-compose run --rm -w /obs backend make -C src/backend test'
ensure
sh "docker-compose stop"
sh 'docker-compose stop'
end
end

desc 'Scan the code base for syntax/code problems'
task :lint do
begin
sh "docker-compose -f docker-compose.ci.yml run --rm rspec bundle exec rake dev:bootstrap dev:lint"
sh 'docker-compose -f docker-compose.ci.yml run --rm rspec bundle exec rake dev:bootstrap dev:lint'
ensure
sh "docker-compose -f docker-compose.ci.yml stop"
sh 'docker-compose -f docker-compose.ci.yml stop'
end
end
end

namespace :maintainer do
desc "Rebuild all our static containers"
desc 'Rebuild all our static containers'
task rebuild: ['rebuild:base', 'rebuild:backend', 'rebuild:frontend-base', 'rebuild:mariadb', 'rebuild:memcached'] do
end
namespace :rebuild do
task :base do
sh "docker build . -t openbuildservice/base:423 -t openbuildservice/base -f Dockerfile.423"
sh 'docker build . -t openbuildservice/base:423 -t openbuildservice/base -f Dockerfile.423'
end
task :mariadb do
sh "docker build . -t openbuildservice/mariadb:423 -t openbuildservice/mariadb -f Dockerfile.mariadb"
sh 'docker build . -t openbuildservice/mariadb:423 -t openbuildservice/mariadb -f Dockerfile.mariadb'
end
task :memcached do
sh "docker build . -t openbuildservice/memcached:423 -t openbuildservice/memcached -f Dockerfile.memcached"
sh 'docker build . -t openbuildservice/memcached:423 -t openbuildservice/memcached -f Dockerfile.memcached'
end
task 'frontend-base' do
sh "docker build . -t openbuildservice/frontend-base:423 -t openbuildservice/frontend-base -f Dockerfile.frontend-base"
sh 'docker build . -t openbuildservice/frontend-base:423 -t openbuildservice/frontend-base -f Dockerfile.frontend-base'
end
task :backend do
sh "docker build . -t openbuildservice/backend:423 -t openbuildservice/backend -f Dockerfile.backend"
sh 'docker build . -t openbuildservice/backend:423 -t openbuildservice/backend -f Dockerfile.backend'
end
end

desc "Rebuild and publish all our static containers"
desc 'Rebuild and publish all our static containers'
task publish: [:rebuild, 'publish:base', 'publish:mariadb', 'publish:memcached', 'publish:backend', 'publish:frontend-base'] do
end
namespace :publish do
task :base do
sh "docker push openbuildservice/base:423"
sh "docker push openbuildservice/base"
sh 'docker push openbuildservice/base:423'
sh 'docker push openbuildservice/base'
end
task :mariadb do
sh "docker push openbuildservice/mariadb:423"
sh "docker push openbuildservice/mariadb"
sh 'docker push openbuildservice/mariadb:423'
sh 'docker push openbuildservice/mariadb'
end
task :memcached do
sh "docker push openbuildservice/memcached:423"
sh "docker push openbuildservice/memcached"
sh 'docker push openbuildservice/memcached:423'
sh 'docker push openbuildservice/memcached'
end
task :backend do
sh "docker push openbuildservice/backend:423"
sh "docker push openbuildservice/backend"
sh 'docker push openbuildservice/backend:423'
sh 'docker push openbuildservice/backend'
end
task 'frontend-base' do
sh "docker push openbuildservice/frontend-base:423"
sh "docker push openbuildservice/frontend-base"
sh 'docker push openbuildservice/frontend-base:423'
sh 'docker push openbuildservice/frontend-base'
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion docs/dev/controller_template_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def blacks
# Use hide_action if they are not private

def call_them(dogs = [])
say("Hey!")
say('Hey!')
dogs.each(&:bark)
end

Expand Down
6 changes: 3 additions & 3 deletions docs/dev/model_template_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Dog < ApplicationRecord
POSSIBLE_COLORS = %w(white black brown vanilla chocolate dotted).freeze

#### Self config
self.table_name = "OBS_dogs"
self.table_name = 'OBS_dogs'

#### Attributes
attr_accessor :number_of_barks
Expand Down Expand Up @@ -53,12 +53,12 @@ def self.born!(attributes)
end

def self.killall_by(attributes = {})
say("Die!")
say('Die!')
where(attributes).each(&:kill)
end

def self.call_all
say("Fiuuiuuuu!")
say('Fiuuiuuuu!')
all.each(&:bark)
end

Expand Down
4 changes: 2 additions & 2 deletions src/api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ gem 'escape_utils'
# to sanitize HTML/CSS
gem 'sanitize'
# as authorization system
gem "pundit"
gem 'pundit'
# for password hashing
gem 'bcrypt'
#
Expand Down Expand Up @@ -65,7 +65,7 @@ gem 'peek'
gem 'peek-dalli'
gem 'peek-mysql2'
# for kerberos authentication
gem "gssapi", require: false
gem 'gssapi', require: false
# for sending events to rabbitmq
gem 'bunny'
# for making changes to existing data
Expand Down
64 changes: 32 additions & 32 deletions src/api/app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def require_valid_project_name
end

def add_api_version
response.headers["X-Opensuse-APIVersion"] = (CONFIG['version']).to_s
response.headers['X-Opensuse-APIVersion'] = (CONFIG['version']).to_s
end

def volley_backend_path(path)
Expand Down Expand Up @@ -152,10 +152,10 @@ def get_request_path
query_string = request.query_string
if request.form_data?
# it's uncommon, but possible that we have both
query_string += "&" if query_string.present?
query_string += '&' if query_string.present?
query_string += request.raw_post
end
query_string = "?" + query_string if query_string.present?
query_string = '?' + query_string if query_string.present?
path + query_string
end

Expand Down Expand Up @@ -185,26 +185,26 @@ def pass_to_backend(path = nil)
end

text = response.body
send_data(text, type: response.fetch("content-type"),
disposition: "inline")
send_data(text, type: response.fetch('content-type'),
disposition: 'inline')
text
end
public :pass_to_backend

rescue_from ActiveRecord::RecordInvalid do |exception|
render_error status: 400, errorcode: "invalid_record", message: exception.record.errors.full_messages.join('\n')
render_error status: 400, errorcode: 'invalid_record', message: exception.record.errors.full_messages.join('\n')
end

rescue_from ActiveXML::Transport::Error do |exception|
render_error status: exception.code, errorcode: "uncaught_exception", message: exception.summary
render_error status: exception.code, errorcode: 'uncaught_exception', message: exception.summary
end

rescue_from Timeout::Error do |exception|
render_error status: 408, errorcode: "timeout_error", message: exception.message
render_error status: 408, errorcode: 'timeout_error', message: exception.message
end

rescue_from ActiveXML::ParseError do
render_error status: 400, errorcode: 'invalid_xml', message: "Invalid XML"
render_error status: 400, errorcode: 'invalid_xml', message: 'Invalid XML'
end

rescue_from APIException do |exception|
Expand All @@ -224,7 +224,7 @@ def pass_to_backend(path = nil)
xml = ActiveXML::Node.new(text)
http_status = xml.value('code')
unless xml.has_attribute? 'origin'
xml.set_attribute "origin", "backend"
xml.set_attribute 'origin', 'backend'
end
text = xml.dump_xml
rescue ActiveXML::ParseError
Expand All @@ -233,11 +233,11 @@ def pass_to_backend(path = nil)
end

rescue_from Project::WritePermissionError do |exception|
render_error status: 403, errorcode: "modify_project_no_permission", message: exception.message
render_error status: 403, errorcode: 'modify_project_no_permission', message: exception.message
end

rescue_from Package::WritePermissionError do |exception|
render_error status: 403, errorcode: "modify_package_no_permission", message: exception.message
render_error status: 403, errorcode: 'modify_package_no_permission', message: exception.message
end

rescue_from ActiveXML::Transport::NotFoundError, ActiveRecord::RecordNotFound do |exception|
Expand All @@ -249,18 +249,18 @@ def pass_to_backend(path = nil)
end

rescue_from Pundit::NotAuthorizedError do |exception|
message = "You are not authorized to perform this action."
message = 'You are not authorized to perform this action.'

pundit_action =
case exception.try(:query).to_s
when "index?" then "list"
when "show?" then "view"
when "create?" then "create"
when "new?" then "create"
when "update?" then "update"
when "edit?" then "edit"
when "destroy?" then "delete"
when "branch?" then "branch"
when 'index?' then 'list'
when 'show?' then 'view'
when 'create?' then 'create'
when 'new?' then 'create'
when 'update?' then 'update'
when 'edit?' then 'edit'
when 'destroy?' then 'delete'
when 'branch?' then 'branch'
else exception.try(:query)
end

Expand Down Expand Up @@ -298,20 +298,20 @@ def gather_exception_defaults(opt)
end

if @status == 401
unless response.headers["WWW-Authenticate"]
unless response.headers['WWW-Authenticate']
if CONFIG['kerberos_mode']
response.headers["WWW-Authenticate"] = 'Negotiate'
response.headers['WWW-Authenticate'] = 'Negotiate'
else
response.headers["WWW-Authenticate"] = 'basic realm="API login"'
response.headers['WWW-Authenticate'] = 'basic realm="API login"'
end
end
end
if @status == 404
@summary ||= "Not found"
@errorcode ||= "not_found"
@summary ||= 'Not found'
@errorcode ||= 'not_found'
end

@summary ||= "Internal Server Error"
@summary ||= 'Internal Server Error'

if @exception
@errorcode ||= 'uncaught_exception'
Expand Down Expand Up @@ -340,15 +340,15 @@ def render_error(opt = {})

def render_ok(opt = {})
# keep compatible to old call style
@errorcode = "ok"
@summary = "Ok"
@errorcode = 'ok'
@summary = 'Ok'
@data = opt[:data] if opt[:data]
render template: 'status', status: 200
end

def render_invoked(opt = {})
@errorcode = "invoked"
@summary = "Job invoked"
@errorcode = 'invoked'
@summary = 'Job invoked'
@data = opt[:data] if opt[:data]
render template: 'status', status: 200
end
Expand Down Expand Up @@ -423,7 +423,7 @@ def set_response_format_to_xml

def forward_from_backend(path)
# apache & mod_xforward case
if CONFIG['use_xforward'] && CONFIG['use_xforward'] != "false"
if CONFIG['use_xforward'] && CONFIG['use_xforward'] != 'false'
logger.debug "[backend] VOLLEY(mod_xforward): #{path}"
headers['X-Forward'] = "http://#{CONFIG['source_host']}:#{CONFIG['source_port']}#{path}"
headers['Cache-Control'] = 'no-transform' # avoid compression
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/controllers/architectures_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def show
required_parameters :id
@architecture = Architecture.find_by_name(params[:id])
unless @architecture
render_error(status: 400, errorcode: "unknown_architecture", message: "Architecture does not exist: #{params[:id]}") && return
render_error(status: 400, errorcode: 'unknown_architecture', message: "Architecture does not exist: #{params[:id]}") && return
end

respond_to do |format|
Expand Down
Loading

0 comments on commit 2f66b8a

Please sign in to comment.