Skip to content

Conversation

@prakritchai
Copy link
Contributor

Problem

The GitLab integration was failing with a "Not Found" error during comment cleanup, causing the entire VCS reporting to fail. This occurred when the removeExistingComments functionality attempted to delete stale comment/discussion IDs that were no longer valid.

Error message:

error: GitLab report failed Not Found
error: Report to VCS failed {"error":{}}

Root Cause

  1. Stale comment IDs: Comments deleted externally became invalid, but the system still tried to delete them
  2. No error handling: 404 errors in deletion operations caused the entire process to fail
  3. Promise.all failure: One failed deletion caused all subsequent operations to fail
  4. Missing dependencies: @gitbeaker/rest package was missing from dependencies

Solution

🔧 GitLabMRService.ts

  • Added deleteNoteWithErrorHandling() method with comprehensive 404 error handling
  • Enhanced deleteDiscussion() with try-catch blocks for missing discussions
  • Replaced Promise.allSettled() with ES2015-compatible sequential processing
  • Added detailed logging for partial failures and success tracking

🔧 GitLabAdapter.ts

  • Replaced Promise.all() with individual error handling for each deletion
  • Added ID validation before attempting deletion operations
  • Implemented graceful handling of partial failures
  • Enhanced logging to track successful vs failed deletions

🔧 GitLab.spec.ts

  • Added comprehensive unit tests for 404 error scenarios
  • Added tests for partial failure resilience
  • Added tests for invalid ID validation
  • Added tests for discussion note deletion with individual failures
  • Added logging verification tests

📦 package.json

  • Added missing @gitbeaker/core and @gitbeaker/rest dependencies

Key Features

404 Error Resilience: System continues processing even when individual comments/discussions are not found
Partial Failure Handling: Logs warnings for failed deletions but continues with successful ones
ID Validation: Validates IDs before attempting deletion operations
Detailed Logging: Provides clear feedback on success/failure ratios
Backward Compatibility: No breaking changes to existing functionality

Testing

  • All 131 tests pass across 23 test suites
  • Added comprehensive error scenario coverage
  • Tested with various GitLab API error responses
  • Verified graceful degradation with partial failures

Files Changed

  • package.json - Added missing GitBeaker dependencies
  • src/Provider/GitLab/GitLab.spec.ts - Added comprehensive error handling tests
  • src/Provider/GitLab/GitLabAdapter.ts - Enhanced error handling and logging
  • src/Provider/GitLab/GitLabMRService.ts - Added 404 error resilience

Impact

This fix resolves the GitLab "Not Found" error completely, ensuring reliable comment management and preventing integration failures due to stale comment references.

- Add comprehensive error handling for 404 errors in GitLabMRService
- Replace Promise.all with individual error handling in GitLabAdapter
- Add graceful handling of stale comment/discussion IDs
- Enhance logging for partial deletion failures
- Add extensive unit tests for error scenarios
- Install missing @gitbeaker dependencies for proper API support

Fixes issue where stale comment IDs caused entire comment cleanup to fail
with 'Not Found' error, preventing successful GitLab integration.
@jeeyo jeeyo self-requested a review July 2, 2025 06:18
jeeyo
jeeyo previously approved these changes Jul 2, 2025
@prakritchai
Copy link
Contributor Author

🔧 CI Pipeline Fix Applied

I've fixed the yarn lockfile issue that was causing the CI pipeline to fail:

Problem

yarn install v1.22.22
[1/5] Validating package.json...
[2/5] Resolving packages...
error Your lockfile needs to be updated, but yarn was run with `--frozen-lockfile`.

Solution Applied

Removed corrupted yarn.lock - The original lockfile had syntax errors
Deleted package-lock.json - Removed npm lockfile since this is a yarn project
Regenerated yarn.lock from scratch - Used npx yarn@1.22.22 install to create fresh lockfile
Synchronized dependencies - Ensured yarn.lock matches package.json exactly

Result

  • Fresh yarn.lock file that's properly synchronized with package.json
  • CI pipeline should now pass with --frozen-lockfile flag
  • All GitBeaker dependencies properly resolved and locked

The PR is now ready for CI validation! 🚀

@prakritchai prakritchai force-pushed the fix/gitlab-not-found-error branch from 24f3654 to 295c9f2 Compare July 2, 2025 11:48
- Add @types/glob@^7.2.0 and @types/minimatch@^3.0.5 to resolve TypeScript compilation errors
- Update yarn.lock with new dependencies
- Ensure GitLab MR Service uses proper types from @gitbeaker/core
- All tests passing (131/131)
- Build successful with TypeScript strict mode
- Fixed all TypeScript 'any' type annotations to proper types
- Removed unused imports and functions
- Reduced cognitive complexity in GitLabMRService.deleteDiscussion method
- Fixed prettier formatting issues
- Updated interface types to match implementation
- All tests passing and linting clean
@jeeyo jeeyo self-requested a review July 3, 2025 07:49
@jeeyo jeeyo merged commit 6a825b5 into codeleague:main Jul 3, 2025
2 checks passed
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.

3 participants