Skip to content

Commit

Permalink
Move checks and missing_checks into Project
Browse files Browse the repository at this point in the history
It's not related to staging projects, it's just that we currently
only test/display it in that context
  • Loading branch information
coolo committed Nov 25, 2018
1 parent b784eae commit 26ca5c0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 49 deletions.
34 changes: 5 additions & 29 deletions src/api/app/models/obs_factory/staging_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ def self.find(distribution, id)
# @return [String] description of the Project object
delegate :description, to: :project

delegate :checks, to: :project
delegate :missing_checks, to: :project

# Checks if the project is adi staging project
#
# @return [Boolean] true if the project is adi staging project
Expand Down Expand Up @@ -192,9 +195,9 @@ def build_state
end

def check_state
if missing_checks.present? || checks.any?(&:pending?)
if missing_checks.present? || checks.pending.exists?
:testing
elsif checks.any?(&:failed?)
elsif checks.failed.exists?
:failed
else
:acceptable
Expand Down Expand Up @@ -228,35 +231,8 @@ def overall_state
@state
end

def checks
fetch_status if @checks.nil?
@checks
end

def missing_checks
fetch_status if @missing_checks.nil?
@missing_checks
end

protected

def fetch_status
@checks = []
@missing_checks = []
repositories.each do |repo|
add_status(repo)
repo.repository_architectures.each do |repo_arch|
add_status(repo_arch)
end
end
end

def add_status(checkable)
status = checkable.current_status_report
@missing_checks += status.missing_checks
@checks += status.checks
end

# Used internally to calculate #broken_packages and #building_repositories
def set_buildinfo
buildresult = Xmlhash.parse(Backend::Api::BuildResults::Status.failed_results(name))
Expand Down
30 changes: 30 additions & 0 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1690,6 +1690,14 @@ def dashboard
packages.find_by(name: 'dashboard')
end

def checks
Status::Check.where(status_report: combined_status_reports)
end

def missing_checks
@missing_checks ||= calculate_missing_checks
end

private

def discard_cache
Expand Down Expand Up @@ -1744,6 +1752,28 @@ def has_local_distribution(project_name, repository)
linked_repository.name == repository
end
end

def status_reports(checkables)
status_reports = Status::Report.where(checkable: checkables)
result = {}
status_reports.where(uuid: checkables.map(&:build_id)).find_each do |report|
result[report.checkable] = report
end

checkables.each do |checkable|
result[checkable] ||= Status::Report.new(checkable: checkable)
end

result.values
end

def combined_status_reports
@combined_status_reports ||= status_reports(repositories) | status_reports(repository_architectures)
end

def calculate_missing_checks
combined_status_reports.map(&:missing_checks).flatten
end
end
# rubocop:enable Metrics/ClassLength

Expand Down
16 changes: 0 additions & 16 deletions src/api/app/models/staging/staging_project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,6 @@ def unassign_managers_group(managers)
relationships.find_by(group: managers, role: role).try(:destroy!)
end

def checks
@checks ||= Status::Check.where(status_reports_id: publish_reports | built_reports)
end

def missing_checks
@missing_checks ||= (publish_reports + built_reports).map(&:missing_checks).flatten
end

private

def cache_problems
Expand Down Expand Up @@ -150,14 +142,6 @@ def status_reports(checkables)
result.values
end

def publish_reports
@publish_reports ||= status_reports(repositories)
end

def built_reports
@built_reports ||= status_reports(repository_architectures)
end

def check_state
return :testing if missing_checks.present? || checks.pending.exists?
return :failed if checks.failed.exists?
Expand Down
4 changes: 0 additions & 4 deletions src/api/app/models/status/checkable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ module Status::Checkable
serialize :required_checks, Array
has_many :status_reports, as: :checkable, class_name: 'Status::Report', dependent: :destroy
end

def current_status_report
status_reports.find_or_initialize_by(uuid: build_id)
end
end

0 comments on commit 26ca5c0

Please sign in to comment.