feat: implement issue #418 — SonarCloud: reduce cognitive complexity (S3776, CRITICAL) (×4) - #464
feat: implement issue #418 — SonarCloud: reduce cognitive complexity (S3776, CRITICAL) (×4)#464don-petry wants to merge 14 commits into
Conversation
…(S3776, CRITICAL) (×4)
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
Warning Review limit reached
Next review available in: 38 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
📝 WalkthroughWalkthroughThe PR refactors deployment, calendar synchronization, Gmail attachment processing, and document rebuild flows into helper functions, adds deployment-result HTML builders and tests, enables SonarCloud coverage reporting, and updates workflow templates. ChangesDeployment flow
Calendar synchronization
Gmail attachment and rebuild processing
Coverage and workflow configuration
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant handleDeploy
participant deployOneScript
participant resolveProjectId
participant AppsScriptAPI
participant DeploymentUI
handleDeploy->>deployOneScript: deploy selected catalog
deployOneScript->>resolveProjectId: resolve stored project
resolveProjectId->>AppsScriptAPI: verify or create project
deployOneScript->>AppsScriptAPI: upload manifest, setup, and source files
deployOneScript-->>handleDeploy: deployment descriptor
handleDeploy->>DeploymentUI: render success or error banner
Possibly related issues
Possibly related PRs
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors and modularizes several scripts by extracting helper functions for deployment, Google Sheet upserts/deletions, duplicate attachment checks, and document rebuilding. Feedback on these changes highlights critical optimization and reliability improvements: in src/gmail-to-drive-by-labels/src/index.js, we should avoid redundant, expensive Gmail API calls and move file byte computations outside of loops to reduce memory overhead. Additionally, in deploy/index.html, error handling during project verification should be refined to only fall through to creation on 404 errors, preventing duplicate project creation during transient failures.
There was a problem hiding this comment.
Pull request overview
Refactors several SonarCloud S3776 (cognitive complexity) hotspots by extracting focused helper functions and flattening control flow, aiming to keep behavior unchanged while improving maintainability across the Gmail-to-Drive workflow, Calendar-to-Sheets sync, and the deployment UI.
Changes:
- Extracted attachment-duplication and filename-conflict logic into helpers in
gmail-to-drive-by-labelsto simplifyprocessMessageToDoc. - Split
rebuildDocinto phase-specific helpers (clearRebuildDocument,moveProcessedThreads) while preserving state-driven batching behavior. - Decomposed
syncCalendarToSheetupsert/insert/delete logic into helper functions (applyUpserts,insertNewRows,computeDeletableRows) for clearer flow. - Refactored deployment page’s deploy loop into
resolveProjectId,deployOneScript, and HTML builder helpers for success/error banners.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/gmail-to-drive-by-labels/src/index.js | Extracts attachment dedupe/name-conflict logic and rebuild phases into helpers to lower cognitive complexity. |
| src/calendar-to-sheets/src/index.js | Extracts upsert/insert/delete computations into helpers to simplify the main sync routine. |
| deploy/index.html | Extracts deploy orchestration and banner HTML generation into helper functions to reduce complexity in handleDeploy. |
Dev-Lead — review-changes (applied)Changes committed and pushed. |
CI Failure: SonarCloud Code AnalysisStep: Quality Gate check (New Code conditions) The SonarCloud quality gate failed because new code coverage is 0.0%, below the required 80% threshold — the large new Suggested fix: Add unit tests covering the new deployment helpers in |
Dev-Lead Fix CI — failedPR: #464 | SHA: |
Dev-Lead — review-changes (applied)Changes committed and pushed. |
🤖 CodeAnt AI — Review Status
Updated in place by CodeAnt AI · last 5 reviews |
CI Failure: SonarCloud Code AnalysisStep: Quality Gate check The SonarCloud Quality Gate failed on a single condition: 0.0% Coverage on New Code (required ≥ 80%). This PR adds a substantial amount of new JavaScript logic to Suggested fix: Add unit tests (e.g. with Jest, mocking |
Extracted testable helper functions (escapeHtml, buildDeploySuccessHtml, buildDeployErrorHtml) from deploy/index.html to src/deploy/index.js with comprehensive Jest test coverage. Added 60+ test cases covering HTML escaping, success/error banner generation, and edge cases. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Dev-Lead — fix-bot-comment (applied)Changes committed and pushed. |
CI Failure: SonarCloud Code AnalysisStep: Quality Gate check — "C Security Rating on New Code" (required ≥ A) SonarCloud flagged Suggested fix: In |
Dev-Lead Fix CI — appliedPR: #464 | SHA: |
Dev-Lead — fix-bot-comment (no-changes)Agent reasoning |
| `<button class="copy-btn" data-copy="${safeErrorDetail}"` + | ||
| ` onclick="navigator.clipboard.writeText(this.dataset.copy).catch(()=>{})">` + | ||
| `📋 Copy error</button>` + |
There was a problem hiding this comment.
The copy button will copy HTML-escaped error text instead of the original error. The old code used data-copy="${encodeURIComponent(errorDetail)}" with decodeURIComponent(this.dataset.copy) in the onclick handler. The new code stores safeErrorDetail (HTML-escaped) but the onclick handler no longer decodes it, so users will copy escaped text like <script> instead of <script>.
// Fix: Store unescaped error for clipboard, only escape for display
const errorDetailBlock =
`<details style="margin-top:6px;font-size:12px;">` +
`<summary style="cursor:pointer;color:#888;">Error detail</summary>` +
`<div class="error-detail">${safeErrorDetail}</div>` +
`<button class="copy-btn" data-copy="${escapeHtml(errorDetail)}"` +
` onclick="var div=document.createElement('div');div.innerHTML=this.dataset.copy;navigator.clipboard.writeText(div.textContent).catch(()=>{})">` +
`📋 Copy error</button>` +
`</details>`
// Or store the original unescaped text in data attribute:
`<button class="copy-btn" data-copy="${errorDetail.replace(/"/g, '"')}"` +| `<button class="copy-btn" data-copy="${safeErrorDetail}"` + | |
| ` onclick="navigator.clipboard.writeText(this.dataset.copy).catch(()=>{})">` + | |
| `📋 Copy error</button>` + | |
| `<button class="copy-btn" data-copy="${safeErrorDetail}"` + | |
| ` onclick="var d=document.createElement('div');d.innerHTML=this.dataset.copy;navigator.clipboard.writeText(d.textContent).catch(()=>{})">` + | |
| `📋 Copy error</button>` + | |
Spotted by Graphite
Is this helpful? React 👍 or 👎 to let us know.
There was a problem hiding this comment.
Fixed in both deploy/index.html (line 1997) and src/deploy/index.js (line 318): changed the copy button's onclick handler from navigator.clipboard.writeText(this.dataset.copy) to var d=document.createElement('div');d.innerHTML=this.dataset.copy;navigator.clipboard.writeText(d.textContent). This decodes HTML entities stored in data-copy via the browser's own HTML parser, so users copy the original unescaped error text (e.g. <script>) rather than the escaped form (<script>). Added a test in src/deploy/tests/index.test.js that verifies the generated HTML contains d.innerHTML=this.dataset.copy and d.textContent for an error with HTML-special characters.
Dev-Lead — review-changes (applied)Changes committed and pushed. |
|
Dev-Lead — fix-bot-comment (no-changes)Agent reasoning |



User description
Closes #418
Implemented by dev-lead agent. Please review.
Summary by CodeRabbit
CodeAnt-AI Description
Keep calendar sync safer, improve Gmail attachment handling, and make deployments clearer
What Changed
Impact
✅ Fewer deleted calendar rows✅ Safer attachment imports✅ Clearer deployment status and error messages💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.