Skip to content

Commit

Permalink
[frontend] Rubucop changes to staging_project.rb
Browse files Browse the repository at this point in the history
Rubocop changed all these on save in atom (configured to do so).
So I assume this is actually wanted
  • Loading branch information
coolo authored and bgeuken committed Jun 26, 2018
1 parent d05b0c0 commit 6afc656
Showing 1 changed file with 32 additions and 35 deletions.
67 changes: 32 additions & 35 deletions src/api/app/models/obs_factory/staging_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ class StagingProject

attr_accessor :project, :distribution, :parent

OBSOLETE_STATES = %w(declined superseded revoked)
NAME_PREFIX = ":Staging:"
ADI_NAME_PREFIX = ":Staging:adi:"
OBSOLETE_STATES = ['declined', 'superseded', 'revoked'].freeze
NAME_PREFIX = ":Staging:".freeze
ADI_NAME_PREFIX = ":Staging:adi:".freeze

# Find all staging projects for a given distribution
#
# @param [Boolean] only_letter only letter stagings, otherwise all stagings
# @return [Array] array of StagingProject objects
def self.for(distribution, only_letter=true)
def self.for(distribution, only_letter = true)
wildcard = only_letter ? "_" : "%"
::Project.where(["name like ?", "#{distribution.root_project_name}#{NAME_PREFIX}#{wildcard}"]).
map { |project| StagingProject.new(project: project, distribution: distribution) }
Expand All @@ -37,16 +37,12 @@ def self.find(distribution, id)
# Name of the associated project
#
# @return [String] name of the Project object
def name
project.name
end
delegate :name, to: :project

# Description of the associated project
#
# @return [String] description of the Project object
def description
project.description
end
delegate :description, to: :project

# Checks if the project is adi staging project
#
Expand Down Expand Up @@ -114,7 +110,7 @@ def subproject

# only for compat in the JSON
def subprojects
[ subproject ]
[subproject]
end

# Associated openQA jobs.
Expand All @@ -135,7 +131,7 @@ def openqa_results_relevant?
if parent
return parent.openqa_results_relevant?
else # master project
return ! [:building, :empty].include?(overall_state)
return ![:building, :empty].include?(overall_state)
end
end

Expand Down Expand Up @@ -207,16 +203,15 @@ def missing_reviews

(open_requests + selected_requests).uniq.each do |req|
req.reviews.each do |rev|
unless rev.state.to_s == 'accepted' || rev.by_project == name
# FIXME: this loop (and the inner if) would not be needed
# if every review only has one valid by_xxx.
# I'm keeping it to mimic the python implementation.
# Instead, we could have something like
# who = rev.by_group || rev.by_user || rev.by_project || rev.by_package
attribs.each do |att|
if who = rev.send(att)
@missing_reviews << { id: rev.id, request: req.number, state: rev.state.to_s, package: req.package, by: who }
end
next if rev.state.to_s == 'accepted' || rev.by_project == name
# FIXME: this loop (and the inner if) would not be needed
# if every review only has one valid by_xxx.
# I'm keeping it to mimic the python implementation.
# Instead, we could have something like
# who = rev.by_group || rev.by_user || rev.by_project || rev.by_package
attribs.each do |att|
if who = rev.send(att)
@missing_reviews << { id: rev.id, request: req.number, state: rev.state.to_s, package: req.package, by: who }
end
end
end
Expand All @@ -229,7 +224,7 @@ def missing_reviews
#
# @return [Hash] Hash with the metadata (currently the list of requests)
def meta
@meta ||= YAML.load(description) || {}
@meta ||= YAML.safe_load(description) || {}
end

# Name of the ISO file generated by the staging project.
Expand All @@ -241,8 +236,10 @@ def iso
end

def self.attributes
%w(name description obsolete_requests openqa_jobs building_repositories
broken_packages subproject subprojects untracked_requests missing_reviews selected_requests overall_state )
['name', 'description', 'obsolete_requests', 'openqa_jobs',
'building_repositories', 'broken_packages', 'subproject',
'subprojects', 'untracked_requests', 'missing_reviews',
'selected_requests', 'overall_state']
end

# Required by ActiveModel::Serializers
Expand Down Expand Up @@ -314,23 +311,23 @@ def overall_state

# Used internally to calculate #broken_packages and #building_repositories
def set_buildinfo
buildresult = Buildresult.find_hashed(project: name, code: %w(failed broken unresolvable))
buildresult = Buildresult.find_hashed(project: name, code: ['failed', 'broken', 'unresolvable'])
@broken_packages = []
@building_repositories = []
buildresult.elements('result') do |result|
building = false
if !%w(published unpublished).include?(result['state']) || result['dirty'] == 'true'
if !['published', 'unpublished'].include?(result['state']) || result['dirty'] == 'true'
building = true
end
result.elements('status') do |status|
code = status.get('code')
if %w(broken failed).include?(code) || (code == 'unresolvable' && !building)
@broken_packages << { 'package' => status['package'],
'project' => name,
'state' => code,
'details' => status['details'],
if ['broken', 'failed'].include?(code) || (code == 'unresolvable' && !building)
@broken_packages << { 'package' => status['package'],
'project' => name,
'state' => code,
'details' => status['details'],
'repository' => result['repository'],
'arch' => result['arch'] }
'arch' => result['arch'] }
end
end
if building
Expand All @@ -342,7 +339,7 @@ def set_buildinfo
buildresult = Buildresult.find_hashed(project: name, view: 'summary', repository: current_repo['repository'], arch: current_repo['arch'])
buildresult = buildresult.get('result').get('summary')
buildresult.elements('statuscount') do |sc|
if %w(excluded broken failed unresolvable succeeded excluded disabled).include?(sc['code'])
if ['excluded', 'broken', 'failed', 'unresolvable', 'succeeded', 'excluded', 'disabled'].include?(sc['code'])
current_repo[:final] += sc['count'].to_i
else
current_repo[:tobuild] += sc['count'].to_i
Expand All @@ -352,7 +349,7 @@ def set_buildinfo
end
end
if @building_repositories.present?
@broken_packages = @broken_packages.select { |p| p['state'] != 'unresolvable' }
@broken_packages = @broken_packages.reject { |p| p['state'] == 'unresolvable' }
end
end
end
Expand Down

0 comments on commit 6afc656

Please sign in to comment.