Skip to content

Commit

Permalink
[frontend] Drop BuildReasonFile model
Browse files Browse the repository at this point in the history
The BuildReasonFile model was abstracting the _reason file that is
stored in the backend.
Though the only place where this method was used we parsed the raw xml
and created another object (PackageBuildReason) out of it.

Because of that it makes sense to drop this model and use a Backend::Api
call like we already do elsewhere.

In addition this solves an issue caused by BuildReasonFile#to_s returning
nil when the file isn't available or invalid.

Kudos for the idea goes to @DavidKang
  • Loading branch information
bgeuken committed Jun 25, 2018
1 parent 1cab3fd commit 2b108f0
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 28 deletions.
20 changes: 0 additions & 20 deletions src/api/app/models/build_reason_file.rb

This file was deleted.

15 changes: 7 additions & 8 deletions src/api/app/models/package.rb
Expand Up @@ -1450,14 +1450,13 @@ def self.what_depends_on(project, package, repository, architecture)
def last_build_reason(repo, arch, package_name = nil)
repo = repo.name if repo.is_a? Repository

xml_data = BuildReasonFile.new(
project_name: project.name,
package_name: package_name || name,
repo: repo,
arch: arch
)

data = Xmlhash.parse(xml_data.to_s)
begin
build_reason = Backend::Api::BuildResults::Status.build_reason(project.name, package_name || name, repo, arch)
rescue ActiveXML::Transport::NotFoundError
return PackageBuildReason.new
end

data = Xmlhash.parse(build_reason)
# ensure that if 'packagechange' exists, it is an Array and not a Hash
# Bugreport: https://github.com/openSUSE/open-build-service/issues/3230
data['packagechange'] = [data['packagechange']] if data && data['packagechange'].is_a?(Hash)
Expand Down
4 changes: 4 additions & 0 deletions src/api/lib/backend/api/build_results/status.rb
Expand Up @@ -18,6 +18,10 @@ def self.job_status(project_name, package_name, repository_name, architecture_na
http_get(['/build/:project/:repository/:architecture/:package/_jobstatus', project_name, repository_name, architecture_name, package_name])
end

def self.build_reason(project_name, package_name, repository_name, architecture_name)
http_get(['/build/:project/:repository/:architecture/:package/_reason', project_name, repository_name, architecture_name, package_name])
end

# Returns the result view for a build
# @return [String]
def self.build_result(project_name, package_name, repository_name, architecture_name)
Expand Down

0 comments on commit 2b108f0

Please sign in to comment.