Skip to content

Commit

Permalink
[webui][api] Refactor project buildresult
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidKang committed May 12, 2017
1 parent ae02264 commit b8d2f31
Show file tree
Hide file tree
Showing 12 changed files with 269 additions and 87 deletions.
35 changes: 1 addition & 34 deletions src/api/app/controllers/webui/project_controller.rb
Expand Up @@ -219,40 +219,7 @@ def add_group

def buildresult
check_ajax
@buildresult = Buildresult.find_hashed(project: params[:project], view: 'summary')
fill_status_cache
# convert build result
myarray = []
@buildresult.elements('result') do |result|
result['summary'].elements('statuscount') do |sc|
myarray << [result['repository'], result['arch'], Buildresult.code2index(sc['code']), sc['count']]
end
end
myarray.sort!
repos = []
orepo = nil
oarch = nil
archs = nil
counts = nil
myarray.each do |repo, arch, code, count|
if orepo != repo
archs << [oarch, counts] if oarch
oarch = nil
repos << [orepo, archs] if orepo
archs = []
end
orepo = repo
if oarch != arch
archs << [oarch, counts] if oarch
counts = []
end
oarch = arch
counts << [Buildresult.index2code(code), count]
end
archs << [oarch, counts] if oarch
repos << [orepo, archs] if orepo
@buildresult = repos
render partial: 'buildstatus'
render partial: 'buildstatus', locals: { project: @project, buildresults: @project.buildresults }
end

def delete_dialog
Expand Down
19 changes: 19 additions & 0 deletions src/api/app/models/buildresult.rb
Expand Up @@ -59,4 +59,23 @@ def self.index2code(index)
def self.final_status?(status)
status.in?(["succeeded", "failed", "unresolvable", "broken", "disabled", "excluded"])
end

def self.summary(project_name)
results = find_hashed(project: project_name, view: 'summary')
local_build_results = {}
results.elements('result').sort {|a, b| a['repository'] <=> b['repository']}.each do |result|
build = LocalBuildResult.new(repository: result['repository'], architecture: result['arch'], code: result['code'], state: result['state'])

build.summary = []
result['summary'].elements('statuscount').each do |count|
build.summary << StatusCount.new(code: count['code'], count: count['count'])
end

build.summary.sort! { |a, b| code2index(a.code) <=> code2index(b.code) }
local_build_results[result['repository']] ||= []
local_build_results[result['repository']] << build
end

local_build_results
end
end
2 changes: 1 addition & 1 deletion src/api/app/models/local_build_result.rb
@@ -1,4 +1,4 @@
class LocalBuildResult
include ActiveModel::Model
attr_accessor :repository, :architecture, :code, :state, :details
attr_accessor :repository, :architecture, :code, :state, :details, :summary
end
4 changes: 4 additions & 0 deletions src/api/app/models/project.rb
Expand Up @@ -215,6 +215,10 @@ def cleanup_before_destroy
end
private :cleanup_before_destroy

def buildresults
Buildresult.summary(name)
end

def subprojects
Project.where("name like ?", "#{name}:%")
end
Expand Down
4 changes: 4 additions & 0 deletions src/api/app/models/status_count.rb
@@ -0,0 +1,4 @@
class StatusCount
include ActiveModel::Model
attr_accessor :code, :count
end
47 changes: 0 additions & 47 deletions src/api/app/views/webui/project/_buildstatus.html.erb

This file was deleted.

61 changes: 61 additions & 0 deletions src/api/app/views/webui/project/_buildstatus.html.haml
@@ -0,0 +1,61 @@
#project-buildstatus
- if buildresults.blank?
- if project.remoteurl
%p
%i This project is just used to get referenced for using remote resources.
- elsif project.repositories.empty?
%p
%i
This project currently has
no #{link_to 'build targets', controller: :repositories, action: :distributions, project: project.name}
defined.
- else
%p
%i No build result available
- else
%table.repostatus
- buildresults.each do |repository, builds|
- builds.sort_by(&:architecture).each_with_index do |build, index|
%tr
- if index.zero?
%td.repo{ rowspan: builds.length }
= link_to(word_break(repository, 12),
{ action: :state,
project: project.name,
repository: repository,
controller: :repositories },
{ title: "Repository #{repository}" })

%td.arch{ title: "#{repository} summary" }
= repo_status_icon(build.state, build.details)
= link_to(build.architecture, { action: :monitor,
"#{valid_xml_id('repo_' + repository)}": 1,
"arch_#{build.architecture}": 1,
project: project.name,
succeeded: 1,
failed: 1,
unresolvable: 1,
broken: 1,
blocked: 1,
dispatching: 1,
scheduled: 1,
building: 1,
finished: 1,
signing: 1,
locked: 1,
deleting: 1,
defaults: 0 }, rel: 'nofollow', class: 'nowrap')

%td.nowrap{ style: "width: 1%" }
- build.summary.each do |status_count|
%span{ class: "status_#{status_count.code.to_s.gsub(/[- ]/, '_')}" }
= link_to("#{status_count.code}: #{status_count.count}",
{ action: :monitor,
"#{valid_xml_id('repo_' + repository)}": 1,
"arch_#{build.architecture}": 1,
project: params[:project],
"#{status_count.code}": 1,
defaults: 0 }, rel: 'nofollow', class: 'nowrap')

= sprite_tag('help', title: Buildresult.status_description(status_count.code))
%br
44 changes: 44 additions & 0 deletions src/api/spec/cassettes/Buildresult/_summary/1_2_1.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/api/spec/cassettes/Buildresult/_summary/1_2_2.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/api/spec/cassettes/Buildresult/_summary/1_2_3.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 15 additions & 4 deletions src/api/spec/controllers/webui/project_controller_spec.rb
Expand Up @@ -397,13 +397,24 @@
end

describe 'GET #buildresult' do
it 'assigns the buildresult' do
summary = Xmlhash::XMLHash.new({'statuscount' => {'code' => 'succeeded', 'count' => 1} })
build_result = { 'result' => Xmlhash::XMLHash.new({'repository' => 'openSUSE', 'arch' => 'x86_64', 'summary' => summary }) }
let(:summary) { Xmlhash::XMLHash.new({'statuscount' => {'code' => 'succeeded', 'count' => '1'} }) }
let(:build_result) do
{ 'result' => Xmlhash::XMLHash.new({'repository' => 'openSUSE',
'arch' => 'x86_64', 'code' => 'published', 'state' => 'published', 'summary' => summary }) }
end

let(:local_build_result) { assigns(:buildresults)['openSUSE'].first }
let(:result) { { architecture: 'x86_64', code: 'published', repository: 'openSUSE', state: 'published' } }
let(:status_count) { local_build_result.summary.first }

before do
allow(Buildresult).to receive(:find_hashed).and_return(Xmlhash::XMLHash.new(build_result))
get :buildresult, params: { project: project_with_package }, xhr: true
expect(assigns(:buildresult)).to match_array([["openSUSE", [["x86_64", [[:succeeded, 1]]]]]])
end

it { expect(assigns(:buildresults)).to have_key('openSUSE') }
it { expect(local_build_result).to have_attributes(result) }
it { expect(status_count).to have_attributes({ code: 'succeeded', count: '1' }) }
end

describe 'GET #delete_dialog' do
Expand Down

0 comments on commit b8d2f31

Please sign in to comment.