Skip to content

Commit

Permalink
Merge pull request #14943 from hennevogel/feature/remote-packages
Browse files Browse the repository at this point in the history
Introduces concern for build result parsing
  • Loading branch information
krauselukas committed Sep 21, 2023
2 parents 5741403 + 25ed739 commit 367b540
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 150 deletions.
2 changes: 1 addition & 1 deletion src/api/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ Style/StringConcatenation:
- 'app/controllers/webui/apidocs_controller.rb'
- 'app/controllers/webui/main_controller.rb'
- 'app/controllers/webui/package_controller.rb'
- 'app/controllers/webui/project_controller.rb'
- 'app/controllers/concerns/webui/project_build_result_parsing.rb'
- 'app/controllers/webui/projects/maintenance_incident_requests_controller.rb'
- 'app/controllers/webui/projects/rebuild_times_controller.rb'
- 'app/controllers/webui/projects/status_controller.rb'
Expand Down
49 changes: 30 additions & 19 deletions src/api/.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 --auto-gen-only-exclude --exclude-limit 100`
# on 2023-09-12 12:41:04 UTC using RuboCop version 1.56.3.
# on 2023-09-21 12:17:09 UTC using RuboCop version 1.56.3.
# 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 @@ -12,6 +12,8 @@ Capybara/SpecificMatcher:
- 'spec/features/webui/users/user_home_page_spec.rb'

# Offense count: 33
# Configuration parameters: Include.
# Include: **/*_spec.rb, **/spec/**/*, **/test/**/*, **/features/support/factories/**/*.rb
FactoryBot/FactoryAssociationWithStrategy:
Exclude:
- 'spec/factories/attrib_default_values.rb'
Expand Down Expand Up @@ -152,7 +154,7 @@ Lint/UselessMethodDefinition:
- 'app/controllers/webui/requests/submissions_controller.rb'
- 'test/test_helper.rb'

# Offense count: 881
# Offense count: 883
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 254
Expand All @@ -171,7 +173,7 @@ Metrics/BlockNesting:
- 'lib/xpath_engine.rb'
- 'test/node_matcher.rb'

# Offense count: 82
# Offense count: 83
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ClassLength:
Exclude:
Expand Down Expand Up @@ -267,6 +269,7 @@ Metrics/CyclomaticComplexity:
- 'app/controllers/application_controller.rb'
- 'app/controllers/build_controller.rb'
- 'app/controllers/concerns/backend_proxy.rb'
- 'app/controllers/concerns/webui/project_build_result_parsing.rb'
- 'app/controllers/configurations_controller.rb'
- 'app/controllers/issue_trackers_controller.rb'
- 'app/controllers/person_controller.rb'
Expand Down Expand Up @@ -350,15 +353,16 @@ Metrics/CyclomaticComplexity:
- 'test/functional/zzz_post_consistency_test.rb'
- 'test/node_matcher.rb'

# Offense count: 963
# Offense count: 966
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 221

# Offense count: 5
# Offense count: 6
# Configuration parameters: CountComments, Max, CountAsOne.
Metrics/ModuleLength:
Exclude:
- 'app/controllers/concerns/webui/project_build_result_parsing.rb'
- 'app/helpers/flag_helper.rb'
- 'app/helpers/maintenance_helper.rb'
- 'app/helpers/webui/request_helper.rb'
Expand Down Expand Up @@ -388,6 +392,7 @@ Metrics/PerceivedComplexity:
Exclude:
- 'app/controllers/application_controller.rb'
- 'app/controllers/build_controller.rb'
- 'app/controllers/concerns/webui/project_build_result_parsing.rb'
- 'app/controllers/configurations_controller.rb'
- 'app/controllers/issue_trackers_controller.rb'
- 'app/controllers/person_controller.rb'
Expand Down Expand Up @@ -617,7 +622,7 @@ Naming/VariableNumber:
# Configuration parameters: MinSize.
Performance/CollectionLiteralInLoop:
Exclude:
- 'app/controllers/webui/project_controller.rb'
- 'app/controllers/concerns/webui/project_build_result_parsing.rb'
- 'app/models/concerns/has_relationships.rb'
- 'lib/memory_debugger.rb'
- 'lib/tasks/extract.rake'
Expand Down Expand Up @@ -694,13 +699,13 @@ RSpec/AnyInstance:
- 'spec/models/project_spec.rb'
- 'spec/policies/package_policy_spec.rb'

# Offense count: 1223
# Offense count: 1225
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Enabled: false

# Offense count: 468
# Offense count: 469
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: SkipBlocks, EnforcedStyle.
# SupportedStyles: described_class, explicit
Expand Down Expand Up @@ -829,7 +834,7 @@ RSpec/IteratedExpectation:
Exclude:
- 'spec/models/user_spec.rb'

# Offense count: 379
# Offense count: 381
# This cop supports safe autocorrection (--autocorrect).
RSpec/LeadingSubject:
Enabled: false
Expand Down Expand Up @@ -869,7 +874,7 @@ RSpec/MessageSpies:
- 'spec/controllers/webui/apidocs_controller_spec.rb'
- 'spec/models/kiwi/image_spec.rb'

# Offense count: 1694
# Offense count: 1696
# Configuration parameters: AllowSubject.
RSpec/MultipleMemoizedHelpers:
Max: 28
Expand Down Expand Up @@ -997,7 +1002,7 @@ Rails/FilePath:
- 'test/functional/zzz_post_consistency_test.rb'
- 'test/test_helper.rb'

# Offense count: 9
# Offense count: 8
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: AllowedMethods, AllowedPatterns.
# AllowedMethods: order, limit, select, lock
Expand All @@ -1011,9 +1016,8 @@ Rails/FindEach:
- 'app/views/models/_configuration.xml.builder'
- 'db/data/20210707102506_add_api_endpoints_to_payload.rb'
- 'db/data/20230620110143_backfill_scm_vendor_and_hook_event_in_workflow_run.rb'
- 'spec/factories/bs_requests.rb'

# Offense count: 25
# Offense count: 27
# Configuration parameters: Include.
# Include: app/models/**/*.rb
Rails/HasManyOrHasOneDependent:
Expand All @@ -1037,7 +1041,7 @@ Rails/HelperInstanceVariable:
- 'app/helpers/webui/project_helper.rb'
- 'app/helpers/webui/webui_helper.rb'

# Offense count: 36
# Offense count: 37
# Configuration parameters: IgnoreScopes, Include.
# Include: app/models/**/*.rb
Rails/InverseOf:
Expand Down Expand Up @@ -1182,7 +1186,7 @@ Style/ArgumentsForwarding:
Exclude:
- 'app/models/configuration.rb'

# Offense count: 152
# Offense count: 155
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: nested, compact
Expand Down Expand Up @@ -1225,7 +1229,7 @@ Style/ConditionalAssignment:
Exclude:
- 'app/models/bs_request_action_submit.rb'

# Offense count: 991
# Offense count: 1000
# Configuration parameters: AllowedConstants.
Style/Documentation:
Enabled: false
Expand All @@ -1237,7 +1241,7 @@ Style/ExplicitBlockArgument:
- 'app/lib/backend/connection.rb'
- 'app/models/project.rb'

# Offense count: 1730
# Offense count: 1741
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Expand Down Expand Up @@ -1361,14 +1365,21 @@ Style/SoleNestedConditional:
- 'script/reformat_memprof'
- 'test/node_matcher.rb'

# Offense count: 1
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: Mode.
Style/StringConcatenation:
Exclude:
- 'app/controllers/concerns/webui/project_build_result_parsing.rb'

# Offense count: 377
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: MinSize.
# SupportedStyles: percent, brackets
Style/SymbolArray:
EnforcedStyle: brackets

# Offense count: 297
# Offense count: 298
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle, MinSize, WordRegex.
# SupportedStyles: percent, brackets
Expand Down Expand Up @@ -1412,7 +1423,7 @@ ViewComponent/MissingPreviewFile:
- 'app/components/workflow_run_row_component.rb'
- 'app/components/write_and_preview_component.rb'

# Offense count: 2713
# Offense count: 2717
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Expand Down
133 changes: 133 additions & 0 deletions src/api/app/controllers/concerns/webui/project_build_result_parsing.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
module Webui::ProjectBuildResultParsing
extend ActiveSupport::Concern

def monitor_buildresult
@legend = Buildresult::STATUS_DESCRIPTION

@name_filter = params[:pkgname]
@lastbuild_switch = params[:lastbuild]
# FIXME: this code needs some love
defaults = if params[:defaults]
(begin
Integer(params[:defaults])
rescue ArgumentError
1
end).positive?
else
true
end
params['expansionerror'] = 1 if params['unresolvable']
monitor_set_filter(defaults)

find_opt = { project: @project.to_param, view: 'status', code: @status_filter,
arch: @arch_filter, repository: @repo_filter }
find_opt[:lastbuild] = 1 if @lastbuild_switch.present?

buildresult = Buildresult.find_hashed(find_opt)
if buildresult.empty?
flash[:warning] = "No build results for project '#{elide(@project.name)}'"
redirect_to action: :show, project: params[:project]
return
end

return unless buildresult.key?('result')

buildresult
end

def monitor_parse_buildresult(buildresult)
@packagenames = Set.new
@statushash = {}
@repostatushash = {}
@repostatusdetailshash = {}
@failures = 0

buildresult.elements('result') do |result|
monitor_parse_result(result)
end

# convert to sorted array
@packagenames = @packagenames.to_a.sort!
end

def monitor_parse_result(result)
repo = result['repository']
arch = result['arch']

return unless @repo_filter.nil? || @repo_filter.include?(repo)
return unless @arch_filter.nil? || @arch_filter.include?(arch)

# package status cache
@statushash[repo] ||= {}
stathash = @statushash[repo][arch] = {}

result.elements('status') do |status|
package = status['package']
next if @name_filter.present? && !filter_matches?(package, @name_filter)

stathash[package] = status
@packagenames.add(package)
@failures += 1 if status['code'].in?(['unresolvable', 'failed', 'broken'])
end

# repository status cache
@repostatushash[repo] ||= {}
@repostatusdetailshash[repo] ||= {}

return unless result.key?('state')

@repostatushash[repo][arch] = if result.key?('dirty')
'outdated_' + result['state']
else
result['state']
end

@repostatusdetailshash[repo][arch] = result['details'] if result.key?('details')
end

def monitor_set_filter(defaults)
@avail_status_values = Buildresult.avail_status_values
@status_filter = []
@avail_status_values.each do |s|
id = s.delete(' ')
if params.key?(id)
next if params[id].to_s == '0'
else
next unless defaults
end
next if defaults && ['disabled', 'excluded', 'unknown'].include?(s)

@status_filter << s
end

repos = @project.repositories
@avail_repo_values = repos.select(:name).distinct.order(:name).pluck(:name)
@avail_arch_values = repos.joins(:architectures).select('architectures.name').distinct.order('architectures.name').pluck('architectures.name')

@arch_filter = []
@avail_arch_values.each do |s|
archid = valid_xml_id("arch_#{s}")
@arch_filter << s if defaults || params[archid]
end

@repo_filter = []
@avail_repo_values.each do |s|
repoid = valid_xml_id("repo_#{s}")
@repo_filter << s if defaults || params[repoid]
end
end

def filter_matches?(input, filter_string)
result = false
filter_string.gsub!(/\s*/, '')
filter_string.split(',').each do |filter|
no_invert = filter.match(/(^!?)(.+)/)
result = if no_invert[1] == '!'
input.include?(no_invert[2]) ? result : true
else
input.include?(no_invert[2]) ? true : result
end
end
result
end
end
Loading

0 comments on commit 367b540

Please sign in to comment.