sample-platform
sample-platform copied to clipboard
fix(ci): Prevent invalid commit hashes from blocking release pipeline
[FIX] Prevent invalid commit hashes in test entries during CCExtractor releases
In raising this pull request, I confirm the following:
- [x] I have read and understood the contributors guide.
- [x] I have checked that another pull request for this purpose does not exist.
- [x] I have considered, and confirmed that this submission will be valuable to others.
- [x] I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
- [x] I give this submission freely, and claim no ownership to its content.
My familiarity with the project is as follows :
- [ ] I have never used the project.
- [ ] I have used the project briefly.
- [x] I have used the project extensively, but have not contributed previously.
- [ ] I am an active contributor to the project.
Issue Description
When CCExtractor releases a new version, a test entry gets added with commit hash 0000000000000000000000000000000000000000 which is invalid. This blocks any test after that and causes issues with the testing pipeline.
Root Cause
The issue occurs in the release webhook handler in mod_ci/controllers.py. When processing a release event, the code uses GeneralData.query.filter(GeneralData.key == 'last_commit').first().value to get the commit hash, which may be invalid or contain zeros when there are issues with previous webhook processing.
Fix Implemented
This PR implements two key fixes:
-
Added validation to
add_test_entryfunction:- Prevents creation of test entries with invalid commit hashes
- Adds detailed error logging when invalid hashes are detected
- Skips test entry creation for empty, all-zero, or too-short commit hashes
-
Fixed release webhook handler:
- Uses GitHub API to fetch the actual commit hash from the release tag
- Implements proper fallback with validation if tag lookup fails
- Creates release records without updating test baselines when no valid commit hash can be determined
- Only updates test baselines if a valid test entry exists for the commit
Benefits
- No more test entries with invalid commit hashes like
0000000000000000000000000000000000000000 - Releases are now associated with their correct commit hashes
- System gracefully handles cases where commit hashes can't be determined
- Invalid commits no longer block subsequent tests
- Better error logging for easier troubleshooting
Testing
This fix has been tested by simulating GitHub webhook events for releases and verifying that:
- No invalid test entries are created
- Release version records are created correctly
- Test baselines are only updated when valid commit hashes are available
Related Issues
Fixes the long-standing issue where release events create invalid test entries.
Quality Gate passed
Issues
0 New issues
0 Accepted issues
Measures
0 Security Hotspots
0.0% Coverage on New Code
0.0% Duplication on New Code