solidstats 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f9d5cde522de317145141315b74583eab36c12dfa77587a1c1271647ffe2dc34
4
+ data.tar.gz: 74aace50f49490af9b00f410bf96385ed7eecd728001cb45bc9b836c02999a51
5
+ SHA512:
6
+ metadata.gz: 8105421d981e6b919c47ce9fa09490cbb1b2638c1f8dde567a2ebd609da7b72066fa34df7af5c04b8d3f4a088e7480dfd5832f818d4a8fe8cda7f6d429e5928e
7
+ data.tar.gz: '09fe1f31b0a6cce1bf003ff769ded70682273ebe326da32e6ab1bf2b48d08e0cc0d35cddf0bbe39b3e5395e590b67c96def52c5f3a802c262022ac4df648e53c'
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright MezbahAlam
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,26 @@
1
+
2
+ Solidstats is a local-only Rails engine that shows your project's health at `/solidstats`.
3
+
4
+ ## Features
5
+ - Bundler Audit scan
6
+ - Rubocop offense count
7
+ - TODO/FIXME tracker
8
+ - Test coverage summary
9
+
10
+ ## Installation
11
+
12
+ ```ruby
13
+ # Gemfile (dev only)
14
+ group :development do
15
+ gem 'solidstats', path: '../solidstats'
16
+ end
17
+ ```
18
+
19
+ Then mount in `config/routes.rb`:
20
+
21
+ ```ruby
22
+ mount Solidstats::Engine => '/solidstats' if Rails.env.development?
23
+ ```
24
+
25
+ ## License
26
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/setup"
2
+
3
+ load "rails/tasks/statistics.rake"
4
+
5
+ require "bundler/gem_tasks"
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
10
+ * files in this directory. Styles in this file should be added after the last require_* statement.
11
+ * It is generally better to create a new file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ module Solidstats
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,55 @@
1
+ module Solidstats
2
+ class DashboardController < ApplicationController
3
+ AUDIT_CACHE_FILE = Rails.root.join("tmp", "solidstats_audit.json")
4
+ AUDIT_CACHE_HOURS = 12 # Configure how many hours before refreshing
5
+
6
+ def index
7
+ @audit_output = fetch_audit_output
8
+ @rubocop_output = "JSON.parse(`rubocop --format json`)"
9
+ @todo_count = `grep -r -E \"TODO|FIXME|HACK\" app lib | wc -l`.to_i
10
+ @coverage = "read_coverage_percent"
11
+ end
12
+
13
+ private
14
+
15
+ def fetch_audit_output
16
+ # Check if cache file exists and is recent enough
17
+ if File.exist?(AUDIT_CACHE_FILE)
18
+ cached_data = JSON.parse(File.read(AUDIT_CACHE_FILE))
19
+ last_run_time = Time.parse(cached_data["timestamp"])
20
+
21
+ # Use cached data if it's less than AUDIT_CACHE_HOURS old
22
+ if Time.now - last_run_time < AUDIT_CACHE_HOURS.hours
23
+ return cached_data["output"]
24
+ end
25
+ end
26
+
27
+ # Cache expired or doesn't exist, run the audit
28
+ raw_output = `bundle audit check --update --format json`
29
+ json_part = raw_output[/\{.*\}/m] # extract JSON starting from first '{'
30
+ audit_output = JSON.parse(json_part) rescue { error: "Failed to parse JSON" }
31
+
32
+ # Save to cache file with timestamp
33
+ cache_data = {
34
+ "output" => audit_output,
35
+ "timestamp" => Time.now.iso8601
36
+ }
37
+
38
+ # Ensure the tmp directory exists
39
+ FileUtils.mkdir_p(File.dirname(AUDIT_CACHE_FILE))
40
+
41
+ # Write the cache file
42
+ File.write(AUDIT_CACHE_FILE, JSON.generate(cache_data))
43
+
44
+ audit_output
45
+ end
46
+
47
+ def read_coverage_percent
48
+ file = Rails.root.join("coverage", ".last_run.json")
49
+ return 0 unless File.exist?(file)
50
+
51
+ data = JSON.parse(File.read(file))
52
+ data.dig("result", "covered_percent").to_f.round(2)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,4 @@
1
+ module Solidstats
2
+ module ApplicationHelper
3
+ end
4
+ end
@@ -0,0 +1,4 @@
1
+ module Solidstats
2
+ class ApplicationJob < ActiveJob::Base
3
+ end
4
+ end
@@ -0,0 +1,6 @@
1
+ module Solidstats
2
+ class ApplicationMailer < ActionMailer::Base
3
+ default from: "from@example.com"
4
+ layout "mailer"
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Solidstats
2
+ class ApplicationRecord < ActiveRecord::Base
3
+ self.abstract_class = true
4
+ end
5
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Solidstats</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= yield :head %>
9
+
10
+ <%= stylesheet_link_tag "solidstats/application", media: "all" %>
11
+ </head>
12
+ <body>
13
+
14
+ <%= yield %>
15
+
16
+ </body>
17
+ </html>
@@ -0,0 +1,5 @@
1
+ <% if @audit_output.include?('No vulnerabilities found') %>
2
+ <p class="status-badge success">All Clear</p>
3
+ <% else %>
4
+ <p class="status-badge warning">Issues Found</p>
5
+ <% end %>
@@ -0,0 +1,506 @@
1
+ <div id="audit-details" class="details-panel hidden">
2
+ <%= render partial: 'solidstats/dashboard/audit/audit_summary' %>
3
+
4
+ <% results = @audit_output.dig("results") || [] %>
5
+ <% if results.empty? %>
6
+ <%= render partial: 'solidstats/dashboard/audit/no_vulnerabilities' %>
7
+ <% else %>
8
+ <%= render partial: 'solidstats/dashboard/audit/audit_filters' %>
9
+ <%= render partial: 'solidstats/dashboard/audit/vulnerabilities_table', locals: { results: results } %>
10
+ <%= render partial: 'solidstats/dashboard/audit/vulnerability_details', locals: { results: results } %>
11
+ <% end %>
12
+ </div>
13
+
14
+ <style>
15
+ /* Audit details specific styles */
16
+ .audit-summary {
17
+ margin-bottom: 2rem;
18
+ }
19
+
20
+ .audit-summary-header {
21
+ display: flex;
22
+ justify-content: space-between;
23
+ align-items: center;
24
+ border-bottom: 1px solid #dee2e6;
25
+ padding-bottom: 1rem;
26
+ margin-bottom: 1rem;
27
+ }
28
+
29
+ .audit-summary-header h3 {
30
+ margin: 0;
31
+ font-size: 1.2rem;
32
+ font-weight: 600;
33
+ }
34
+
35
+ .audit-stats {
36
+ display: flex;
37
+ gap: 2rem;
38
+ margin-bottom: 1rem;
39
+ }
40
+
41
+ .audit-stat {
42
+ text-align: center;
43
+ }
44
+
45
+ .audit-stat .stat-value {
46
+ display: block;
47
+ font-size: 1.8rem;
48
+ font-weight: 700;
49
+ color: #333;
50
+ }
51
+
52
+ .audit-stat .stat-label {
53
+ font-size: 0.9rem;
54
+ color: #666;
55
+ }
56
+
57
+ .audit-filters {
58
+ display: flex;
59
+ gap: 0.5rem;
60
+ margin-bottom: 1rem;
61
+ }
62
+
63
+ .filter-btn {
64
+ background: #f1f1f1;
65
+ border: none;
66
+ padding: 0.4rem 0.8rem;
67
+ border-radius: 4px;
68
+ font-size: 0.85rem;
69
+ cursor: pointer;
70
+ }
71
+
72
+ .filter-btn.active {
73
+ background: #007bff;
74
+ color: white;
75
+ }
76
+
77
+ .vulnerability-row.high-severity {
78
+ background-color: #fff8f8;
79
+ }
80
+
81
+ .solution {
82
+ display: flex;
83
+ align-items: center;
84
+ gap: 0.5rem;
85
+ }
86
+
87
+ .copy-btn {
88
+ background: #e9ecef;
89
+ border: none;
90
+ border-radius: 4px;
91
+ padding: 0.3rem 0.5rem;
92
+ font-size: 0.8rem;
93
+ cursor: pointer;
94
+ display: flex;
95
+ align-items: center;
96
+ gap: 0.25rem;
97
+ }
98
+
99
+ .copy-btn:hover {
100
+ background: #dee2e6;
101
+ }
102
+
103
+ .copy-btn.copied {
104
+ background: #d4edda;
105
+ color: #155724;
106
+ }
107
+
108
+ .no-vulnerabilities {
109
+ text-align: center;
110
+ padding: 2rem;
111
+ color: #155724;
112
+ }
113
+
114
+ /* Styling for details section */
115
+ .vulnerabilities-details-section {
116
+ margin-top: 3rem;
117
+ border-top: 1px solid #dee2e6;
118
+ padding-top: 1.5rem;
119
+ }
120
+
121
+ .vulnerabilities-details-section.hidden .md-container {
122
+ display: none;
123
+ }
124
+
125
+ .vulnerabilities-details-section h3 {
126
+ display: flex;
127
+ justify-content: space-between;
128
+ align-items: center;
129
+ }
130
+
131
+ .toggle-details-btn {
132
+ background: #f1f1f1;
133
+ border: none;
134
+ padding: 0.4rem 0.8rem;
135
+ border-radius: 4px;
136
+ font-size: 0.85rem;
137
+ cursor: pointer;
138
+ transition: background-color 0.2s;
139
+ }
140
+
141
+ .toggle-details-btn:hover {
142
+ background: #e2e6ea;
143
+ }
144
+
145
+ .toggle-details-btn[aria-expanded="true"] {
146
+ background: #007bff;
147
+ color: white;
148
+ }
149
+
150
+ .vulnerability-detail {
151
+ margin-bottom: 2rem;
152
+ padding: 1.5rem;
153
+ border-radius: 8px;
154
+ background-color: #f8f9fa;
155
+ border: 1px solid #dee2e6;
156
+ }
157
+
158
+ .vulnerability-detail.high-severity {
159
+ border-left: 4px solid #dc3545;
160
+ }
161
+
162
+ .vulnerability-title {
163
+ margin-top: 0;
164
+ margin-bottom: 0.75rem;
165
+ font-size: 1.1rem;
166
+ font-weight: 600;
167
+ }
168
+
169
+ .vulnerability-meta {
170
+ display: flex;
171
+ gap: 1rem;
172
+ margin-bottom: 1rem;
173
+ font-size: 0.85rem;
174
+ }
175
+
176
+ .cve, .date {
177
+ color: #666;
178
+ }
179
+
180
+ .description {
181
+ font-size: 0.9rem;
182
+ line-height: 1.5;
183
+ white-space: pre-line;
184
+ }
185
+
186
+ .advisory-link {
187
+ margin-top: 1rem;
188
+ }
189
+
190
+ .advisory-link a {
191
+ color: #007bff;
192
+ text-decoration: none;
193
+ }
194
+
195
+ .advisory-link a:hover {
196
+ text-decoration: underline;
197
+ }
198
+
199
+ .view-details-link {
200
+ margin-left: 0.5rem;
201
+ font-size: 0.85rem;
202
+ color: #007bff;
203
+ text-decoration: none;
204
+ }
205
+
206
+ .view-details-link:hover {
207
+ text-decoration: underline;
208
+ }
209
+
210
+ /* Markdown-style container */
211
+ .md-container {
212
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
213
+ color: #24292e;
214
+ background-color: #f6f8fa;
215
+ border: 1px solid #e1e4e8;
216
+ border-radius: 6px;
217
+ padding: 0;
218
+ overflow: hidden;
219
+ transition: all 0.3s ease;
220
+ }
221
+
222
+ /* Each vulnerability as a markdown entry */
223
+ .md-entry {
224
+ border-bottom: 1px solid #e1e4e8;
225
+ padding: 24px;
226
+ background-color: #ffffff;
227
+ }
228
+
229
+ .md-entry:last-child {
230
+ border-bottom: none;
231
+ }
232
+
233
+ .md-entry.high-severity {
234
+ border-left: 4px solid #d73a49;
235
+ }
236
+
237
+ /* Markdown heading style */
238
+ .md-heading {
239
+ font-size: 1.5rem;
240
+ font-weight: 600;
241
+ margin: 0 0 16px 0;
242
+ color: #24292e;
243
+ font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
244
+ }
245
+
246
+ /* Metadata tags */
247
+ .md-metadata {
248
+ display: flex;
249
+ flex-wrap: wrap;
250
+ gap: 8px;
251
+ margin-bottom: 16px;
252
+ }
253
+
254
+ .md-tag {
255
+ display: inline-block;
256
+ padding: 2px 8px;
257
+ border-radius: 12px;
258
+ font-size: 12px;
259
+ font-weight: 500;
260
+ background-color: #e1e4e8;
261
+ }
262
+
263
+ .md-tag.cve {
264
+ background-color: #0366d6;
265
+ color: white;
266
+ }
267
+
268
+ .md-tag.ghsa {
269
+ background-color: #6f42c1;
270
+ color: white;
271
+ }
272
+
273
+ .md-tag.severity.high, .md-tag.severity.critical {
274
+ background-color: #d73a49;
275
+ color: white;
276
+ }
277
+
278
+ .md-tag.severity.medium {
279
+ background-color: #f6a33e;
280
+ color: white;
281
+ }
282
+
283
+ .md-tag.severity.low {
284
+ background-color: #1b7c83;
285
+ color: white;
286
+ }
287
+
288
+ .md-tag.severity.unknown {
289
+ background-color: #6a737d;
290
+ color: white;
291
+ }
292
+
293
+ .md-date {
294
+ font-size: 12px;
295
+ color: #6a737d;
296
+ }
297
+
298
+ /* Markdown divider */
299
+ .md-divider {
300
+ height: 1px;
301
+ background-color: #e1e4e8;
302
+ margin: 16px 0;
303
+ }
304
+
305
+ /* Markdown content */
306
+ .md-content {
307
+ font-size: 14px;
308
+ line-height: 1.6;
309
+ color: #24292e;
310
+ margin-bottom: 16px;
311
+ }
312
+
313
+ .md-content p {
314
+ margin-bottom: 16px;
315
+ }
316
+
317
+ .md-content p:last-child {
318
+ margin-bottom: 0;
319
+ }
320
+
321
+ /* Code block style */
322
+ .md-code-block {
323
+ margin: 16px 0;
324
+ background-color: #f6f8fa;
325
+ border-radius: 6px;
326
+ overflow: hidden;
327
+ }
328
+
329
+ .md-code-header {
330
+ padding: 8px 16px;
331
+ background-color: #f1f8ff;
332
+ border-bottom: 1px solid #d0d7de;
333
+ color: #57606a;
334
+ font-size: 12px;
335
+ font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
336
+ }
337
+
338
+ .md-code {
339
+ margin: 0;
340
+ padding: 16px;
341
+ overflow-x: auto;
342
+ font-size: 13px;
343
+ line-height: 1.45;
344
+ color: #24292e;
345
+ font-family: SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
346
+ }
347
+
348
+ /* Link style */
349
+ .md-link {
350
+ display: flex;
351
+ align-items: center;
352
+ margin-top: 16px;
353
+ }
354
+
355
+ .md-link-icon {
356
+ margin-right: 4px;
357
+ font-size: 14px;
358
+ }
359
+
360
+ .md-link a {
361
+ color: #0366d6;
362
+ text-decoration: none;
363
+ font-size: 14px;
364
+ }
365
+
366
+ .md-link a:hover {
367
+ text-decoration: underline;
368
+ }
369
+
370
+ /* Back to top link */
371
+ .md-back {
372
+ margin-top: 24px;
373
+ font-size: 14px;
374
+ text-align: right;
375
+ }
376
+
377
+ .back-to-top {
378
+ color: #586069;
379
+ text-decoration: none;
380
+ }
381
+
382
+ .back-to-top:hover {
383
+ color: #0366d6;
384
+ text-decoration: underline;
385
+ }
386
+
387
+ .vulnerabilities-details-section h3 {
388
+ margin-bottom: 16px;
389
+ font-size: 1.2rem;
390
+ font-weight: 600;
391
+ color: #24292e;
392
+ }
393
+ </style>
394
+
395
+ <script>
396
+ document.addEventListener('DOMContentLoaded', function() {
397
+ // Copy functionality for solution buttons
398
+ document.querySelectorAll('.copy-btn').forEach(function(button) {
399
+ button.addEventListener('click', function() {
400
+ const solution = this.getAttribute('data-solution');
401
+ navigator.clipboard.writeText(solution).then(() => {
402
+ // Change button appearance temporarily
403
+ const originalText = this.innerHTML;
404
+ this.innerHTML = '<span class="copy-icon">✓</span> Copied!';
405
+ this.classList.add('copied');
406
+
407
+ setTimeout(() => {
408
+ this.innerHTML = originalText;
409
+ this.classList.remove('copied');
410
+ }, 2000);
411
+ });
412
+ });
413
+ });
414
+
415
+ // Toggle details section functionality
416
+ const toggleBtn = document.querySelector('.toggle-details-btn');
417
+ if (toggleBtn) {
418
+ toggleBtn.addEventListener('click', function() {
419
+ const detailsSection = document.querySelector('.vulnerabilities-details-section');
420
+ const isHidden = detailsSection.classList.contains('hidden');
421
+
422
+ if (isHidden) {
423
+ // Show the details
424
+ detailsSection.classList.remove('hidden');
425
+ this.textContent = 'Hide Details';
426
+ this.setAttribute('aria-expanded', 'true');
427
+
428
+ // Scroll to the details section
429
+ detailsSection.scrollIntoView({
430
+ behavior: 'smooth',
431
+ block: 'start'
432
+ });
433
+ } else {
434
+ // Hide the details
435
+ detailsSection.classList.add('hidden');
436
+ this.textContent = 'Show Details';
437
+ this.setAttribute('aria-expanded', 'false');
438
+ }
439
+ });
440
+ }
441
+
442
+ // View details link functionality - simplified to avoid duplication
443
+ document.querySelectorAll('.view-details-link').forEach(function(link) {
444
+ link.addEventListener('click', function(e) {
445
+ e.preventDefault();
446
+ const target = this.getAttribute('href');
447
+ const detailsSection = document.querySelector('.vulnerabilities-details-section');
448
+
449
+ // Show the details section if it's hidden
450
+ if (detailsSection.classList.contains('hidden')) {
451
+ detailsSection.classList.remove('hidden');
452
+ const toggleBtn = document.querySelector('.toggle-details-btn');
453
+ toggleBtn.textContent = 'Hide Details';
454
+ toggleBtn.setAttribute('aria-expanded', 'true');
455
+ }
456
+
457
+ // Scroll to the specific vulnerability
458
+ setTimeout(() => {
459
+ document.querySelector(target).scrollIntoView({
460
+ behavior: 'smooth',
461
+ block: 'start'
462
+ });
463
+ }, 100);
464
+ });
465
+ });
466
+
467
+ // Filter functionality
468
+ document.querySelectorAll('.filter-btn').forEach(function(button) {
469
+ button.addEventListener('click', function() {
470
+ const filter = this.getAttribute('data-filter');
471
+
472
+ // Update active button
473
+ document.querySelectorAll('.filter-btn').forEach(btn => btn.classList.remove('active'));
474
+ this.classList.add('active');
475
+
476
+ // Handle special case for copy-solutions
477
+ if (filter === 'copy-solutions') {
478
+ const solutions = [];
479
+ document.querySelectorAll('.vulnerability-row').forEach(function(row) {
480
+ const gem = row.cells[0].textContent.trim();
481
+ const solution = row.querySelector('.solution code')?.textContent.trim() || "No patch available";
482
+ solutions.push(`${gem}: ${solution}`);
483
+ });
484
+
485
+ // Copy all solutions to clipboard
486
+ navigator.clipboard.writeText(solutions.join('\n')).then(() => {
487
+ alert('All solutions copied to clipboard!');
488
+ });
489
+
490
+ return;
491
+ }
492
+
493
+ // Filter the vulnerability rows
494
+ document.querySelectorAll('.vulnerability-row').forEach(function(row) {
495
+ const isHigh = row.classList.contains('high-severity');
496
+
497
+ if (filter === 'all') {
498
+ row.style.display = '';
499
+ } else if (filter === 'high') {
500
+ row.style.display = isHigh ? '' : 'none';
501
+ }
502
+ });
503
+ });
504
+ });
505
+ });
506
+ </script>
@@ -0,0 +1,5 @@
1
+ <div class="audit-filters">
2
+ <button class="filter-btn active" data-filter="all">All</button>
3
+ <button class="filter-btn" data-filter="high">High Severity</button>
4
+ <button class="filter-btn" data-filter="copy-solutions">Copy All Solutions</button>
5
+ </div>