Skip to content

feat: implement issue #427 — SonarCloud: cognitive complexity (S3776)#431

Open
don-petry wants to merge 3 commits into
mainfrom
dev-lead/issue-427-20260707-1917
Open

feat: implement issue #427 — SonarCloud: cognitive complexity (S3776)#431
don-petry wants to merge 3 commits into
mainfrom
dev-lead/issue-427-20260707-1917

Conversation

@don-petry

Copy link
Copy Markdown
Collaborator

Closes #427

Implemented by dev-lead agent. Please review.

Copilot AI review requested due to automatic review settings July 7, 2026 19:27
@don-petry don-petry requested a review from a team as a code owner July 7, 2026 19:27
@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 7, 2026

Copy link
Copy Markdown

Warning

Review limit reached

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

Next review available in: 42 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: e8e7f60f-ac19-41e8-849c-ae896b8ffed8

📥 Commits

Reviewing files that changed from the base of the PR and between f04efc7 and 31f2632.

⛔ Files ignored due to path filters (2)
  • _bmad/bmm/workflows/4-implementation/bmad-retrospective/workflow.md is excluded by !_bmad/**
  • _bmad/bmm/workflows/4-implementation/bmad-sprint-status/workflow.md is excluded by !_bmad/**
📒 Files selected for processing (6)
  • .github/skills/bmad-retrospective/workflow.md
  • .github/skills/bmad-sprint-status/workflow.md
  • deploy/index.html
  • deploy/tests/ui.spec.js
  • src/calendar-to-sheets/src/index.js
  • src/gmail-to-drive-by-labels/src/index.js
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch dev-lead/issue-427-20260707-1917

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.

@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 refactors multiple components by extracting inline logic into modular helper functions. In deploy/index.html, project resolution and error HTML building are extracted. In src/calendar-to-sheets/src/index.js, row upserting, insertion, and deletion computation are modularized. In src/gmail-to-drive-by-labels/src/index.js, duplicate attachment checks, file name resolution, and document rebuilding phases are extracted into separate helpers. The review feedback highlights two key improvement opportunities: optimizing moveEmailsPhase by avoiding redundant and expensive Google Apps Script API calls to processedLabel.getThreads() and replacing array mutations with simple index tracking, and safely handling null or undefined error objects in buildDeployErrorHtml to prevent potential runtime TypeError crashes.

Comment thread src/gmail-to-drive-by-labels/src/index.js Outdated
Comment thread deploy/index.html Outdated
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

CI Failure: SonarCloud Code Analysis

Step: Quality Gate (New Code Coverage)
Root cause: Test failure

The SonarCloud Quality Gate failed because New Code Coverage is 0.0%, below the required 80% threshold. This PR (branch dev-lead/issue-427-20260707-1917) modifies src/gmail-to-drive-by-labels/src/index.js and src/calendar-to-sheets/src/index.js without adding any corresponding tests, so none of the changed lines are exercised by the test suite. SonarCloud also flagged 3 minor code-smell warnings (an unused Session variable assignment/declaration in gmail-to-drive-by-labels/src/index.js:167, and a preference for Number.isNaN over isNaN in calendar-to-sheets/src/index.js:190), but these are warnings, not the blocking condition.

Suggested fix: Add unit tests covering the new/changed logic in src/gmail-to-drive-by-labels/src/index.js and src/calendar-to-sheets/src/index.js to bring new-code coverage to at least 80%, and remove the unused Session variable while switching to Number.isNaN.

View run logs

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

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

Refactors several high-complexity routines flagged by SonarCloud (S3776) into smaller helper functions, aiming to reduce cognitive complexity while preserving existing behavior across Apps Script logic and the deploy UI.

Changes:

  • gmail-to-drive-by-labels: extracted attachment dedupe + name-conflict logic into helpers; extracted rebuild state machine phases into helpers.
  • calendar-to-sheets: extracted upsert/insert/delete decision logic into helpers to simplify syncCalendarToSheet.
  • deploy/index.html: extracted idempotent project resolution and deployment error rendering into helper functions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/gmail-to-drive-by-labels/src/index.js Reduces cognitive complexity by extracting attachment handling and rebuild phases into helpers.
src/calendar-to-sheets/src/index.js Reduces cognitive complexity by extracting row upsert/insert/delete computations into helpers.
deploy/index.html Reduces cognitive complexity by extracting project-id resolution and deploy-error HTML generation into helpers.

Comment thread deploy/index.html
Comment thread deploy/index.html Outdated
@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 7, 2026 19:32
@don-petry don-petry disabled auto-merge July 7, 2026 19:33
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

CI Failure: SonarCloud Code Analysis

Step: Quality Gate
Root cause: Test failure (missing coverage)

SonarCloud's Quality Gate failed because New Code coverage is 0.0%, well below the required 80% threshold. The PR extracts several new functions with no accompanying tests: resolveDeployProjectId and buildDeployErrorHtml in deploy/index.html, and upsertRows, insertNewRows, shouldDeleteRow, computeRowsToDelete in src/calendar-to-sheets/src/index.js. Since none of these lines are exercised by the existing test suite, SonarCloud counts 0% coverage on all new code.

Suggested fix: Add unit tests for the six newly extracted functions listed above (e.g. upsertRows/insertNewRows/shouldDeleteRow/computeRowsToDelete in the calendar-to-sheets test suite) so the new code paths are exercised and coverage crosses 80%.

View run logs

@don-petry

Copy link
Copy Markdown
Collaborator Author

Dev-Lead — review-changes (applied)

Changes committed and pushed.

@don-petry don-petry enabled auto-merge (squash) July 7, 2026 19:36
@don-petry don-petry disabled auto-merge July 7, 2026 19:36
@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

CI Failure: SonarCloud Code Analysis

Step: Quality Gate — new_coverage condition
Root cause: Test failure

The SonarCloud Quality Gate failed because coverage on new code is 0.0%, versus the required minimum of 80% (115 new lines added, all 115 uncovered). This PR (issue #427) extracts two new functions in deploy/index.htmlresolveDeployProjectId() and buildDeployErrorHtml() — out of an inline handler to reduce cognitive complexity (S3776), but no tests were added to exercise either function, so none of the new lines are covered by the test suite. All other gate conditions (reliability, security, maintainability, duplication, security hotspots) pass.

Suggested fix: Add unit tests for resolveDeployProjectId() (covering the stored-id-hit, stored-id-404-fallback, and create-new-project paths) and buildDeployErrorHtml() (covering the API-disabled and generic-error branches) in deploy/index.html, then re-run the analysis to confirm new-code coverage clears the 80% threshold.

View run logs

@don-petry

Copy link
Copy Markdown
Collaborator Author

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

No changes were needed for this PR.

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: cognitive complexity (S3776)

3 participants