Skip to content

feat: implement issue #428 — SonarCloud: JavaScript/TypeScript code quality - #438

Closed
don-petry wants to merge 9 commits into
mainfrom
dev-lead/issue-428-20260714-1821
Closed

feat: implement issue #428 — SonarCloud: JavaScript/TypeScript code quality#438
don-petry wants to merge 9 commits into
mainfrom
dev-lead/issue-428-20260714-1821

Conversation

@don-petry

@don-petry don-petry commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Closes #428

Implemented by dev-lead agent. Please review.

Summary by CodeRabbit

  • Bug Fixes

    • Improved deployment input validation and error reporting.
    • Made calendar processing more resilient to missing or unexpected event data.
    • Improved email body cleanup for common reply and forward headers.
    • Preserved attachment extensions more reliably when resolving filename conflicts.
  • Quality Improvements

    • Added test coverage for email body truncation and strengthened UI test synchronization.
    • SonarCloud analysis now includes JavaScript test coverage.
    • Improved escaping and validation across deployment interfaces.

@don-petry
don-petry requested a review from a team as a code owner July 14, 2026 18:51
Copilot AI review requested due to automatic review settings July 14, 2026 18:51
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@don-petry, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 07e4b5ff-3dd8-47fb-8d5c-a78d264d5936

📥 Commits

Reviewing files that changed from the base of the PR and between eb5831d and 570b613.

📒 Files selected for processing (2)
  • .github/workflows/codeql.yml
  • .github/workflows/sonarcloud.yml
📝 Walkthrough

Walkthrough

This PR applies JavaScript quality-rule updates across deployment, installer, calendar, Gmail, and utility code. It adds SonarCloud coverage generation and LCOV configuration, improves UI test synchronization, updates test mocks, and adjusts two workflow template output blocks.

Changes

Code quality and coverage updates

Layer / File(s) Summary
Coverage generation and SonarCloud reporting
.github/workflows/sonarcloud.yml, scripts/check-coverage.js, sonar-project.properties
CI now runs tests with coverage before SonarCloud analysis, and SonarCloud is configured to read the generated LCOV report.
Deployment UI and installer updates
deploy/index.html, deploy/tests/ui.spec.js, gas-installer/Index.html, gas-installer/src/index.js, gas-installer/tests/ui.spec.js
Deployment and installer helpers update validation, escaping, parsing, optional access, file detection, and UI synchronization behavior.
Runtime validation and utility robustness
src/deploy/index.js, src/gas-utils.js, src/calendar-to-briefing-doc/*, src/calendar-to-sheets/src/index.js, test-utils/*
Type validation now uses TypeError; utility logic adopts Node-prefixed imports, optional access, nullish defaults, and simplified iteration and formatting patterns.
Gmail document rebuild handling
src/gmail-to-drive-by-labels/*, src/gas-utils.js
Document generation updates subject and attachment naming behavior, rebuild timing uses Date.now(), and body-cleaning tests cover multiple reply-header patterns.
Workflow template output formatting
.github/skills/bmad-retrospective/workflow.md, .github/skills/bmad-sprint-status/workflow.md
Generated workflow output blocks receive blank-line insertions.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The two .github/skills/bmad-* workflow template edits are unrelated to the SonarCloud code-quality work and appear out of scope. Move the bmad workflow whitespace edits into a separate PR unless they are intentionally part of issue #428.
Docstring Coverage ⚠️ Warning Docstring coverage is 77.78% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the main SonarCloud code-quality work for issue #428 and matches the changeset.
Linked Issues check ✅ Passed The diff applies the expected SonarCloud fixes, test updates, and coverage configuration across the affected files, matching the linked issue scope.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev-lead/issue-428-20260714-1821

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown
Contributor

CI Failure: SonarCloud Code Analysis

Step: Quality Gate check
Root cause: Test failure

SonarCloud's Quality Gate failed because 0.0% Coverage on New Code was reported, against a required threshold of ≥ 80%. The PR modifies several JS files (gas-installer/src/index.js, scripts/check-coverage.js, deploy/index.html) with logic changes (e.g. getFileType, filterGithubItems), but none of the new/changed lines appear to be exercised by any test that contributed to the coverage report submitted for this analysis — so SonarCloud treats the new code as entirely untested.

Suggested fix: Add or extend unit tests (e.g. in deploy/tests/ui.spec.js or a new test file for gas-installer/src/index.js) that directly exercise the changed functions (getFileType, filterGithubItems, and the coverage-script changes), then verify the coverage report (coverage/coverage-final.json) includes those lines before re-running the analysis.

View run logs

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modernizes the codebase by adopting newer JavaScript features, such as optional chaining (?.), Date.now(), Number.parseInt, and node: prefixed built-in imports. It also simplifies several regular expressions, replaces a hardcoded timeout in UI tests with element visibility assertions, and updates error types to TypeError where appropriate. The review feedback correctly points out that using replaceAll with a global regular expression is redundant and potentially risky compared to replace, suggesting a revert for those specific changes.

Comment thread src/gas-utils.js Outdated
Comment thread src/gmail-to-drive-by-labels/src/index.js Outdated
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (no-changes)

No changes were needed for this PR.

@don-petry
don-petry enabled auto-merge (squash) July 14, 2026 18:54
@don-petry
don-petry disabled auto-merge July 14, 2026 18:54
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — fix-reviews (applied)

Changes committed and pushed.

@don-petry
don-petry enabled auto-merge (squash) July 14, 2026 18:57

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR addresses SonarCloud JavaScript/TypeScript code-quality findings across the repo by applying mostly mechanical refactors (optional chaining/nullish coalescing, node: core imports, replaceAll, Number.parseInt, Date.now(), regex simplifications, and small test refactors) while aiming to keep runtime behavior unchanged.

Changes:

  • Modernize JS patterns to satisfy Sonar rules (optional chaining, ??, replaceAll, Number.parseInt, Date.now(), node: imports, simplified regexes).
  • Improve test quality/readability (parameterized Jest test; replace fixed Playwright sleep with an observable UI condition).
  • Tighten type-check error signaling in deploy tooling (TypeError for type validation).

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test-utils/setup.js Switch to require('node:crypto') for core module import.
test-utils/mocks.js Use optional chaining to simplify safe property/method access in mocks.
src/gmail-to-drive-by-labels/tests/code.test.js Update Date mocking to align with Date.now() usage.
src/gmail-to-drive-by-labels/src/index.js Apply Sonar-driven refactors (`
src/gas-utils.js Apply Sonar-driven refactors (regex changes, replaceAll, optional chaining, node:crypto).
src/deploy/index.js Use TypeError for type-check failures.
src/calendar-to-sheets/src/index.js Split sort().forEach() into separate statements to satisfy rule guidance.
src/calendar-to-briefing-doc/tests/index.test.js Replace repetitive tests with it.each parameterized test.
src/calendar-to-briefing-doc/src/index.js Use optional chaining and ?? for clearer defaults/guards.
scripts/check-coverage.js Use node: imports and a for...of loop for branch coverage iteration.
gas-installer/src/index.js Prefer endsWith() and optional chaining in filtering.
gas-installer/Index.html Prefer replaceAll() for HTML escaping helpers.
deploy/tests/ui.spec.js Use node:path and replace fixed waits with DOM visibility synchronization.
deploy/index.html Apply Sonar-driven refactors (remove unused var, regex simplification, optional chaining, Number.parseInt, replaceAll, simplify template usage).

Comment thread src/gas-utils.js Outdated
@don-petry
don-petry disabled auto-merge July 14, 2026 18:57
coderabbitai[bot]
coderabbitai Bot previously approved these changes Jul 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

CI Failure: SonarCloud Code Analysis

Step: Quality Gate
Root cause: Test failure

The Quality Gate failed on a single condition: 0.0% Coverage on New Code, against a required minimum of 80%. This PR changes logic in deploy/index.html and gas-installer/src/index.js (e.g. escapeHtml, buildSetupSource, validateScriptId, and various optional-chaining/replaceAll conversions), but none of those changed lines are exercised by new or updated tests, so SonarCloud reports them as 0% covered.

Suggested fix: Add or extend test cases in deploy/tests/ui.spec.js that directly exercise the modified functions (escapeHtml, buildSetupSource, validateScriptId, and the error-handling branches using optional chaining) so the changed lines in deploy/index.html and gas-installer/src/index.js are covered, then push to re-trigger analysis.

View run logs

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (applied)

Changes committed and pushed.

@github-actions

Copy link
Copy Markdown
Contributor

CI Failure: SonarCloud Code Analysis

Step: Quality Gate
Root cause: Test failure

The SonarCloud Quality Gate failed with 0.0% Coverage on New Code (required ≥ 80%). This PR only touches .html/.js files (syntax modernization: replaceAll, optional chaining, Number.parseInt, an added test assertion in deploy/tests/ui.spec.js) but the coverage report shows none of the changed lines are exercised by instrumented tests, so SonarCloud treats the new code as entirely untested.

Suggested fix: Ensure the coverage job actually runs and uploads a report covering the changed files (deploy/index.html, gas-installer/Index.html, gas-installer/src/index.js) — e.g. confirm deploy/tests/ui.spec.js executes against the modified functions (escapeHtml, buildSetupSource, validateScriptId) with coverage instrumentation enabled and the resulting LCOV/coverage report is passed to the SonarCloud scan step, so the changed lines are counted as covered.

View run logs

@don-petry
don-petry enabled auto-merge (squash) July 14, 2026 19:03
@don-petry
don-petry disabled auto-merge July 14, 2026 19:03
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead Fix CI — applied

PR: #438 | SHA: 74ca8da9be29c0e5a01b571b562b0168874ad690
Fix committed and pushed. Waiting for CI.

@don-petry
don-petry enabled auto-merge (squash) July 14, 2026 19:07
@don-petry
don-petry disabled auto-merge July 14, 2026 19:08
@don-petry
don-petry disabled auto-merge July 16, 2026 14:24
@don-petry
don-petry enabled auto-merge (squash) July 16, 2026 14:27
@don-petry
don-petry disabled auto-merge July 16, 2026 17:43
@don-petry
don-petry enabled auto-merge (squash) July 16, 2026 17:48
@don-petry
don-petry disabled auto-merge July 16, 2026 19:37
@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-lead assessment: All review threads have been addressed and resolved. The only outstanding CI item is the Analyze (python) CodeQL job, which failed with a transient network error (ECONNRESET during CodeQL tool bundle download — not a code issue). A manual re-run of that job should clear it. All other checks pass, tests are green (304/304), and coverage meets thresholds.

@don-petry
don-petry enabled auto-merge (squash) July 16, 2026 19:40
@don-petry
don-petry disabled auto-merge July 16, 2026 21:18
@don-petry
don-petry enabled auto-merge (squash) July 16, 2026 21:20
@don-petry
don-petry disabled auto-merge July 17, 2026 03:39
@don-petry
don-petry enabled auto-merge (squash) July 17, 2026 03:41
@don-petry
don-petry disabled auto-merge July 17, 2026 06:30
@don-petry
don-petry enabled auto-merge (squash) July 17, 2026 06:36
@don-petry
don-petry disabled auto-merge July 17, 2026 10:14
@don-petry

Copy link
Copy Markdown
Collaborator Author

Phase 0 Assessment — CI Failure Triage

The Analyze (python) CodeQL job failed due to a transient network error, not a code issue:

Error: read ECONNRESET
  at TLSWrap.onStreamRead (node:internal/stream_base_commons:216:20)

The runner hit a connection reset while downloading the CodeQL bundle (codeql-bundle-linux64.tar.zst) from GitHub's CDN. The Python source files (analyze_sources.py) were not modified on this branch and contain no CodeQL findings — the JavaScript/TypeScript and Actions scans both passed.

The failed run (ID 29362615699) cannot be re-triggered via the API. A fresh push or manual re-run of the CodeQL workflow will resolve this.

No open human review threads remain. All 304 tests pass locally, lint is clean (0 errors).

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead Agent — Phase 0 Assessment

No open review threads to address. Assessed the one failing CI check:

  • Analyze (python) failed with a transient ECONNRESET network error during CodeQL initialization (not a code issue). The workflow run cannot be retried via CLI. A new push to the branch will trigger a fresh CodeQL scan.

Local verification:

  • ✅ All 304 tests pass (npm test)
  • ✅ Coverage meets thresholds: statements 98.91%, branches 90.07%, functions 98%, lines 100%
  • ✅ Lint and format checks pass (npm run check)

The PR code is correct and ready. The transient CodeQL failure is an infrastructure flake unrelated to the changes.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead Agent — Review Response Assessment

Open human review threads: None to address.

CI assessment:

  • Analyze (python) (failed): Transient ECONNRESET network error during CodeQL initialization — no Python files were modified in this PR, and the failure is unrelated to the code changes. The same CodeQL setup succeeds on main. This is an infrastructure flake that will resolve on next trigger.
  • dev-lead / ci-relay + dev-lead / dispatch (cancelled): Expected lifecycle cancellations of previous dev-lead agent invocations superseded by this session.
  • All other checks: passing ✅

Local verification:

  • All 304 tests pass ✅
  • Coverage: 98.91% statements, 90.07% branches, 98% functions, 100% lines — all above required thresholds ✅
  • Lint: no errors (22 pre-existing warnings in test files, unrelated to this PR) ✅

@don-petry

Copy link
Copy Markdown
Collaborator Author

The Analyze (python) CodeQL check failed due to a transient network error (ECONNRESET while downloading the CodeQL bundle during CI setup) — not caused by any code change in this PR. The same check passes on main. This is a GitHub infrastructure issue; a re-run or re-push should clear it.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — waiting on PR blockers (intent: review-changes)

PR: #438
No changes were committed, but the PR still has blocking checks or reviews (failing or cancelled checks, or changes-requested reviews). The retry cron will re-attempt automatically. Next attempt after: 2026-07-19T21:39:11Z

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (applied)

Changes committed and pushed.

@donpetry-bot

Copy link
Copy Markdown
Contributor

Review — fix requested (cycle 1/3)

The automated review identified the following issues. Please address each one:

Findings to fix

Automated review — NEEDS HUMAN REVIEW

Risk: MEDIUM
Reviewed commit: 570b6133cbb9f3cf00df8e58a79bcda37435640a
Review mode: triage-approved (single reviewer)

Summary

Code-quality modernization pass driven by SonarCloud findings (issue #428): optional chaining, replaceAll, Number.parseInt, node: import prefixes, Date.now(), regex simplifications, plus SonarCloud workflow hardening (step-scoped SONAR_TOKEN, npm ci --ignore-scripts, coverage upload) and a new SHA-pinned CodeQL workflow. The code changes are behavior-preserving and well-tested, but the PR cannot be approved in its current state: it has merge conflicts with main, the core CI suite never ran on the current head SHA, and the new CodeQL workflow conflicts with the repo's already-enabled CodeQL default setup.

Linked issue analysis

Closes #428 (SonarCloud: JavaScript/TypeScript code quality — 58 findings, worst severity MAJOR). The diff substantively addresses the flagged rule categories: S6582 (optional chaining), S7781 (replaceAll), S7773 (Number.parseInt), S7772 (node: imports), S5869 (duplicate character-class entries), S3358 (nested ternaries), S7759 (Date.now), S6557 (endsWith). SonarCloud Quality Gate passed on an earlier commit in this PR. The issue is substantively addressed.

Findings

Blocking:

  1. Merge conflict with mainmergeable: CONFLICTING / mergeStateStatus: DIRTY. The PR must be rebased and conflicts resolved before it can merge.
  2. Core CI did not run on the current head SHA (570b613) — only CodeQL default-setup checks and a skipped dependabot job are attached to this commit. The Node.js test suite, coverage, lint, Playwright, gitleaks, and SonarCloud checks that ran on earlier commits are absent (conflicted PRs cannot build a merge ref, so pull_request workflows do not trigger). Green CI on the current head cannot be verified.
  3. New .github/workflows/codeql.yml conflicts with CodeQL default setup — the Analyze (actions) / Analyze (javascript-typescript) / Analyze (python) checks on this PR come from dynamic/github-code-scanning/codeql (default setup), not from the new workflow, which has never executed. GitHub rejects SARIF uploads from advanced configurations while default setup is enabled, so once merged this workflow's analyze step will fail. Either disable default setup or drop the new workflow — not both.

Non-blocking notes:

  • github/codeql-action is pinned to bb16b9ba…, which is the annotated tag object SHA for v4.37.1, not the tag's target commit (7188fc3…). Recommend pinning the commit SHA per org pinning standards.
  • actions/setup-node is pinned to 48b55a01… = v6.4.0, while the comment says # v6 (v6 currently points to v6.5.0). Cosmetic comment drift.
  • Positive: SONAR_TOKEN moved from job-level env to step-level (resolves the CodeRabbit security thread), npm ci --ignore-scripts resolves the GitHub Advanced Security finding, all 5 prior review threads are resolved, and the refactors were spot-checked as behavior-preserving (escapeHtml replaceAll ordering, [\w-] regex equivalence, Date.now mock update, TypeError subclassing Error).
  • Secret scan: the run_secret_scanning MCP tool is unavailable in this environment; no secret material appears in the diff (only proper ${{ secrets.SONAR_TOKEN }} references). The gitleaks CI check remains authoritative but has not run on this head (see blocking item 2).

CI status

Checks present on head 570b613: Analyze (actions) ✅, Analyze (javascript-typescript) ✅, Analyze (python) ✅, CodeQL ✅ (all from default setup), dependabot-automerge ⏭ skipped. Missing on this head: Node.js Tests, coverage, lint, Playwright, gitleaks, SonarCloud — not triggered because the PR is in a conflicted state. SonarCloud Quality Gate passed on earlier commit eb5831d.


Reviewed automatically by the PR-review agent (single-reviewer mode: fable 5). Reply if you need a human review.

Additional tasks

  1. Resolve all unresolved review thread comments from other reviewers
  2. Ensure all CI checks pass after your changes
  3. Rebase on the target branch if behind
  4. Do NOT modify files unrelated to the findings above

The review cascade will automatically re-review after new commits are pushed.

@don-petry

Copy link
Copy Markdown
Collaborator Author

Closing as part of the open-PR drain (50-PR automation cap). This branch has real merge conflicts with main and cannot be rebased automatically; the linked compliance issue remains OPEN so dev-lead can regenerate a clean PR once there is cap headroom. No work is lost.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SonarCloud: JavaScript/TypeScript code quality

4 participants