Skip to content

Commit

Permalink
Merge pull request #319 from alexandergraul/obs_controller
Browse files Browse the repository at this point in the history
Refactor: new obs_controller
  • Loading branch information
Ana06 committed Jun 5, 2018
2 parents 6faaa97 + 9dd4339 commit 9c4e7b8
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 163 deletions.
71 changes: 27 additions & 44 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-02-02 15:19:47 +0100 using RuboCop version 0.49.1.
# on 2018-06-02 15:57:33 +0200 using RuboCop version 0.49.1.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
Expand All @@ -23,14 +23,13 @@ Layout/CaseIndentation:
- 'app/controllers/application_controller.rb'
- 'app/models/screenshot.rb'

# Offense count: 86
# Offense count: 81
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SupportedStylesForEmptyBraces, SpaceBeforeBlockParameters.
# SupportedStyles: space, no_space
# SupportedStylesForEmptyBraces: space, no_space
Layout/SpaceInsideBlockBraces:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/download_controller.rb'
- 'app/controllers/package_controller.rb'
- 'app/helpers/application_helper.rb'
Expand Down Expand Up @@ -88,10 +87,10 @@ Lint/InheritException:
- 'app/models/seeker.rb'
- 'lib/api_connect.rb'

# Offense count: 5
# Offense count: 3
Lint/RescueException:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/obs_controller.rb'
- 'app/models/screenshot.rb'
- 'lib/api_connect.rb'

Expand Down Expand Up @@ -128,17 +127,17 @@ Lint/UselessAccessModifier:
- 'app/models/appdata.rb'
- 'lib/activexml/matcher.rb'

# Offense count: 4
# Offense count: 3
Lint/UselessAssignment:
Exclude:
- 'app/models/screenshot.rb'
- 'lib/activexml/node.rb'

# Offense count: 37
# Offense count: 42
Metrics/AbcSize:
Max: 108

# Offense count: 1
# Offense count: 2
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/BlockLength:
Max: 26
Expand All @@ -151,29 +150,29 @@ Metrics/BlockNesting:
# Offense count: 6
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 470
Max: 469

# Offense count: 23
# Offense count: 27
Metrics/CyclomaticComplexity:
Max: 55

# Offense count: 155
# Offense count: 200
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 157
Max: 155

# Offense count: 41
# Offense count: 48
# Configuration parameters: CountComments.
Metrics/MethodLength:
Max: 105

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 128
Max: 127

# Offense count: 17
# Offense count: 19
Metrics/PerceivedComplexity:
Max: 55

Expand Down Expand Up @@ -223,7 +222,7 @@ Style/AndOr:
- 'lib/activexml/node.rb'
- 'lib/activexml/transport.rb'

# Offense count: 4
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
# SupportedStyles: line_count_based, semantic, braces_for_chaining
Expand All @@ -232,9 +231,7 @@ Style/AndOr:
# IgnoredMethods: lambda, proc, it
Style/BlockDelimiters:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/download_controller.rb'
- 'app/controllers/search_controller.rb'

# Offense count: 2
Style/CaseEquality:
Expand Down Expand Up @@ -268,7 +265,6 @@ Style/ClassVars:
# Cop supports --auto-correct.
Style/ColonMethodCall:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/download_controller.rb'
- 'lib/activexml/node.rb'

Expand All @@ -291,35 +287,32 @@ Style/Documentation:
- 'lib/activexml/transport.rb'
- 'lib/api_connect.rb'

# Offense count: 4
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: empty, nil, both
Style/EmptyElse:
Exclude:
- 'app/controllers/download_controller.rb'
- 'app/models/screenshot.rb'

# Offense count: 22
# Offense count: 21
# Cop supports --auto-correct.
Style/EmptyLiteral:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/download_controller.rb'
- 'app/models/appdata.rb'
- 'app/models/seeker.rb'
- 'lib/activexml/matcher.rb'
- 'lib/activexml/node.rb'
- 'lib/activexml/transport.rb'

# Offense count: 2
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: compact, expanded
Style/EmptyMethod:
Exclude:
- 'app/controllers/download_controller.rb'
- 'app/controllers/package_controller.rb'

