Skip to content

Conversation

@ksylvan
Copy link
Collaborator

@ksylvan ksylvan commented Jul 16, 2025

Improve PR Sync Logic for Changelog Generator

Summary

This PR enhances the changelog generation system to properly preserve and associate PR numbers with version tags during cache merges. The changes improve the accuracy of changelog entries by ensuring that PR numbers are correctly maintained when versions are cached and retrieved.

Files Changed

  • CHANGELOG.md: Added new version entry v1.4.248 with detailed changelog improvements
  • cmd/generate_changelog/changelog.db: Updated binary database file with new cached data
  • cmd/generate_changelog/internal/changelog/generator.go: Enhanced PR fetching logic to handle missing PRs in cached versions

Code Changes

cmd/generate_changelog/internal/changelog/generator.go

The most significant changes are in the fetchPRs() method:

// Check if we need to sync for missing PRs
missingPRs := false
for _, version := range g.versions {
    for _, prNum := range version.PRNumbers {
        if _, exists := g.prs[prNum]; !exists {
            missingPRs = true
            break
        }
    }
    if missingPRs {
        break
    }
}

// If we have never synced or it's been more than 24 hours, do a full sync
// Also sync if we have versions with PR numbers that aren't cached
needsSync := lastSync.IsZero() || time.Since(lastSync) > 24*time.Hour || g.cfg.ForcePRSync || missingPRs

This code adds a check to determine if any versions have PR numbers that aren't present in the cached PR data, and forces a sync if missing PRs are detected.

CHANGELOG.md

Added a new version entry documenting the improvements made to the changelog system itself, including proper attribution of changes to PR #1616.

Reason for Changes

The changes address an issue where PR numbers associated with version tags were not being properly preserved during cache operations. Previously, when versions were cached and later retrieved, the PR number associations could be lost, leading to incomplete or inaccurate changelog entries.

Impact of Changes

  • Improved Accuracy: Changelog entries will now correctly display all associated PR numbers for each version
  • Better Caching Logic: The system now intelligently detects when cached PR data is incomplete and triggers appropriate syncing
  • Enhanced User Experience: Users will see more complete and accurate changelog information with proper PR attributions

Test Plan

The changes should be tested by:

  1. Running the changelog generator with existing cached data to ensure missing PRs are detected
  2. Verifying that forced syncing occurs when PR numbers are missing from the cache
  3. Confirming that the generated changelog properly associates PR numbers with their respective versions
  4. Testing the caching mechanism to ensure it doesn't unnecessarily sync when all PR data is present

Additional Notes

  • The binary database file has been updated to reflect the new caching logic
  • The missingPRs flag ensures that the system is more robust in handling incomplete cached data
  • The changelog now properly documents its own improvements, creating a self-referential but accurate record of the enhancement

Potential Issues to Monitor:

  • Performance impact of the additional PR number checking logic
  • Ensure the nested loop breaks properly to avoid unnecessary iterations
  • Verify that the database updates don't cause corruption or compatibility issues

### CHANGES

- Enhance changelog to associate PR numbers with version tags
- Improve PR number parsing with proper error handling
- Collect all PR numbers for commits between version tags
- Associate aggregated PR numbers with each version entry
- Update cached versions with newly found PR numbers
- Add check for missing PRs to trigger sync if needed
@ksylvan ksylvan requested a review from Copilot July 16, 2025 01:22

This comment was marked as resolved.

@ksylvan ksylvan merged commit 5212fbc into danielmiessler:main Jul 16, 2025
1 check passed
@ksylvan ksylvan deleted the 0715-really-really-fix-changelog-pr-sync-issue branch July 16, 2025 04:46
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