This script provides an automated way to summarize changes made to files in a Git repository. It uses the OpenAI API to generate concise, human-readable summaries of the git diff output, useful for generating changelogs or quick summaries of recent modifications.
- Summarize Current Changes: By default, it fetches and summarizes the
git diffoutput for each changed file in your current working directory. - Summarize Specific Commits: You can now specify a commit hash to summarize the changes introduced by that particular commit.
- Batch Processing: Sends the diff summary to OpenAI's API in batches (limited to 4000 characters) for summary generation.
- Content Sanitization: Sanitizes the content to ensure only relevant alphanumeric and selected symbols are included.
- Readable Output: Displays each summary generated by the OpenAI API, making it easy to track modifications.
- Token Usage Tracking: Counts input and output tokens for each API call and displays the total usage.
- Cost Calculation: Provides a detailed cost estimate for the API calls, formatted with appropriate precision.
- Self-Update Mechanism: Easily update the tool to the latest version from the main branch.
- Git: Ensure
gitis installed and you are working in a repository. - OpenAI API Key: Required to send requests to OpenAI's API. This should be stored in a
.envfile in the project directory. - jq: This JSON processor is used to format API request and response data.
- cURL: Used to make HTTP requests to the OpenAI API.
- Python 3: Used to parse JSON responses from the OpenAI API.
- bc: Used for floating-point calculations in cost estimation.
-
Clone the repository and navigate to the project directory.
-
Create a
.envfile in the project root with your OpenAI API key:OPENAI_API_KEY=your_openai_api_key -
Ensure the required tools are installed:
- Install
jqon Debian-based systems withsudo apt-get install jq. - Install
curlif not already available. - Ensure Python 3 is installed and accessible via
python3. - Ensure
bcis installed for cost calculations.
- Install
-
Run the
install.shscript to set up thereportgencommand:chmod +x install.sh ./install.sh
This creates a symbolic link to the
index.shscript in/usr/local/bin, allowing you to runreportgenfrom anywhere.
-
Summarize Current Working Changes:
reportgen
This will:
- Load your OpenAI API key from the
.envfile. - Check for changed files in the repository.
- Generate a sanitized diff summary for each file, sending it in 4000-character batches to OpenAI for summarization.
- Display the output of each summarized topic in the terminal.
- Show the total token usage and estimated cost.
- Load your OpenAI API key from the
-
Summarize a Specific Commit:
reportgen <commit_hash>
For example:
reportgen 8d403a9
This will:
- Generate a summary of changes introduced by that specific commit.
- Provide a concise set of topics reflecting what changed in that commit.
- Display token usage and cost information.
-
Update the Tool:
reportgen --update
This will:
- Check if the script is in a git repository.
- Fetch the latest changes from the main branch.
- Warn about and confirm before overwriting any local modifications.
- Pull the latest version and return to your original branch.
Example Output
- Added new type definitions for Tutor entity in Tutors component
- Refactored TutorItem props for improved type safety
- Updated TutorsList component to handle missing index ...
===== USAGE SUMMARY ===== Input tokens: 1240 Output tokens: 317 Total tokens: 1557 Cost: $0.38 USD
This project is licensed under the MIT License. See the LICENSE file for details.