Skip to content

Commit

Permalink
Adopt to the new backend routes
Browse files Browse the repository at this point in the history
In f0e7fce @mls introduced a project wide API
for _jobhistory, this adopts the code to it. Also change it to return objects
instead of strings for easier consumption.
  • Loading branch information
hennevogel committed Dec 18, 2018
1 parent 8708e2e commit 76520e1
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 15 deletions.
83 changes: 68 additions & 15 deletions src/api/lib/backend/api/build_results/job_history.rb
Expand Up @@ -5,26 +5,79 @@ module BuildResults
class JobHistory
extend Backend::ConnectionHelper

# Returns the worker status
# @return [String]
def self.not_failed(project_name, repository_name, arch_name, limit)
http_get(['/build/:project/:repository/:arch/_jobhistory', project_name,
repository_name, arch_name],
params: { limit: limit, code: ['succeeded', 'unchanged'] }, expand: [:code])
def self.for_project(project_name:, filter: { limit: nil, endtime_start: nil, endtime_end: nil, code: nil, package: nil }, raw: false)
filter.compact!
begin
results = http_get(['/build/:project/_jobhistory', project_name], params: filter, expand: [:code])
rescue Backend::Error
return_value = raw ? '<jobhistlist />' : []
return return_value
end
return results if raw
build_local_jobhistory(jobhistory_xml: results)
end

# Return all for a package
def self.all_for_package(project_name, package_name, repository_name, arch_name, limit = 100)
http_get(['/build/:project/:repository/:arch/_jobhistory', project_name,
repository_name, arch_name],
params: { limit: limit, package: package_name })
def self.for_package(project_name:, package_name:, repository_name:, arch_name:, filter: { limit: nil, endtime_start: nil, endtime_end: nil, code: nil }, raw: false)
filter.compact!

begin
results = http_get(['/build/:project/:repository/:arch/_jobhistory', project_name,
repository_name, arch_name], params: filter.merge!(package: package_name), expand: [:code])
rescue Backend::Error
return_value = raw ? '<jobhistlist />' : []
return return_value
end
return results if raw
build_local_jobhistory(jobhistory_xml: results, overwrite_attributes: { repository: repository_name, arch: arch_name })
end

def self.for_repository_and_arch(project_name:, repository_name:, arch_name:, filter: { limit: nil, endtime_start: nil, endtime_end: nil, code: nil }, raw: false)
filter.compact!

begin
results = http_get(['/build/:project/:repository/:arch/_jobhistory', project_name,
repository_name, arch_name], params: filter, expand: [:code])
rescue Backend::Error
return_value = raw ? '<jobhistlist />' : []
return return_value
end
return results if raw
build_local_jobhistory(jobhistory_xml: results, overwrite_attributes: { repository: repository_name, arch: arch_name })
end

def self.last_failures(project_name, package_name, repository_name, arch_name)
http_get(['/build/:project/:repository/:arch/_jobhistory', project_name,
repository_name, arch_name],
params: { package: package_name, code: 'lastfailures' })
# We need overwrite_attributes because the backend omits repo/arch in the output when we
# ask it for a package.
def self.build_local_jobhistory(jobhistory_xml: '<jobhistlist></jobhistlist>', overwrite_attributes: {})
jobhistory_hash = Xmlhash.parse(jobhistory_xml)
local_job_history = []

jobhistory_hash.elements('jobhist').each_with_index do |jobhistory, index|
prev_srcmd5 = jobhistory_hash.elements('jobhist')[index - 1].try(:fetch, 'srcmd5', nil)
attributes = { repository: jobhistory['repository'],
arch: jobhistory['arch'],
package: jobhistory['package'],
revision: jobhistory['rev'],
srcmd5: jobhistory['srcmd5'],
package_version: jobhistory['versrel'],
build_counter: jobhistory['bcnt'],
ready_time: jobhistory['readytime'].to_i,
start_time: jobhistory['starttime'].to_i,
end_time: jobhistory['endtime'].to_i,
total_time: jobhistory['endtime'].to_i - jobhistory['starttime'].to_i,
code: jobhistory['code'],
worker_id: jobhistory['workerid'],
host_arch: jobhistory['hostarch'],
reason: jobhistory['reason'],
verifymd5: jobhistory['verifymd5'],
prev_srcmd5: prev_srcmd5 }.merge!(overwrite_attributes)

local_job_history << LocalJobHistory.new(attributes)
end

local_job_history.reverse
end

private_class_method :build_local_jobhistory
end
end
end
Expand Down
1 change: 1 addition & 0 deletions src/api/lib/backend/connection_helper.rb
Expand Up @@ -103,6 +103,7 @@ def rename_params(params, renames)
def expand_params(params, expand)
expanded_params = []
expand.each do |key|
next if params[key].is_a?(String)
expanded_params += params.delete(key).map { |value| value.to_query(key) } if params.key?(key)
end
expanded_params += [params.to_query] unless params.empty?
Expand Down

0 comments on commit 76520e1

Please sign in to comment.