Skip to content

Commit

Permalink
Merge pull request #3059 from DavidKang/show-job-history
Browse files Browse the repository at this point in the history
[webui][api] Show jobhistory
  • Loading branch information
bgeuken committed May 4, 2017
2 parents 2d299c2 + c8084e2 commit 5eaaad2
Show file tree
Hide file tree
Showing 28 changed files with 2,612 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/api/app/assets/javascripts/webui/application/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -154,4 +154,8 @@ $( document ).ready(function() {
link.text(link_text);
});
});

$('#jobhistory-table').dataTable({
order: [[0, 'desc']]
});
});
5 changes: 5 additions & 0 deletions src/api/app/assets/stylesheets/webui/application/package.scss
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,8 @@ table.repostatus td {
overflow-y: auto;
}
}

.subtitle {
font-size: 1em;
margin-top: 0;
}
38 changes: 38 additions & 0 deletions src/api/app/controllers/webui/packages/job_history_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
module Webui
module Packages
class JobHistoryController < WebuiController
before_action :set_project
before_action :set_package
before_action :set_repository
before_action :set_architecture

def index
@jobshistory = @package.jobhistory_list(@project, @repository.name, @architecture.name)
end

private

def set_package
@package = ::Package.get_by_project_and_name( @project.to_param, params[:package_name],
{use_source: false, follow_project_links: true, follow_multibuild: true} )
rescue APIException
flash[:error] = "Package \"#{params[:package_name]}\" not found in project \"#{params[:project]}\""
redirect_to project_show_path(project: @project, nextstatus: 404)
end

def set_repository
@repository = @project.repositories.find_by(name: params[:repository])
return @repository if @repository
flash[:error] = "Couldn't find repository '#{params[:repository]}'."
redirect_to(package_binaries_path(package: @package.name, project: @project.name, repository: params[:repository]))
end

def set_architecture
@architecture = ::Architecture.archcache[params[:arch]]
return @architecture if @architecture
flash[:error] = "Couldn't find architecture '#{params[:arch]}'."
redirect_to(package_binaries_path(package: @package.name, project: @project.name, repository: params[:repository]))
end
end
end
end
9 changes: 9 additions & 0 deletions src/api/app/helpers/webui/package_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,13 @@ def nbsp(text)
# But at this point we know it truly is html safe
result.html_safe
end

def humanize_time(seconds)
[[60, :s], [60, :m], [24, :h]].map do |count, name|
if seconds > 0
seconds, n = seconds.divmod(count)
"#{n.to_i}#{name}"
end
end.compact.reverse.join(' ')
end
end
4 changes: 4 additions & 0 deletions src/api/app/models/local_job_history.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class LocalJobHistory
include ActiveModel::Model
attr_accessor :revision, :build_counter, :worker_id, :host_arch, :reason, :ready_time, :start_time, :end_time, :total_time, :code
end
22 changes: 22 additions & 0 deletions src/api/app/models/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,28 @@ def buildresults(prj = project)
local_build_results
end

def jobhistory_list(project, repository, arch, limit = 100)
results = Jobhistory.find_hashed(project: project.name, package: name,
repository: repository, arch: arch,
limit: limit)

local_jobs_history = []
results.elements('jobhist').reverse_each do |result|
local_jobs_history << LocalJobHistory.new(revision: result['rev'],
build_counter: result['bcnt'],
worker_id: result['workerid'],
host_arch: result['hostarch'],
reason: result['reason'],
ready_time: result['readytime'].to_i,
start_time: result['starttime'].to_i,
end_time: result['endtime'].to_i,
total_time: result['endtime'].to_i - result['starttime'].to_i,
code: result['code'])
end

local_jobs_history
end

def service_error(revision = nil)
revision ||= serviceinfo.try{ to_hash['xsrcmd5'] }
PackageServiceErrorFile.new(project_name: project.name, package_name: name).to_s(rev: revision)
Expand Down
1 change: 1 addition & 0 deletions src/api/app/views/webui/package/binaries.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
<% if found_statistics %>
<%= link_to sprited_text('server_chart', 'Show'), { :action => 'statistics', :project => @project, :package => @package, :repository => @repository, :arch => result['arch'] } %> used resources
<% end %>
<%= link_to sprited_text('text_indent','Job history'), index_package_job_history_path(project: @project, package_name: @package, repository: @repository, arch: result['arch']), class: '' %> list
</p>
<% end %>
36 changes: 36 additions & 0 deletions src/api/app/views/webui/packages/job_history/_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<%= content_for :ready_function do %>
$("#advanced_tabs_trigger").click(function() {
$("#advanced_tabs").show();
$("#advanced_list_item").hide();
});
<% end %>

