Class: HtmlReport

Inherits:
Object
  • Object
show all
Defined in:
lib/tipster/reports/html_report.rb

Instance Method Summary collapse

Constructor Details

#initialize(commit_id = nil) ⇒ HtmlReport

Returns a new instance of HtmlReport.



10
11
12
13
# File 'lib/tipster/reports/html_report.rb', line 10

def initialize(commit_id = nil)
   @risk_report = File.temp 'risk_report.html'
	generate html commit_id
end

Instance Method Details

#code_churn_details(code_churn_status) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/tipster/reports/html_report.rb', line 72

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

#code_ratio_details(code_ratio_status) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/tipster/reports/html_report.rb', line 59

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

#display_in_browserObject



41
42
43
# File 'lib/tipster/reports/html_report.rb', line 41

def display_in_browser
	Launchy.open('file:///' << @risk_report)
end

#file_details(change_list) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/tipster/reports/html_report.rb', line 45

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


152
153
154
155
156
# File 'lib/tipster/reports/html_report.rb', line 152

def footer
	"
	  </body>
	</html>"
end

#generate(source) ⇒ Object



37
38
39
# File 'lib/tipster/reports/html_report.rb', line 37

def generate(source)
	File.open(@risk_report, 'w') {|f| f.write(source) }
end

#headerObject



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/tipster/reports/html_report.rb', line 84

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

#html(commit_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/tipster/reports/html_report.rb', line 15

def html(commit_id)

   is_valid_repository = RepositoryContext.valid_repository?
   is_valid_commit = RepositoryContext.valid_commit_id? commit_id

   if !is_valid_repository
     return 'Invalid repository path.'
   end

   if !is_valid_commit
     return 'Invalid commit ID'
   end

	code_ratio_presenter = CodeRatioPresenter.new commit_id
	code_ratio_status = code_ratio_presenter.status

   code_churn_presenter = CodeChurnPresenter.new commit_id
   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