Permalink
Browse files

Build an HTML report that contains information about each heuristic a…

…nd whether or not it passed for a given commit.
  • Loading branch information...
1 parent f8aa166 commit 4326a5a2d377f0abd42eed86b569132453b516c7 @robertgreiner committed Jan 12, 2012
Showing with 142 additions and 0 deletions.
  1. +142 −0 lib/tipster/reports/html_report.rb
@@ -0,0 +1,142 @@
+require 'rubygems'
+require 'launchy'
+require_relative '../presenters/code_ratio_presenter'
+require_relative '../presenters/code_churn_presenter'
+
+class HtmlReport
+
+ def initialize
+ generate html
+ end
+
+ def html
+ code_ratio_presenter = CodeRatioPresenter.new
+ code_ratio_status = code_ratio_presenter.status
+
+ code_churn_presenter = CodeChurnPresenter.new
+ code_churn_status = code_churn_presenter.status
+
+ header << file_details(code_ratio_presenter.change_list) << code_ratio_details(code_ratio_status) << code_churn_details(code_churn_status) << footer
+ end
+
+ def generate(source)
+ File.open('risk_report.html', 'w') {|f| f.write(source) }
+ end
+
+ def display_in_browser
+ Launchy.open('risk_report.html')
+ end
+
+ def file_details(change_list)
+ file_details = "
+ <h2>What files am I checking in?</h2>
+ <div class=\"commitDetails\">
+ <ul>"
+
+ change_list.each { |x| file_details << "<li>" << x.file_name << "</li>" }
+
+ file_details << "
+ </ul>
+ </div>
+ "
+ end
+
+ def code_ratio_details(code_ratio_status)
+ "
+ <h2>Is my code risky?</h2>
+ <div class=\"heuristicStatus #{code_ratio_status.status}\">
+ <ul>
+ <li class=\"result\">#{code_ratio_status.status}</li>
+ <li class=\"heuristicName\">Code Ratio</li>
+ <li class=\"description\">#{code_ratio_status.description}</li>
+ </ul>
+ </div>
+ "
+ end
+
+ def code_churn_details(code_churn_status)
+ "
+ <div class=\"heuristicStatus #{code_churn_status.status}\">
+ <ul>
+ <li class=\"result\">#{code_churn_status.status}</li>
+ <li class=\"heuristicName\">Code Churn</li>
+ <li class=\"description\">#{code_churn_status.description}</li>
+ </ul>
+ </div>
+ "
+ end
+
+ def header
+ "
+ <!DOCTYPE html>
+ <html lang=\"en\">
+ <head>
+ <meta charset=\"utf-8\" />
+ <title>Check-In Risk Report</title>
+
+ <style media=\"screen\" type=\"text/css\">
+ body {
+ font-family: Helvetica, \"Helvetica Neue\", Arial;
+ font-size: 16px;
+ color: #333;
+ }
+
+ h1 {
+ font-size: 20px;
+ }
+
+ h2 {
+ font-size: 16px;
+ }
+
+ .commitDetails {
+ font-size: 12px;
+ }
+
+ .heuristicStatus ul, .heuristicStatus li {
+ display: inline;
+ }
+
+ .heuristicStatus ul li {
+ display: block;
+ padding: 1px 5px 0px 5px;
+ float: left;
+ }
+
+ .Risky {
+ border-left: 5px solid #9e2b20;
+ height: 20px;
+ margin-bottom: 15px;
+ }
+
+ .Safe {
+ border-left: 5px solid #0af510;
+ height: 20px;
+ margin-bottom: 15px;
+ }
+
+ .heuristicName {
+ color: #555;
+ }
+
+ .result {
+ font-weight: bold;
+ }
+
+ .description {
+ color: #999;
+ }
+ </style>
+
+ </head>
+ <body>
+ <h1>Commit Risk Report</h1>
+ "
+ end
+
+ def footer
+ "
+ </body>
+ </html>"
+ end
+end

0 comments on commit 4326a5a

Please sign in to comment.