-
-
Notifications
You must be signed in to change notification settings - Fork 41
Implement comprehensive GitHub API error handling for changelog synchronization #375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement comprehensive GitHub API error handling for changelog synchronization #375
Conversation
- Add github_api_utils.sh with rate limiting, auth validation, retry logic - Enhance process_single_release.sh with force regeneration options - Improve catch_up_releases.sh with better error tracking and CLI options - Update main sync workflow with enhanced error handling and debugging - Add comprehensive documentation for new error handling features - Include actionable error suggestions and troubleshooting guidance Co-authored-by: castrojo <1264109+castrojo@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements comprehensive GitHub API error handling for the changelog synchronization system, transforming basic error handling into a robust, production-ready infrastructure. The implementation includes rate limit management, authentication validation, retry logic with exponential backoff, enhanced logging capabilities, and force regeneration options for existing changelog files.
Key changes:
- Added a new shared GitHub API utilities module with comprehensive error handling and retry logic
- Enhanced existing scripts with force regeneration capabilities and improved error reporting
- Implemented structured logging with multiple verbosity levels and actionable troubleshooting suggestions
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
File | Description |
---|---|
scripts/github_api_utils.sh |
New comprehensive utility module providing robust GitHub API functions with error handling, rate limiting, and logging |
scripts/process_single_release.sh |
Enhanced with force regeneration option, structured logging, and improved error handling throughout the process |
scripts/catch_up_releases.sh |
Updated with CLI argument parsing, health checks, error tracking, and integration with new API utilities |
GITHUB_API_ERROR_HANDLING.md |
New comprehensive documentation covering all error handling features, usage examples, and troubleshooting guides |
.github/workflows/sync-bluefin-releases.yml |
Enhanced workflow with API health checks, repository validation, and improved error reporting using new utilities |
# Calculate wait time if we're out of requests | ||
if [[ "$core_remaining" -eq 0 ]]; then | ||
local current_time wait_time | ||
current_time=$(date +%s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The arithmetic expansion could fail if core_reset_time
or current_time
contain non-numeric values. Add validation to ensure both variables are valid integers before performing arithmetic operations.
current_time=$(date +%s) | |
current_time=$(date +%s) | |
# Validate that core_reset_time and current_time are integers | |
if ! [[ "$core_reset_time" =~ ^[0-9]+$ && "$current_time" =~ ^[0-9]+$ ]]; then | |
log_error "Invalid reset time or current time: core_reset_time='$core_reset_time', current_time='$current_time'" | |
return $ERROR_RATE_LIMIT | |
fi |
Copilot uses AI. Check for mistakes.
if [[ $attempt -lt $max_retries ]]; then | ||
log_verbose "⏳ Retrying in ${current_delay}s..." | ||
sleep "$current_delay" | ||
current_delay=$((current_delay * 2)) # Exponential backoff |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The exponential backoff calculation could result in extremely large delay values that exceed reasonable limits. Consider adding a maximum delay cap to prevent indefinite waiting.
current_delay=$((current_delay * 2)) # Exponential backoff | |
current_delay=$((current_delay * 2)) # Exponential backoff | |
if (( current_delay > MAX_WAIT_TIME )); then | |
current_delay=$MAX_WAIT_TIME | |
fi |
Copilot uses AI. Check for mistakes.
FORCE_REGENERATE="false" | ||
|
||
# Check for force regenerate flag | ||
if [[ "$9" == "--force-regenerate" ]] || [[ "$FORCE_REGENERATE_CHANGELOGS" == "true" ]]; then |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using positional parameter $9
for flag detection is fragile and makes the script difficult to extend with additional parameters. Consider implementing proper argument parsing with a while loop to handle flags in any position.
Copilot uses AI. Check for mistakes.
[0-9]*) | ||
# Skip numeric argument (already processed as DAYS_BACK) | ||
shift |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The numeric argument handling assumes the first numeric argument is always DAYS_BACK, but this logic doesn't update DAYS_BACK if it appears later in the argument list. This could lead to inconsistent behavior when arguments are reordered.
Copilot uses AI. Check for mistakes.
# Check if we're approaching rate limits | ||
if [[ "$core_remaining" -lt "$RATE_LIMIT_BUFFER" ]]; then | ||
local reset_date | ||
reset_date=$(date -d "@$core_reset_time" 2>/dev/null || date -r "$core_reset_time" 2>/dev/null || echo "unknown") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fallback chain for date formatting uses different command formats for different systems but doesn't validate that core_reset_time
is a valid Unix timestamp before using it. Consider adding validation to ensure it's numeric before attempting date conversion.
reset_date=$(date -d "@$core_reset_time" 2>/dev/null || date -r "$core_reset_time" 2>/dev/null || echo "unknown") | |
if [[ "$core_reset_time" =~ ^[0-9]+$ ]]; then | |
reset_date=$(date -d "@$core_reset_time" 2>/dev/null || date -r "$core_reset_time" 2>/dev/null || echo "unknown") | |
else | |
reset_date="unknown" | |
fi |
Copilot uses AI. Check for mistakes.
Problem
The existing changelog synchronization system had basic error handling that could fail silently or with unclear error messages when encountering GitHub API issues. The system lacked:
Solution
This PR implements a comprehensive GitHub API error handling infrastructure that provides robust, reliable interaction with GitHub APIs.
Key Features
🔧 Enhanced Error Handling
⚡ Rate Limiting Management
🔒 Authentication & Repository Validation
🔄 Retry Logic & Resilience
📝 Enhanced Logging & Debugging
⚙️ Force Regeneration Capability
--force-regenerate
flag to overwrite existing changelog filesFORCE_REGENERATE_CHANGELOGS
environment variable supportFiles Modified/Created
scripts/github_api_utils.sh
- New shared utility with comprehensive API functionsscripts/process_single_release.sh
- Enhanced with force regeneration and better loggingscripts/catch_up_releases.sh
- Improved CLI options and error tracking.github/workflows/sync-bluefin-releases.yml
- Updated to use enhanced error handlingGITHUB_API_ERROR_HANDLING.md
- Comprehensive documentationUsage Examples
Error Handling Examples
Authentication Issues:
Rate Limiting:
Repository Access:
Testing
All changes have been thoroughly tested with:
The enhanced system is production-ready and provides robust, reliable GitHub API interaction with comprehensive error handling for the changelog synchronization workflow.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.