#!/usr/bin/env ruby require 'sinatra/base' require 'sinatra/assetpack' require 'haml' require 'json' require 'time' require File.join(File.expand_path("..", File.dirname(__FILE__)),"lib","nailed") require File.join(File.expand_path("..", File.dirname(__FILE__)),"db","database") class App < Sinatra::Base ROOT_PATH = File.join(File.expand_path("..", File.dirname(__FILE__))) self.set :root, File.join(ROOT_PATH, "lib") set :public_folder, File.join(ROOT_PATH, "public") set :views, File.join(ROOT_PATH, "views") set :bind, '0.0.0.0' register Sinatra::AssetPack assets { serve '/js', from: '../public/vendor/js' serve '/css', from: '../public/vendor/css' serve '/images', from: '../public/images' js :foundation, '/js/foundation.min.js', [ '/js/external/*.js', '/js/foundation/foundation.js', '/js/foundation/*.js' ] js :morris, '/js/morris.min.js', [ '/js/morris/morris.js', '/js/morris/raphael.js' ] css :foundation, '/css/foundation.min.css', [ '/css/foundation.css', '/css/normalize.css' ] css :morris, '/css/morris.min.js', [ '/css/morris.css' ] js_compression :jsmin css_compression :simple } before do @products = Nailed::PRODUCTS["products"].map{|p,v| v["versions"]}.flatten @product_query = @products.join('&product=') @github_repos = Pullrequest.all(:order => [:created_at.desc]).map(&:repository_rname).uniq end helpers do def get_trends(action, item) case action when :bug trend = Bugtrend.all(:product_name => item) when :pull trend = Pulltrend.all(:repository_rname => item) when :l3 trend = L3Trend.all end trend_clone = trend.clone begin interval = (trend.length/20.0).round last_iter_open = trend.first.open trend.each do |bt| if trend.index(bt) % interval != 0 if bt != trend.last if bt.open == last_iter_open trend_clone.delete(bt) end end else next end last_iter_open = bt.open end rescue ZeroDivisionError end trend_clone.to_json end end # define sinatra routes get '/' do @l3trend = get_trends(:l3, nil) @bugtop = [] Nailed::PRODUCTS["products"].each do |product,values| values["versions"].each do |version| p = Product.get(version) open = Bugreport.count(:product_name => p.name, :is_open => true) @bugtop << {label: p.name, value: open} unless open == 0 end end @bugtop = @bugtop.to_json haml :index end Nailed::PRODUCTS["products"].each do |product,values| values["versions"].each do |version| get "/#{version.gsub(/ /,'_')}/bugzilla" do @product = version @bugtrend = get_trends(:bug, version) @allbugs = Bugreport.all(:product_name => version).to_json @allopenbugs = (Bugreport.all(:product_name => version, :is_open => true) - Bugreport.all(:product_name => version, :whiteboard.like => "%openL3%", :is_open => true)).sort! {|a,b| Time.parse(b.last_change_time.to_s).to_i <=> Time.parse(a.last_change_time.to_s).to_i} @allopenl3bugs = (Bugreport.all(:product_name => version, :is_open => true, :whiteboard.like => "%openL3%")).sort! {|a,b| Time.parse(b.last_change_time.to_s).to_i <=> Time.parse(a.last_change_time.to_s).to_i} @bugprio = [] {"P1 - Urgent" => "p1", "P2 - High" => "p2", "P3 - Medium" => "p3", "P4 - Low" => "p4", "P5 - None" => "p5"}.each_pair do |key,val| @bugprio << {"bugprio" => key, val => Bugreport.count(:product_name => version, :priority => key, :is_open => true)} end @bugprio = @bugprio.to_json haml :bugzilla end end end @github_repos = Pullrequest.all(:order => [:created_at.desc]).map(&:repository_rname).uniq @github_repos.each do |repo| get "/github/#{repo}" do @repo = repo @org = Repository.get(repo).organization_oname @github_url_all_pulls = "https://github.com/#{@org}/#{@repo}/pulls" @allpulls = Pullrequest.all(:repository_rname => repo).sort! {|a,b| b.pr_number <=> a.pr_number} @pulltrend = get_trends(:pull, repo) haml :github end end run! if app_file == $0 end