# Offense count: 5
# Cop supports --auto-correct.
Expand All @@ -341,7 +334,7 @@ Style/GuardClause:
- 'lib/activexml/transport.rb'
- 'lib/api_connect.rb'

# Offense count: 117
# Offense count: 109
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
Expand All @@ -353,7 +346,6 @@ Style/HashSyntax:
- 'app/controllers/search_controller.rb'
- 'app/helpers/application_helper.rb'
- 'app/helpers/package_helper.rb'
- 'app/models/screenshot.rb'
- 'app/models/seeker.rb'
- 'lib/activexml/matcher.rb'
- 'lib/activexml/node.rb'
Expand Down Expand Up @@ -383,15 +375,14 @@ Style/MethodCallWithoutArgsParentheses:
Exclude:
- 'lib/activexml/transport.rb'

# Offense count: 16
# Offense count: 15
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: require_parentheses, require_no_parentheses, require_no_parentheses_except_multiline
Style/MethodDefParentheses:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/download_controller.rb'
- 'app/controllers/package_controller.rb'
- 'app/helpers/application_helper.rb'
- 'app/helpers/package_helper.rb'
- 'lib/activexml/node.rb'
Expand All @@ -402,11 +393,6 @@ Style/MethodMissing:
- 'app/models/seeker.rb'
- 'lib/activexml/node.rb'

# Offense count: 1
Style/MultilineBlockChain:
Exclude:
- 'app/controllers/search_controller.rb'

# Offense count: 2
# Cop supports --auto-correct.
Style/MultilineIfModifier:
Expand Down Expand Up @@ -461,7 +447,7 @@ Style/ParallelAssignment:
- 'app/controllers/application_controller.rb'
- 'lib/activexml/transport.rb'

# Offense count: 11
# Offense count: 12
# Cop supports --auto-correct.
# Configuration parameters: AllowSafeAssignment.
Style/ParenthesesAroundCondition:
Expand Down Expand Up @@ -501,13 +487,12 @@ Style/PreferredHashMethods:
- 'lib/activexml/node.rb'
- 'lib/activexml/transport.rb'

# Offense count: 10
# Offense count: 9
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: compact, exploded
Style/RaiseArgs:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/models/seeker.rb'
- 'lib/activexml/node.rb'
- 'lib/activexml/transport.rb'
Expand All @@ -519,7 +504,7 @@ Style/RedundantException:
Exclude:
- 'lib/activexml/transport.rb'

# Offense count: 11
# Offense count: 12
# Cop supports --auto-correct.
Style/RedundantParentheses:
Exclude:
Expand All @@ -528,12 +513,11 @@ Style/RedundantParentheses:
- 'app/helpers/package_helper.rb'
- 'app/models/seeker.rb'

# Offense count: 21
# Offense count: 20
# Cop supports --auto-correct.
# Configuration parameters: AllowMultipleReturnValues.
Style/RedundantReturn:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/helpers/application_helper.rb'
- 'app/models/seeker.rb'
- 'lib/activexml/node.rb'
Expand All @@ -547,14 +531,13 @@ Style/RedundantSelf:
- 'lib/activexml/node.rb'
- 'lib/activexml/transport.rb'

# Offense count: 4
# Offense count: 3
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
# SupportedStyles: slashes, percent_r, mixed
Style/RegexpLiteral:
Exclude:
- 'app/helpers/package_helper.rb'
- 'app/models/screenshot.rb'
- 'lib/activexml/transport.rb'

# Offense count: 1
Expand All @@ -570,7 +553,7 @@ Style/Semicolon:
Exclude:
- 'lib/api_connect.rb'

# Offense count: 224
# Offense count: 268
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, ConsistentQuotesInMultiline.
# SupportedStyles: single_quotes, double_quotes
Expand All @@ -586,7 +569,7 @@ Style/StringLiteralsInInterpolation:
- 'app/models/seeker.rb'
- 'lib/activexml/transport.rb'