<div class="box-header header-tabs" id="package_tabs">
<ul>
<% if @package.name == "patchinfo" %>
<%= tab 'details', 'Details', :controller => '/webui/patchinfo', :action => 'show' %>
<% end %>
<%= tab 'overview', 'Overview', :controller => '/webui/package', :action => 'show' %>
<% unless @spider_bot -%>
<%= tab 'repositories', 'Repositories', :controller => '/webui/repositories', :action => 'index' %>
<%= tab 'revisions', 'Revisions', :controller => '/webui/package', :action => 'revisions' %>
<%= tab 'requests', "Requests", :controller => '/webui/package', :action => 'requests' %>
<%= tab 'users', 'Users', :controller => '/webui/package', :action => 'users' %>
<% end -%>
<% if is_advanced_tab? %>
<%= content_for :ready_function do %>
$("#advanced_tabs").show();
<% end %>
<% else %>
<li id="advanced_list_item"><a href="#" id="advanced_tabs_trigger">Advanced</a></li>
<% end %>
</ul>
<% unless @spider_bot -%>
<div id="advanced_tabs" class="hidden">
<ul>
<%= tab 'attributes', 'Attributes', controller: '/webui/attribute', :package => @package, :project => @project, :action => 'index' %>
<%= tab 'meta', 'Meta', :controller => '/webui/package', :action => 'meta' %>
</ul>
</div>
<% end -%>
</div>
40 changes: 40 additions & 0 deletions src/api/app/views/webui/packages/job_history/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
:ruby
@pagetitle = "Job history of #{@project} / #{@package}"
@metarobots = 'index,nofollow'

= render partial: 'tabs'

%h3= @pagetitle
%h6.subtitle
Repository / Architecture: #{params[:repository]} / #{params[:arch]}

%table#jobhistory-table
%thead
%th Revision
%th Time
%th Reason
%th Status Code
%th Build Time
%th Worker
%th
%tbody
- @jobshistory.each do |jobhistory|
%tr
%td
= jobhistory.revision
%td
= time_tag(Time.at(jobhistory.ready_time))
%td
= jobhistory.reason
%td
= jobhistory.code
%td
= humanize_time(jobhistory.total_time)
%td
= jobhistory.worker_id
%td
- title = "Package:#{@package.name} | revision:#{jobhistory.revision}"
= link_to sprite_tag('req-showdiff', title: title),
package_show_path(project: @project,
package: @package,
rev: jobhistory.revision)
29 changes: 18 additions & 11 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,18 @@ def self.public_or_about_path?(request)
mount Peek::Railtie => '/peek'

cons = {
arch: %r{[^\/]*},
binary: %r{[^\/]*},
filename: %r{[^\/]*},
id: %r{\d*},
login: %r{[^\/]*},
package: %r{[^\/]*},
project: %r{[^\/]*},
repository: %r{[^\/]*},
service: %r{\w[^\/]*},
title: %r{[^\/]*},
user: %r{[^\/]*}
arch: %r{[^\/]*},
binary: %r{[^\/]*},
filename: %r{[^\/]*},
id: %r{\d*},
login: %r{[^\/]*},
package: %r{[^\/]*},
package_name: %r{[^\/]*},
project: %r{[^\/]*},
repository: %r{[^\/]*},
service: %r{\w[^\/]*},
title: %r{[^\/]*},
user: %r{[^\/]*}
}

constraints(WebuiMatcher) do
Expand Down Expand Up @@ -146,6 +147,12 @@ def self.public_or_about_path?(request)
get 'package/files/:project/:package' => :show, constraints: cons
end

resources :packages, only: [], param: :name do
resource :job_history, controller: 'webui/packages/job_history', only: [] do
get '/:project/:repository/:arch' => :index, as: :index, constraints: cons
end
end

controller 'webui/patchinfo' do
post 'patchinfo/new_patchinfo' => :new_patchinfo
post 'patchinfo/updatepatchinfo' => :updatepatchinfo
Expand Down

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

Loading

0 comments on commit 5eaaad2

Please sign in to comment.