This script analyzes a specific git commit or the latest commit in a repository. It fetches the commit message and code diffs, and sends them to OpenAI's ChatGPT API for a natural language explanation.
-
Clone the repository to your local machine.
-
Create a virtual environment using
conda
:conda create --name explain_commits --file requirements.txt
-
Create a
.env
file in the same folder using the.env.template
as a reference:cp .env.template .env
-
Add your OpenAI API key in the
.env
file.
path
: Path to the git repository.-c
,--commit
: Specific commit hash. Defaults to the latest commit if not specified.-i
,--include
: Comma-separated whitelist of file extensions to include. Defaults to.c,.h,.py,.htm
.
To analyze a specific commit:
python explain_commits.py -c [commit_hash] [repository_path]
To analyze the latest commit in the repository:
python explain_commits.py [repository_path]
- Open SmartGit and navigate to Edit → Preferences → Tools.
- Add a new tool with the following settings:
- Menu Item Name: "GPT explain commit"
- Command:
[…]\anaconda3\envs\explain_commits\python.exe
- Arguments:
"[…]\explain_commits.py" -c ${commit} ${repositoryRootPath}
- Handles: Commits
Then this tool is available on the context menu for commits, which will output a .md
file to the repo folder.