Skip to content

refactor: fix quality gate issues, improve type safety and pagination - #21

Merged
ClaudiaFang merged 4 commits into
masterfrom
fix/quality-gate-improvements
Apr 26, 2026
Merged

ClaudiaFang merged 4 commits into
masterfrom
fix/quality-gate-improvements

Conversation

@ClaudiaFang

Copy link
Copy Markdown
Member

Summary of Changes

This PR addresses several SonarCloud quality gate issues, improves type safety, and enhances API reliability.

🛠️ Bug Fixes & Improvements

  • Type Safety: Refactored SyncManager to eliminate any types and use a constructor-injected callback for saving settings.
  • GitLab Pagination: Implemented proper pagination in GitLabService.listFiles to support repositories with more than 100 files.
  • GitHub Awareness: Added detection and warnings for truncated tree results in GitHubService.listFiles.
  • CI Fix: Resolved a GitHub Actions syntax error where secrets were incorrectly used in a reusable workflow with block.
  • Build Fix: Resolved strict null check errors (noUncheckedIndexedAccess) in the diff algorithm logic.

🧹 Code Quality (SonarJS)

  • Cognitive Complexity: Refactored the side-by-side diff algorithm in SyncStatusView.ts to reduce cognitive complexity from 29 to under 15 by decomposing large methods.
  • Type Aliases: Introduced DiffOp and DiffOpType to replace complex inline union types.
  • Integration: Integrated eslint-plugin-sonarjs into the project's ESLint configuration for continuous quality monitoring.
  • De-duplication: Consolidated service name logic into a centralized getServiceName helper.

✅ Verification

  • Ran npm run lint (Passed)
  • Ran npm run build (Passed)
  • Ran npm run test (Passed)

@sonarqubecloud

Copy link
Copy Markdown

@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 enhances the project's code quality and maintainability by integrating the sonarjs ESLint plugin, refactoring the SyncStatusView diff logic into modular components, and centralizing error handling within SyncManager. It also adds support for paginated file listing in GitLab and introduces a GitHub repository ruleset. Review feedback suggests further optimizing the GitLab file listing by adhering to the service interface, leveraging API-side filtering for the root path, and improving array manipulation performance.

@@ -56,14 +56,29 @@ export class GitLabService extends BaseGitService implements GitServiceInterface

async listFiles(branch: string): Promise<string[]> {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The implementation of listFiles is missing the optional path parameter defined in the GitServiceInterface. To improve type safety and adhere to the interface, the signature should be updated.

Suggested change
async listFiles(branch: string): Promise<string[]> {
async listFiles(branch: string, path?: string): Promise<string[]> {

.map(item => item.path)
.filter(p => !this.rootPath || p.startsWith(this.rootPath));
while (true) {
const url = `${this.baseUrl}/api/v4/projects/${encodedProjectId}/repository/tree?ref=${branch}&recursive=true&per_page=${perPage}&page=${page}`;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

When this.rootPath is configured, it is more efficient to pass it to the GitLab API using the path parameter. This reduces the amount of data transferred and the number of pages to iterate through, especially in large repositories.

Suggested change
const url = `${this.baseUrl}/api/v4/projects/${encodedProjectId}/repository/tree?ref=${branch}&recursive=true&per_page=${perPage}&page=${page}`;
const url = `${this.baseUrl}/api/v4/projects/${encodedProjectId}/repository/tree?ref=${branch}&recursive=true&per_page=${perPage}&page=${page}${this.rootPath ? `&path=${encodeURIComponent(this.rootPath)}` : ''}`;

Comment on lines +70 to +75
const paths = data
.filter(item => item.type === 'blob')
.map(item => item.path)
.filter(p => !this.rootPath || p.startsWith(this.rootPath));

allPaths = allPaths.concat(paths);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Using allPaths.push(...paths) is more efficient than allPaths.concat(paths) because it modifies the array in place instead of creating a new array on every iteration. This can be simplified by pushing the filtered results directly.

Suggested change
const paths = data
.filter(item => item.type === 'blob')
.map(item => item.path)
.filter(p => !this.rootPath || p.startsWith(this.rootPath));
allPaths = allPaths.concat(paths);
allPaths.push(...data
.filter(item => item.type === 'blob')
.map(item => item.path)
.filter(p => !this.rootPath || p.startsWith(this.rootPath)));

@ClaudiaFang
ClaudiaFang enabled auto-merge (squash) April 26, 2026 18:13
@ClaudiaFang ClaudiaFang self-assigned this Apr 26, 2026
@ClaudiaFang
ClaudiaFang merged commit 70171fd into master Apr 26, 2026
18 of 20 checks passed
@ClaudiaFang
ClaudiaFang deleted the fix/quality-gate-improvements branch April 26, 2026 18:16
ClaudiaFang pushed a commit that referenced this pull request Apr 26, 2026
## [1.0.5](1.0.4...1.0.5) (2026-04-26)

### Code Refactoring

* address SonarCloud issues and reduce code duplication ([#20](#20)) ([4574abc](4574abc))
* fix quality gate issues, improve type safety and pagination ([#21](#21)) ([70171fd](70171fd))
@ClaudiaFang

Copy link
Copy Markdown
Member Author

🎉 This PR is included in version 1.0.5 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant