Skip to content

Fix/sonarcloud alerts#32

Closed
anchildress1 wants to merge 2 commits intomainfrom
fix/sonarcloud-alerts
Closed

Fix/sonarcloud alerts#32
anchildress1 wants to merge 2 commits intomainfrom
fix/sonarcloud-alerts

Conversation

@anchildress1
Copy link
Member

This pull request includes a series of improvements and fixes across the GitHub Actions workflow, test setup, and main source code to enhance code quality, permissions handling, and reliability. The most significant changes involve refining workflow permissions for better security, updating test and source imports for consistency, and improving pull request creation logic.

GitHub Actions Workflow Improvements:

  • Refined workflow-level and job-level permissions in .github/workflows/ci.yml to use least privilege, setting empty permissions by default and specifying only necessary permissions (contents: read, checks: write, pull-requests: write) for individual jobs. [1] [2] [3] [4] [5]

Testing and Mocking Enhancements:

  • Increased the process event listener limit in __tests__/mocks.js to prevent warnings when repeatedly importing modules during tests.
  • Updated test and source imports to use explicit node: prefixes for core modules (fs, path) for consistency and clarity. [1] [2]
  • Simplified test mocks by removing unnecessary async keywords from methods that do not perform asynchronous operations, and streamlined mock implementations for better reliability. [1] [2] [3] [4] [5] [6]

Source Code Quality and Reliability:

  • Improved pull request body generation in src/index.js by refactoring string concatenation and clarifying the inclusion of the prompt file section.
  • Updated the timestamp generation for branch names to use replaceAll for better reliability.
  • Changed default exports and destructuring for pull request creation to use shorthand property names for conciseness.
  • Ensured the main script awaits the run() function for proper async handling at startup.

SonarQube Configuration:

  • Updated sonar-project.properties to correctly include the __tests__ directory for test coverage analysis.

Minor Code Cleanup:

  • Removed redundant approval responses in the runCopilot function's permission request handler.

github-actions bot and others added 2 commits February 20, 2026 14:01
- Merge redundant switch cases in onPermissionRequest (all returned same
  value; SonarCloud code smell)
- Apply ES6 shorthand for title/body properties in createPullRequest
  (SonarCloud code smell)
- Set sonar.tests=__tests__ so SonarCloud classifies test files correctly
- Raise process.setMaxListeners(50) in test setup to suppress
  MaxListenersExceededWarning from pino instances created per vi.resetModules()
- Rewrite AGENTS.md as concise AI-only strict instructions; fix stale
  references to Jest (→ vitest), 70% coverage threshold (→ 80%), and
  nonexistent test:coverage script

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
src/index.js:
- Use node:fs and node:path prefixes (S4616)
- replaceAll() over replace() with global regex (S5852)
- Extract nested template literal to promptFileSection variable (S4624)
- Use top-level await for run() entry guard (S4123)

__tests__/index.test.js:
- Remove duplicate mocks.js import; use node:fs prefix (S4616)
- Replace always-true ternary with mockResolvedValue(0) (S3923)
- Remove async keyword from intentionally empty stub methods (S4790)

.github/workflows/ci.yml:
- Move all permissions from workflow level to job level (S6275)
- setup/format/lint/build: contents:read only
- test: contents:read + checks:write + pull-requests:write

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings February 23, 2026 01:38
@sonarqubecloud
Copy link

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request addresses SonarCloud code quality alerts through a series of refactoring improvements focused on security best practices, code maintainability, and test reliability. The changes implement the principle of least privilege for GitHub Actions permissions, modernize import patterns, simplify code structure, and improve documentation.

Changes:

  • Implemented least-privilege permissions model in CI workflow with empty default permissions and explicit job-level grants
  • Modernized Node.js core module imports using the node: protocol prefix for better security and clarity
  • Refactored code for improved maintainability (switch case fall-through, ES6 property shorthand, extracted PR body logic, simplified test mocks)
  • Fixed SonarCloud configuration to properly recognize the test directory
  • Streamlined AGENTS.md documentation with essential rules and corrections

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

Show a summary per file
File Description
.github/workflows/ci.yml Refactored permissions to use least privilege model with empty default and explicit job-level grants
src/index.js Modernized imports with node: prefix, simplified switch case fall-through in permission handler, used ES6 property shorthand, improved PR body generation readability, used replaceAll for string replacement, added top-level await for proper async handling
tests/index.test.js Updated imports to use node: prefix, changed mock import from side-effect to named import, removed unnecessary async keywords from synchronous mock methods
tests/mocks.js Increased process event listener limit to prevent false-positive warnings from multiple pino instances during testing
sonar-project.properties Fixed test directory configuration from empty to __tests__ for proper test coverage analysis
AGENTS.md Significantly streamlined documentation, removed verbose content, focused on essential rules, corrected coverage threshold from 70% to 80%

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@anchildress1 anchildress1 deleted the fix/sonarcloud-alerts branch February 24, 2026 01:19
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.

1 participant