Skip to content

Conversation

@vaind
Copy link
Contributor

@vaind vaind commented Sep 23, 2025

Summary

  • Adds fallback to generate changelog from git commits when no changelog.md exists
  • Refactors code into separate functions for better maintainability
  • Supports repositories like Catch2, React, Vue.js that use GitHub releases instead of changelog files

Details

This PR enhances the get-changelog.ps1 script to work with GitHub repositories that don't maintain a traditional CHANGELOG.md file (like Catch2).

Key Changes:

  1. Git Commit Fallback: When no changelog files are found, the script now clones the repository and extracts commit messages between the specified tags
  2. Code Refactoring: Split the monolithic script into focused functions:
    • Get-ChangelogFromCommits: Generate changelog from git log
    • Get-ChangelogFromDiff: Generate changelog from file diff (existing logic)
    • Format-ChangelogContent: Apply consistent formatting and sanitization
  3. Improved Link Handling: Same link sanitization (github-redirect.dependabot.com) applied to prevent notifications
  4. Version Filtering: Automatically filters out version tag commits (e.g., "v3.10.0") to focus on meaningful changes

Example Output:

For repositories without changelog files, the output now looks like:

## Changelog

### Commits between v3.9.1 and v3.10.0

- Forbid deducing reference types for m_predicate in FilterGenerator ([#3005](https://github-redirect.dependabot.com/catchorg/Catch2/issues/3005))
- Make message macros (FAIL, WARN, INFO, etc) thread safe
- Improve performance of writing XML
- Improve performance of writing JSON values
- Handle DESTDIR env var when generating pkgconfig files
- Fix color mode detection on FreeBSD by adding platform macro
- Don't add / to start of pkg-config file path when DESTDIR is unset

Test plan

  • All existing tests continue to pass
  • Added 4 new tests covering the git commit fallback functionality
  • Verified works with Catch2 repository (no changelog.md)
  • Confirmed link formatting prevents GitHub notifications
  • Tested edge cases (no commits, same tags, version filtering)

🤖 Generated with Claude Code

- Adds fallback to generate changelog from git commits when no changelog.md exists
- Refactors code into separate functions for better maintainability:
  - Get-ChangelogFromCommits: Generate changelog from git log
  - Get-ChangelogFromDiff: Generate changelog from file diff
  - Format-ChangelogContent: Apply consistent formatting and sanitization
- Filters out version tag commits to focus on meaningful changes
- Applies same link formatting to prevent GitHub notifications
- Supports repositories like Catch2, React, Vue.js that use GitHub releases
- Maintains backward compatibility with existing changelog.md workflow
- Adds comprehensive tests for new functionality

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions
Copy link
Contributor

github-actions bot commented Sep 23, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 5ab597a

- Update git commit fallback tests to match exact expected output like other tests
- Remove redundant $prefix variable definition (use global scope)
- Add changelog entry for the new git commit fallback feature

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vaind
Copy link
Contributor Author

vaind commented Sep 23, 2025

@sentry review

- Add comprehensive error handling for all git operations to prevent script termination
- Implement progressive fallback: shallow clone → deep clone → full clone
- Add proper cleanup in exception scenarios using try/catch/finally blocks
- Make tests more robust to reduce external dependency brittleness
- Add test for invalid repository error handling
- Improve error messages with specific exit codes
- Ensure temporary repository directories are always cleaned up

Addresses review comments:
- Fix PSNativeCommandErrorActionPreference termination issue
- Handle git command failures gracefully
- Improve git clone depth handling
- Add better directory cleanup
- Make tests less dependent on external repository state

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vaind
Copy link
Contributor Author

vaind commented Sep 23, 2025

Thank you for the detailed review! I've addressed all the feedback:

Fixed Issues:

🔴 Critical Error Handling

  • Added comprehensive error handling for all git operations (git clone, git fetch, git log) using the same pattern as git diff
  • Fixed PSNativeCommandErrorActionPreference termination by wrapping git commands with $ErrorActionPreference = 'Continue' in try/finally blocks
  • Added specific exit code reporting for better debugging

🟡 Robustness Improvements

  • Progressive fallback strategy: shallow clone (200) → deep clone (1000) → full clone if needed
  • Guaranteed cleanup using try/catch/finally blocks with explicit repository directory removal
  • Better error messages with specific exit codes and clearer warnings

🧪 Test Reliability

  • Made tests more robust by checking structure/patterns rather than exact content to reduce external dependency brittleness
  • Added error handling test for invalid repositories to verify graceful failure
  • All 16 tests pass including new error scenarios

🔧 Key Changes Made:

# Before: Could cause script termination
git clone --depth=200 $repoUrl $repoDir

# After: Proper error handling with fallbacks
$cloneResult = & {
    $ErrorActionPreference = 'Continue'
    try {
        git clone --depth=200 $repoUrl $repoDir
        # + progressive fallback logic
    } finally {
        $ErrorActionPreference = $oldErrorActionPreference
    }
}

The implementation now handles all error scenarios gracefully while maintaining the performance benefits of shallow clones when possible.

All CI tests continue to pass ✅

vaind and others added 9 commits September 23, 2025 19:36
…ionPreference

Instead of wrapping every git command with complex error handling, simply set
PSNativeCommandErrorActionPreference to false and handle $LASTEXITCODE explicitly.

This is much cleaner and more maintainable:
- Removes 50+ lines of complex error handling wrappers
- Makes the code more readable and easier to understand
- Still maintains all the same error handling behavior
- All tests continue to pass

Changes:
- Set PSNativeCommandErrorActionPreference = $false globally
- Simplified git clone/fetch/log operations to check $LASTEXITCODE directly
- Removed complex try/catch/finally wrappers from Get-ChangelogFromCommits
- Simplified Get-ChangelogFromDiff git diff operation
- Maintained all progressive fallback and cleanup logic

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Refactored git commit fallback test cases to follow the same pattern as
'supports cross-repo links' test using single expected multiline strings
instead of multiple Should-Match assertions.

Changes:
- 'falls back to git commits when no changelog files exist': Now uses exact expected output
- 'git commit fallback handles PR references correctly': Uses exact expected output
- 'git commit fallback filters out version tag commits': Uses exact expected output with full commit list

Benefits:
- More consistent test style across the test suite
- Easier to see what the expected output should be
- Better failure messages when tests fail
- All 16 tests continue to pass

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Cleaned up the main logic by encapsulating changelog file fetching
within the Get-ChangelogFromDiff function itself.

Changes:
- Get-ChangelogFromDiff now takes (oldTag, newTag, tmpDir) instead of file paths
- Function handles its own changelog file fetching and returns null if files don't exist
- Main logic is simplified to just call both functions and use whichever succeeds
- Removes duplicate code and makes the interface cleaner
- All 16 tests continue to pass

Benefits:
- Cleaner separation of concerns
- Simpler main logic flow
- Each function is more self-contained
- Easier to understand and maintain

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Change test from sentry-javascript to github-workflows repo to reduce
git clone timeout from 26s to 4s. The github-workflows repo is already
used in other tests and clones much faster while still testing the same
error handling functionality for invalid tags.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@vaind vaind marked this pull request as ready for review September 23, 2025 19:55
@vaind
Copy link
Contributor Author

vaind commented Sep 23, 2025

@sentry review

@vaind vaind merged commit 1dbbc41 into main Sep 23, 2025
14 checks passed
@vaind vaind deleted the feat/git-commit-changelog-fallback branch September 24, 2025 09:11
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.

2 participants