-
Notifications
You must be signed in to change notification settings - Fork 17
Fix theme toggle issue on "How it works " page and Implement Cache Busting #259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Rudra-rps
wants to merge
10
commits into
OWASP-BLT:main
Choose a base branch
from
Rudra-rps:feat/theme_toggle_how_it_works
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
221a952
Fix theme toggle binding and disable dev caching
Rudra-rps 1f4b658
resolve merge conflictS
Rudra-rps 59868f1
Fixes copilot review around Cache control, Dark mode fallback, DOMCon…
Rudra-rps ed268fb
implement content-hash cache busting for static assets
Rudra-rps 8357801
Merge remote-tracking branch 'upstream/main' into feat/theme_toggle_h…
Rudra-rps b9d5f9c
resolved conflicts markers
Rudra-rps 6ff0a55
Fix error reporting safety, theme accessibility, and asset fingerprin…
Rudra-rps add8e61
Sanitize all frontend error reporting paths
Rudra-rps ce579e1
resolved flagged issues by coderabbit
Rudra-rps b09c98e
Merge origin/main into feat/theme_toggle_how_it_works
Rudra-rps File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| { | ||
| "error-reporter.js": "error-reporter.71a8b085.js", | ||
| "how-it-works.js": "how-it-works.3ebd3397.js", | ||
| "theme.js": "theme.196e3e21.js" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // Global error reporter: forwards JS errors to the backend, | ||
| // which relays them to the configured SLACK_ERROR_WEBHOOK. | ||
| (function () { | ||
| function safeTruncate(text, maxLen) { | ||
| var str = String(text || ''); | ||
| if (str.length <= maxLen) return str; | ||
| return str.slice(0, Math.max(0, maxLen - 1)) + '…'; | ||
| } | ||
|
|
||
| function redactSensitive(text) { | ||
| var str = String(text || ''); | ||
| // Redact obvious key/value secrets and auth-like tokens. | ||
| str = str.replace(/(authorization|token|apikey|api[_-]?key|password|passwd|cookie|set-cookie|session|secret|bearer)\s*[:=]\s*([^\s,;]+)/gi, '$1:[redacted]'); | ||
| // Redact email addresses. | ||
| str = str.replace(/[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}/gi, '[redacted-email]'); | ||
| // Redact long token-like strings. | ||
| str = str.replace(/\b[A-Za-z0-9_\-]{24,}\b/g, '[redacted-token]'); | ||
| return str; | ||
| } | ||
|
|
||
| function sendPayload(payload) { | ||
| try { | ||
| var body = JSON.stringify(payload); | ||
|
|
||
| // Prefer sendBeacon (good for unload), fallback to fetch if beacon fails. | ||
| var ok = false; | ||
| try { | ||
| ok = navigator.sendBeacon('/api/client-error', body); | ||
| } catch (e) { | ||
| ok = false; | ||
| } | ||
|
|
||
| if (!ok) { | ||
| fetch('/api/client-error', { | ||
| method: 'POST', | ||
| headers: { 'Content-Type': 'application/json' }, | ||
| body: body, | ||
| keepalive: true, | ||
| }).catch(function () { }); | ||
| } | ||
| } catch (e) { /* ignore reporting failures */ } | ||
| } | ||
|
|
||
| function reportError(errorType, message, stack, extra) { | ||
| var payload = Object.assign( | ||
| { error_type: errorType, message: message, stack: stack || '' }, | ||
| extra || {} | ||
| ); | ||
| sendPayload(payload); | ||
| } | ||
|
|
||
| // 1) Catch runtime errors + resource loading errors (capture=true is important for resources) | ||
| window.addEventListener('error', function (event) { | ||
| // Resource errors (script/img/link) often have event.target and no event.error | ||
| var target = event.target || {}; | ||
| var resourceUrl = target.src || target.href; | ||
|
|
||
| if (resourceUrl && (target.tagName === 'SCRIPT' || target.tagName === 'LINK' || target.tagName === 'IMG')) { | ||
| reportError( | ||
| 'ResourceError', | ||
| 'Failed to load or execute resource', | ||
| (event.error && event.error.stack) || '', | ||
| { url: location.href, resource: resourceUrl } | ||
| ); | ||
| return; | ||
| } | ||
|
|
||
| // Normal runtime error (ReferenceError/TypeError/etc.) | ||
| reportError( | ||
| (event.error && event.error.name) || 'Error', | ||
| event.message || (event.error && event.error.message) || String(event.error) || 'Unknown error', | ||
| (event.error && event.error.stack) || '', | ||
| { url: location.href, line: event.lineno, col: event.colno } | ||
| ); | ||
| }, true); | ||
|
|
||
| // 2) Catch unhandled promise rejections | ||
| window.addEventListener('unhandledrejection', function (event) { | ||
| var reason = event.reason || {}; | ||
| reportError( | ||
| (reason.name) || 'UnhandledRejection', | ||
| reason.message || String(reason), | ||
| reason.stack || '', | ||
| { url: location.href } | ||
| ); | ||
| }); | ||
|
|
||
| // 3) Forward handled errors that are logged via console.error | ||
| // This helps when "real errors" are caught by try/catch and only logged. | ||
| (function hookConsoleError() { | ||
| var original = console.error; | ||
| console.error = function () { | ||
| try { | ||
| var args = Array.prototype.slice.call(arguments); | ||
| var errors = args.filter(function (a) { return a instanceof Error; }); | ||
|
|
||
| if (errors.length > 0) { | ||
| var primary = errors[0]; | ||
| var message = redactSensitive(primary.name + ': ' + (primary.message || '')); | ||
| var stack = redactSensitive(primary.stack || ''); | ||
| reportError( | ||
| primary.name || 'ConsoleError', | ||
| safeTruncate(message, 300), | ||
| safeTruncate(stack || message, 2000), | ||
| { | ||
| url: location.href, | ||
| source: 'console.error:unhandled', | ||
| report_channel: 'dedupe-candidate', | ||
| error_count: String(errors.length), | ||
| } | ||
| ); | ||
| } | ||
| } catch (e) { /* ignore */ } | ||
|
|
||
| return original.apply(console, arguments); | ||
| }; | ||
| })(); | ||
| })(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| // Interactive Score Calculator for BLT-Leaf "How It Works" Page | ||
|
|
||
| function calculateScore() { | ||
| // Get input values | ||
| const ciPassed = parseInt(document.getElementById('ciPassed').value); | ||
| const ciFailed = parseInt(document.getElementById('ciFailed').value); | ||
| const approvals = parseInt(document.getElementById('approvals').value); | ||
| const changesRequested = parseInt(document.getElementById('changesRequested').value); | ||
| const conversations = parseInt(document.getElementById('conversations').value); | ||
| const responseRate = parseInt(document.getElementById('responseRate').value); | ||
|
|
||
| // Update displayed values | ||
| document.getElementById('ciPassedValue').textContent = ciPassed; | ||
| document.getElementById('ciFailedValue').textContent = ciFailed; | ||
| document.getElementById('approvalsValue').textContent = approvals; | ||
| document.getElementById('changesRequestedValue').textContent = changesRequested; | ||
| document.getElementById('conversationsValue').textContent = conversations; | ||
| document.getElementById('responseRateValue').textContent = responseRate + '%'; | ||
|
|
||
| // Calculate CI Score | ||
| const totalChecks = ciPassed + ciFailed; | ||
| let ciScore = 0; | ||
| let ciConfidence = 'Low'; | ||
| let ciConfidenceBadge = 'badge-low'; | ||
|
|
||
| if (totalChecks > 0) { | ||
| ciScore = (ciPassed / totalChecks) * 100; | ||
| ciConfidence = 'High'; | ||
| ciConfidenceBadge = 'badge-high'; | ||
| } else { | ||
| // No checks run - low confidence, assume failure | ||
| ciScore = 0; | ||
| ciConfidence = 'Low'; | ||
| ciConfidenceBadge = 'badge-low'; | ||
| } | ||
|
|
||
| // Calculate Review Score | ||
| let reviewScore = 0; | ||
| let reviewConfidence = 'Medium'; | ||
| let reviewConfidenceBadge = 'badge-medium'; | ||
|
|
||
| if (approvals > 0 && changesRequested === 0) { | ||
| reviewScore = 100; | ||
| reviewConfidence = 'High'; | ||
| reviewConfidenceBadge = 'badge-high'; | ||
| } else if (approvals > 0 && changesRequested > 0) { | ||
| reviewScore = 50; | ||
| reviewConfidence = 'Medium'; | ||
| reviewConfidenceBadge = 'badge-medium'; | ||
| } else if (approvals === 0 && changesRequested > 0) { | ||
| reviewScore = 0; | ||
| reviewConfidence = 'High'; | ||
| reviewConfidenceBadge = 'badge-high'; | ||
| } else { | ||
| // No approvals, no changes requested | ||
| reviewScore = 0; | ||
| reviewConfidence = 'Medium'; | ||
| reviewConfidenceBadge = 'badge-medium'; | ||
| } | ||
|
|
||
| // Response Score (direct mapping) | ||
| const responseScore = responseRate; | ||
| let responseConfidence = 'High'; | ||
| let responseConfidenceBadge = 'badge-high'; | ||
|
|
||
| if (responseRate < 50) { | ||
| responseConfidence = 'Low'; | ||
| responseConfidenceBadge = 'badge-low'; | ||
| } else if (responseRate < 80) { | ||
| responseConfidence = 'Medium'; | ||
| responseConfidenceBadge = 'badge-medium'; | ||
| } | ||
|
|
||
| // Calculate Overall Score | ||
| // Formula: (CI × 0.4) + (Review × 0.4) + (Response × 0.2) - (3 × conversations) | ||
| let overallScore = (ciScore * 0.4) + (reviewScore * 0.4) + (responseScore * 0.2); | ||
|
|
||
| // Deduct 3 points per unresolved conversation | ||
| overallScore = Math.max(0, overallScore - (conversations * 3)); | ||
|
|
||
| // Determine overall status | ||
| let overallStatus = ''; | ||
| let overallColor = ''; | ||
|
|
||
| if (overallScore >= 80) { | ||
| overallStatus = '✅ Merge Ready'; | ||
| overallColor = 'text-green-600 dark:text-green-400'; | ||
| } else if (overallScore >= 60) { | ||
| overallStatus = '⚠️ Needs Attention'; | ||
| overallColor = 'text-yellow-600 dark:text-yellow-400'; | ||
| } else { | ||
| overallStatus = '❌ Not Ready'; | ||
| overallColor = 'text-red-600 dark:text-red-400'; | ||
| } | ||
|
|
||
| // Update UI | ||
| const overallScoreElement = document.getElementById('overallScore'); | ||
| overallScoreElement.textContent = Math.round(overallScore) + '%'; | ||
| overallScoreElement.className = overallColor + ' text-5xl font-bold mb-2'; | ||
|
|
||
| document.getElementById('overallStatus').textContent = overallStatus; | ||
|
|
||
| document.getElementById('ciScoreDisplay').innerHTML = | ||
| `${Math.round(ciScore)}% <span class="${ciConfidenceBadge} px-2 py-0.5 rounded text-xs ml-1">${ciConfidence}</span>`; | ||
|
|
||
| document.getElementById('reviewScoreDisplay').innerHTML = | ||
| `${Math.round(reviewScore)}% <span class="${reviewConfidenceBadge} px-2 py-0.5 rounded text-xs ml-1">${reviewConfidence}</span>`; | ||
|
|
||
| document.getElementById('responseScoreDisplay').innerHTML = | ||
| `${Math.round(responseScore)}% <span class="${responseConfidenceBadge} px-2 py-0.5 rounded text-xs ml-1">${responseConfidence}</span>`; | ||
| } | ||
|
|
||
| // Initialize calculator on page load | ||
| document.addEventListener('DOMContentLoaded', function () { | ||
| // Attach event listeners to all range inputs | ||
| const rangeInputs = document.querySelectorAll('input[type="range"]'); | ||
| rangeInputs.forEach(input => { | ||
| input.addEventListener('input', calculateScore); | ||
| }); | ||
|
|
||
| // Initial calculation | ||
| calculateScore(); | ||
| }); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.