# Offense count: 13
# Offense count: 12
# Cop supports --auto-correct.
# Configuration parameters: IgnoredMethods.
# IgnoredMethods: respond_to, define_method
Expand Down
79 changes: 0 additions & 79 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ class ApplicationController < ActionController::Base
before_action :validate_configuration
before_action :set_language
before_action :set_external_urls
before_action :set_distributions
before_action :set_releases_parameters
# depends on releases
before_action :set_baseproject
Expand Down Expand Up @@ -58,18 +57,6 @@ def set_language
@lang = FastGettext.locale
end

def set_distributions
begin
@distributions = Rails.cache.fetch('distributions',
:expires_in => 120.minutes) do
load_distributions
end
rescue
@distributions = nil
end
raise ApiConnect::Error.new(_("OBS Backend not available")) if @distributions.nil?
end

RELEASES_FILE = Rails.root.join('config', 'releases.yml').freeze

def load_releases
Expand Down Expand Up @@ -123,28 +110,6 @@ def set_baseproject
@baseproject = "openSUSE:Leap:#{@stable_version}" if @baseproject.blank?
end

# load available distributions
def load_distributions
logger.debug "Loading distributions"
distributions = Array.new
begin
response = ApiConnect::get("public/distributions")
doc = REXML::Document.new response.body
doc.elements.each("distributions/distribution") { |element|
dist = Hash[:name => element.elements['name'].text, :project => element.elements['project'].text,
:reponame => element.elements['reponame'].text, :repository => element.elements['repository'].text,
:dist_id => element.attributes['id'].sub(".", "")]
distributions << dist
logger.debug "Added Distribution: #{dist[:name]}"
}
distributions.unshift(Hash[:name => "ALL Distributions", :project => 'ALL'])
rescue Exception => e
logger.error "Error while loading distributions: " + e.to_s
raise
end
return distributions
end

# special version of render json with JSONP capabilities (only needed for rails < 3.0)
def render_json(json, options = {})
callback, variable = params[:callback], params[:variable]
Expand Down Expand Up @@ -182,50 +147,6 @@ def valid_project_name? name
name =~ /^[[:alnum:]][-+\w.:]+$/
end

def set_search_options
@search_term = params[:q] || ""
@baseproject = if !cookies[:baseproject].nil? && @distributions.select { |d| d[:project] == cookies[:baseproject] }
cookies[:baseproject]
else
"openSUSE:Factory"
end
@search_devel = (cookies[:search_devel] == "true" ? true : false)
@search_lang = (cookies[:search_lang] == "true" ? true : false)
@search_debug = (cookies[:search_debug] == "true" ? true : false)
end

def filter_packages
# remove maintenance projects, they are not meant for end users
@packages.reject! { |p| p.project.match(/openSUSE\:Maintenance\:/) }
@packages.reject! { |p| p.project == "openSUSE:Factory:Rebuild" }
@packages.reject! { |p| p.project.start_with?("openSUSE:Factory:Staging") }

# only show packages
@packages = @packages.reject { |p| p.first.type == 'ymp' }

@packages.reject! { |p| p.name.end_with?("-devel") } unless @search_devel

unless @search_lang
@packages.reject! { |p| p.name.end_with?("-lang") || p.name.include?("-translations-") || p.name.include?("-l10n-") }
end

unless @search_debug
@packages.reject! { |p| p.name.end_with?("-buildsymbols", "-debuginfo", "-debugsource") }
end

# filter out ports for different arch
if @baseproject.end_with?("ARM")
@packages.filter! { |p| p.project.include?("ARM") || p.repository.include?("ARM") }
elsif @baseproject.end_with?("PowerPC")
@packages.filter! { |p| p.project.include?("PowerPC") || p.repository.include?("PowerPC") }
else # x86
@packages.reject! do |p|
p.repository.end_with?("_ARM", "_PowerPC", "_zSystems") ||
p.project.include?("ARM") || p.project.include?("PowerPC") || p.project.include?("zSystems")
end
end
end

# TODO: atm obs only offers appdata for Factory
def prepare_appdata
@appdata = Rails.cache.fetch("appdata", :expires_in => 12.hours) do
Expand Down
Loading

0 comments on commit 9c4e7b8

Please sign in to comment.