commitgpt 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +208 -70
- data/commitgpt.gemspec +35 -0
- data/lib/commitgpt/cli.rb +46 -6
- data/lib/commitgpt/commit_ai.rb +390 -55
- data/lib/commitgpt/config_manager.rb +164 -0
- data/lib/commitgpt/provider_presets.rb +19 -0
- data/lib/commitgpt/setup_wizard.rb +314 -0
- data/lib/commitgpt/string.rb +4 -0
- data/lib/commitgpt/version.rb +1 -1
- metadata +19 -9
- data/.rspec +0 -3
- data/.rubocop.yml +0 -19
- data/CHANGELOG.md +0 -5
- data/CODE_OF_CONDUCT.md +0 -84
- data/Gemfile +0 -19
- data/Gemfile.lock +0 -73
- data/LICENSE.txt +0 -21
- data/Rakefile +0 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 39ba14207dd3a3821b77597f628a3a5eb5c4d350bac6f5aac1828feda130f7df
|
|
4
|
+
data.tar.gz: d03c824c7e5f6b31a3e16dc1175def59b85980da67e9767a643242ea5d65b1df
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 84fed7c25c40981c4ac1c6d29e26c5260b3b79a59e7e7921aec5d0f176d826f07c06d21d354fd7168d3b0a0f17a9bcd834271d17cd5a2db0cf63964de02a4dd0
|
|
7
|
+
data.tar.gz: e443c012f0ddb35f03551a4d7b943dd207c5500f647e6cacf429f20e3ce1e6863eced86f9292232c7ce49a6aa6fb2d088e180d3c59b8bc268e24fd07d980b097
|
data/README.md
CHANGED
|
@@ -8,128 +8,266 @@
|
|
|
8
8
|
---
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
|
+
|
|
12
|
+
### Method 1: Homebrew (Recommended)
|
|
13
|
+
|
|
14
|
+
The easiest way to install and keep CommitGPT updated.
|
|
15
|
+
|
|
16
|
+
**Install:**
|
|
17
|
+
|
|
11
18
|
```bash
|
|
12
|
-
|
|
19
|
+
brew tap ZPVIP/commitgpt https://github.com/ZPVIP/commitgpt
|
|
20
|
+
brew install commitgpt
|
|
13
21
|
```
|
|
14
22
|
|
|
15
|
-
|
|
23
|
+
**Upgrade:**
|
|
16
24
|
|
|
17
|
-
### API Key
|
|
18
|
-
Grab your API key and add it as an env variable.
|
|
19
25
|
```bash
|
|
20
|
-
|
|
26
|
+
brew update
|
|
27
|
+
brew upgrade commitgpt
|
|
21
28
|
```
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
**Uninstall:**
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
brew uninstall commitgpt
|
|
34
|
+
# Optional: Remove configuration files manually
|
|
35
|
+
rm -rf ~/.config/commitgpt
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
### Method 2: RubyGems (For Ruby Developers)
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary>Click to expand RubyGems installation instructions</summary>
|
|
42
|
+
|
|
43
|
+
#### Prerequisites: Install Ruby
|
|
44
|
+
|
|
45
|
+
If you don't have Ruby installed, follow these steps first.
|
|
46
|
+
|
|
47
|
+
<details>
|
|
48
|
+
<summary><strong>macOS</strong></summary>
|
|
49
|
+
|
|
50
|
+
**1. Install Homebrew** (skip if already installed)
|
|
24
51
|
|
|
25
|
-
### Custom API Endpoint (Optional)
|
|
26
|
-
You can use any OpenAI-compatible API provider by setting `AICM_LINK`:
|
|
27
52
|
```bash
|
|
28
|
-
|
|
29
|
-
|
|
53
|
+
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
|
54
|
+
echo 'export PATH="/opt/homebrew/bin:$PATH"' >> ~/.zshrc
|
|
55
|
+
source ~/.zshrc
|
|
56
|
+
```
|
|
30
57
|
|
|
31
|
-
|
|
32
|
-
# Cerebras
|
|
33
|
-
$ export AICM_LINK=https://api.cerebras.ai/v1
|
|
58
|
+
**2. Install Ruby dependencies**
|
|
34
59
|
|
|
35
|
-
|
|
36
|
-
|
|
60
|
+
```bash
|
|
61
|
+
brew install openssl@3 libyaml gmp rust
|
|
37
62
|
```
|
|
38
63
|
|
|
39
|
-
>
|
|
64
|
+
</details>
|
|
65
|
+
|
|
66
|
+
<details>
|
|
67
|
+
<summary><strong>Ubuntu / Debian</strong></summary>
|
|
68
|
+
|
|
69
|
+
**Install Ruby dependencies**
|
|
40
70
|
|
|
41
|
-
### List Models
|
|
42
|
-
Use `-m` to list all available models from your API provider:
|
|
43
71
|
```bash
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
72
|
+
sudo apt-get update
|
|
73
|
+
sudo apt install build-essential rustc libssl-dev libyaml-dev zlib1g-dev libgmp-dev
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
</details>
|
|
77
|
+
|
|
78
|
+
**Install Ruby with Mise** (version manager)
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
# Install Mise
|
|
82
|
+
curl https://mise.run | sh
|
|
83
|
+
|
|
84
|
+
# For zsh (macOS default)
|
|
85
|
+
echo 'eval "$(~/.local/bin/mise activate)"' >> ~/.zshrc
|
|
86
|
+
source ~/.zshrc
|
|
87
|
+
|
|
88
|
+
# For bash (Ubuntu default)
|
|
89
|
+
# echo 'eval "$(~/.local/bin/mise activate)"' >> ~/.bashrc
|
|
90
|
+
# source ~/.bashrc
|
|
91
|
+
|
|
92
|
+
# Install Ruby
|
|
93
|
+
mise use --global ruby@3
|
|
94
|
+
|
|
95
|
+
# Verify installation
|
|
96
|
+
ruby --version
|
|
97
|
+
#=> 3.4.7
|
|
98
|
+
|
|
99
|
+
# Update RubyGems
|
|
100
|
+
gem update --system
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
#### Install CommitGPT
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
gem install commitgpt
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
</details>
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## Configuration
|
|
114
|
+
|
|
115
|
+
CommitGPT uses a YAML configuration system (`~/.config/commitgpt/`) to support multiple providers and per-provider settings.
|
|
116
|
+
|
|
117
|
+
### Interactive Setup (Recommended)
|
|
118
|
+
Run the setup wizard to configure your provider:
|
|
119
|
+
```bash
|
|
120
|
+
$ aicm setup
|
|
48
121
|
```
|
|
49
122
|
|
|
50
|
-
|
|
51
|
-
|
|
123
|
+
You'll be guided to:
|
|
124
|
+
1. Choose an AI provider (Presets: Cerebras, OpenAI, Ollama, Groq, etc.)
|
|
125
|
+
2. Enter your API Key (stored securely in `config.local.yml`)
|
|
126
|
+
3. Select a model interactively
|
|
127
|
+
4. Set maximum diff length
|
|
128
|
+
|
|
129
|
+
**Note:** Please add `~/.config/commitgpt/config.local.yml` to your `.gitignore` if you are syncing your home directory, as it contains your API keys.
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
## Usage
|
|
134
|
+
|
|
135
|
+
### Generate Commit Message
|
|
136
|
+
Stage your changes and run `aicm`:
|
|
52
137
|
```bash
|
|
53
|
-
$ cd /path/to/your/repo
|
|
54
138
|
$ git add .
|
|
55
139
|
$ aicm
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Switch Provider
|
|
143
|
+
Switch between configured providers easily:
|
|
144
|
+
```bash
|
|
145
|
+
$ aicm -p
|
|
146
|
+
# or
|
|
147
|
+
$ aicm --provider
|
|
148
|
+
```
|
|
56
149
|
|
|
57
|
-
|
|
58
|
-
|
|
150
|
+
### Select Model
|
|
151
|
+
Interactively list and select a model for your current provider:
|
|
152
|
+
```bash
|
|
153
|
+
$ aicm -m
|
|
154
|
+
# or
|
|
155
|
+
$ aicm --models
|
|
156
|
+
```
|
|
59
157
|
|
|
60
|
-
|
|
158
|
+
### Check Configuration
|
|
159
|
+
View your current configuration (Provider, Model, Base URL, Diff Len):
|
|
160
|
+
```bash
|
|
161
|
+
$ aicm help
|
|
162
|
+
```
|
|
163
|
+
(Use the help command to see current active provider settings)
|
|
61
164
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
165
|
+
### View Git Diff
|
|
166
|
+
Preview the diff that will be sent to the AI:
|
|
167
|
+
```bash
|
|
168
|
+
$ aicm -v
|
|
65
169
|
```
|
|
66
170
|
|
|
67
171
|
### Update
|
|
68
|
-
To update to the latest version:
|
|
172
|
+
To update to the latest version (if installed via Gem):
|
|
69
173
|
```bash
|
|
70
174
|
$ gem update commitgpt
|
|
71
|
-
$ gem cleanup commitgpt
|
|
72
|
-
$ gem info commitgpt
|
|
73
175
|
```
|
|
74
176
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
| Environment Variable | Required | Default | Description |
|
|
78
|
-
|---------------------|----------|---------|-------------|
|
|
79
|
-
| `AICM_KEY` | No* | `nil` | Your API key. Required when using official OpenAI API. |
|
|
80
|
-
| `AICM_LINK` | No | `https://api.openai.com/v1` | Custom API endpoint for OpenAI-compatible services. |
|
|
81
|
-
| `AICM_MODEL` | Yes | `gpt-4o-mini` | Model to use for generating commit messages. |
|
|
82
|
-
| `AICM_DIFF_LEN` | No | `32768` | Maximum diff length in characters. Increase if you have large diffs. |
|
|
83
|
-
|
|
84
|
-
\* Required when using the default OpenAI endpoint.
|
|
177
|
+
---
|
|
85
178
|
|
|
86
|
-
|
|
179
|
+
## Supported Providers
|
|
180
|
+
We support any OpenAI-compatible API. Presets available for:
|
|
181
|
+
- **Cerebras** (Fast & Recommended)
|
|
182
|
+
- **OpenAI** (Official)
|
|
183
|
+
- **Ollama** (Local)
|
|
184
|
+
- **Groq**
|
|
185
|
+
- **DeepSeek**
|
|
186
|
+
- **Anthropic (Claude)**
|
|
187
|
+
- **Google AI (Gemini)**
|
|
188
|
+
- **Mistral**
|
|
189
|
+
- **OpenRouter**
|
|
190
|
+
- **Local setups** (LM Studio, LLaMa.cpp, Llamafile)
|
|
87
191
|
|
|
88
|
-
|
|
192
|
+
### Recommended Providers
|
|
89
193
|
|
|
90
|
-
**OpenAI** ([https://
|
|
194
|
+
**OpenAI** ([https://platform.openai.com](https://platform.openai.com))
|
|
91
195
|
```
|
|
92
|
-
gpt-
|
|
93
|
-
gpt-5-mini
|
|
94
|
-
gpt-5-nano
|
|
196
|
+
gpt-4o
|
|
95
197
|
gpt-4o-mini
|
|
96
198
|
```
|
|
97
199
|
|
|
98
|
-
**Cerebras** ([https://
|
|
200
|
+
**Cerebras** ([https://cloud.cerebras.ai](https://cloud.cerebras.ai)) ⭐ Recommended
|
|
99
201
|
```
|
|
100
|
-
zai-glm-4.
|
|
101
|
-
zai-glm-4.7
|
|
102
|
-
gpt-oss-120b
|
|
202
|
+
zai-glm-4.7 # ⭐ Best for commit messages - fast & accurate
|
|
103
203
|
llama3.1-8b
|
|
104
204
|
llama-3.3-70b
|
|
105
|
-
qwen-3-32b
|
|
106
|
-
qwen-3-235b-a22b-instruct-2507
|
|
107
|
-
|
|
108
205
|
```
|
|
109
206
|
|
|
110
|
-
**Groq** ([https://
|
|
207
|
+
**Groq** ([https://console.groq.com](https://console.groq.com))
|
|
111
208
|
```
|
|
112
209
|
llama-3.3-70b-versatile
|
|
113
210
|
llama-3.1-8b-instant
|
|
114
|
-
meta-llama/llama-4-maverick-17b-128e-instruct
|
|
115
|
-
meta-llama/llama-4-scout-17b-16e-instruct
|
|
116
|
-
qwen/qwen3-32b
|
|
117
|
-
moonshotai/kimi-k2-instruct-0905
|
|
118
|
-
openai/gpt-oss-120b
|
|
119
|
-
groq/compound
|
|
120
|
-
groq/compound-mini
|
|
121
211
|
```
|
|
122
212
|
|
|
123
213
|
## How It Works
|
|
124
|
-
This CLI tool runs a `git diff` command to grab all staged changes, sends this to OpenAI's GPT API (or compatible endpoint), and returns an AI-generated commit message. The tool uses the `/v1/chat/completions` endpoint with optimized prompts for generating conventional commit messages.
|
|
125
|
-
|
|
126
|
-
## Limitations
|
|
127
|
-
- Only supports git diffs up to `AICM_DIFF_LEN` characters (default 32K)
|
|
128
|
-
- The generated commit message can't be edited interactively, but you can choose `n` and copy the command to edit manually
|
|
214
|
+
This CLI tool runs a `git diff` command to grab all staged changes, sends this to OpenAI's GPT API (or compatible endpoint), and returns an AI-generated commit message. The tool uses the `/v1/chat/completions` endpoint with optimized prompts/system instructions for generating conventional commit messages.
|
|
129
215
|
|
|
130
216
|
## Special Thanks
|
|
131
217
|
I used ChatGPT to convert `AICommits` from TypeScript to Ruby. Special thanks to [https://github.com/Nutlope/aicommits](https://github.com/Nutlope/aicommits)
|
|
132
218
|
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
## Development Guide
|
|
222
|
+
|
|
223
|
+
### Requirements
|
|
224
|
+
- Ruby >= 2.6.0
|
|
225
|
+
- Git
|
|
226
|
+
|
|
227
|
+
### Local Setup
|
|
228
|
+
1. Clone the repository:
|
|
229
|
+
```bash
|
|
230
|
+
git clone https://github.com/ZPVIP/commitgpt.git
|
|
231
|
+
cd commitgpt
|
|
232
|
+
```
|
|
233
|
+
2. Install dependencies:
|
|
234
|
+
```bash
|
|
235
|
+
bundle install
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### Local Build and Install
|
|
239
|
+
To test your changes locally (builds the gem and installs it to your system):
|
|
240
|
+
```bash
|
|
241
|
+
gem build commitgpt.gemspec
|
|
242
|
+
gem install ./commitgpt-*.gem
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
### Publishing
|
|
246
|
+
|
|
247
|
+
#### RubyGems
|
|
248
|
+
To publish a new version to RubyGems.org (requires RubyGems account permissions):
|
|
249
|
+
```bash
|
|
250
|
+
gem push commitgpt-*.gem
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
#### Homebrew (GitHub Distribution)
|
|
254
|
+
We use a custom script to automate the GitHub Release and Homebrew Formula update process. This enables users to install via `brew tap`.
|
|
255
|
+
|
|
256
|
+
**Steps:**
|
|
257
|
+
```bash
|
|
258
|
+
./scripts/release.sh <version>
|
|
259
|
+
# Example: ./scripts/release.sh 0.3.1
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
**This script automates:**
|
|
263
|
+
1. Creating and pushing a Git Tag.
|
|
264
|
+
2. Creating a GitHub Release (which generates the source tarball).
|
|
265
|
+
3. Calculating the SHA256 checksum of the tarball.
|
|
266
|
+
4. Updating `Formula/commitgpt.rb` with the new URL and checksum.
|
|
267
|
+
5. Committing and pushing the updated Formula to the repository.
|
|
268
|
+
|
|
269
|
+
---
|
|
270
|
+
|
|
133
271
|
## Contributing
|
|
134
272
|
Bug reports and pull requests are welcome on GitHub at https://github.com/ZPVIP/commitgpt. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ZPVIP/commitgpt/blob/main/CODE_OF_CONDUCT.md).
|
|
135
273
|
|
data/commitgpt.gemspec
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "lib/commitgpt/version"
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = "commitgpt"
|
|
7
|
+
spec.version = CommitGpt::VERSION
|
|
8
|
+
spec.authors = ["Peng Zhang"]
|
|
9
|
+
spec.email = ["zpregister@gmail.com"]
|
|
10
|
+
|
|
11
|
+
spec.summary = "A CLI AI that writes git commit messages for you."
|
|
12
|
+
spec.description = "A CLI that writes your git commit messages for you with AI. Never write a commit message again."
|
|
13
|
+
spec.homepage = "https://github.com/ZPVIP/commitgpt"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
spec.required_ruby_version = ">= 2.6.0"
|
|
16
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
17
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/master/CHANGELOG.md"
|
|
19
|
+
|
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
22
|
+
spec.files = Dir.glob("lib/**/*") + Dir.glob("bin/*") + %w[README.md LICENSE commitgpt.gemspec]
|
|
23
|
+
.reject { |f| File.directory?(f) }
|
|
24
|
+
spec.bindir = "bin"
|
|
25
|
+
spec.executables = spec.files.grep(%r{\Abin/}) { |f| File.basename(f) }
|
|
26
|
+
spec.require_paths = ["lib"]
|
|
27
|
+
|
|
28
|
+
# Uncomment to register a new dependency of your gem
|
|
29
|
+
spec.add_dependency "httparty", "~> 0.18"
|
|
30
|
+
spec.add_dependency "thor", "~> 1.2"
|
|
31
|
+
spec.add_dependency "tty-prompt", "~> 0.23"
|
|
32
|
+
|
|
33
|
+
# For more information and examples about making a new gem, checkout our
|
|
34
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
|
35
|
+
end
|
data/lib/commitgpt/cli.rb
CHANGED
|
@@ -2,21 +2,61 @@
|
|
|
2
2
|
|
|
3
3
|
require "thor"
|
|
4
4
|
require "commitgpt/commit_ai"
|
|
5
|
+
require "commitgpt/setup_wizard"
|
|
5
6
|
|
|
6
7
|
module CommitGpt
|
|
7
8
|
# CommitGpt CLI
|
|
8
9
|
class CLI < Thor
|
|
9
|
-
default_task :
|
|
10
|
+
default_task :generate
|
|
10
11
|
|
|
11
|
-
desc "
|
|
12
|
-
method_option :models, aliases: "-m", type: :boolean, desc: "List available models"
|
|
12
|
+
desc "generate", "AI commits for you!"
|
|
13
|
+
method_option :models, aliases: "-m", type: :boolean, desc: "List/Select available models"
|
|
13
14
|
method_option :verbose, aliases: "-v", type: :boolean, desc: "Show git diff being sent to AI"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
method_option :provider, aliases: "-p", type: :boolean, desc: "Switch active provider"
|
|
16
|
+
def generate
|
|
17
|
+
if options[:provider]
|
|
18
|
+
CommitGpt::SetupWizard.new.switch_provider
|
|
19
|
+
elsif options[:models]
|
|
20
|
+
CommitGpt::SetupWizard.new.change_model
|
|
17
21
|
else
|
|
18
22
|
CommitGpt::CommitAi.new.aicm(verbose: options[:verbose])
|
|
19
23
|
end
|
|
20
24
|
end
|
|
25
|
+
|
|
26
|
+
desc "setup", "Configure AI provider and settings"
|
|
27
|
+
def setup
|
|
28
|
+
CommitGpt::SetupWizard.new.run
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Custom help message
|
|
32
|
+
def self.help(shell, subcommand = false)
|
|
33
|
+
shell.say "Usage:"
|
|
34
|
+
shell.say " aicm # Generate AI commit message (Default)"
|
|
35
|
+
shell.say " aicm setup # Configure AI provider and settings"
|
|
36
|
+
shell.say " aicm help [COMMAND] # Describe available commands"
|
|
37
|
+
shell.say ""
|
|
38
|
+
shell.say "Options:"
|
|
39
|
+
shell.say " -m, --models # Interactive model selection"
|
|
40
|
+
shell.say " -p, --provider # Switch active provider"
|
|
41
|
+
shell.say " -v, --verbose # Show git diff being sent to AI"
|
|
42
|
+
shell.say ""
|
|
43
|
+
|
|
44
|
+
# Show current configuration
|
|
45
|
+
begin
|
|
46
|
+
require "commitgpt/config_manager"
|
|
47
|
+
require "commitgpt/string"
|
|
48
|
+
config = CommitGpt::ConfigManager.get_active_provider_config
|
|
49
|
+
if config
|
|
50
|
+
shell.say "Current Configuration:"
|
|
51
|
+
shell.say " Provider: #{config['name'].green}"
|
|
52
|
+
shell.say " Model: #{config['model'].cyan}"
|
|
53
|
+
shell.say " Base URL: #{config['base_url']}"
|
|
54
|
+
shell.say " Diff Len: #{config['diff_len']}"
|
|
55
|
+
shell.say ""
|
|
56
|
+
end
|
|
57
|
+
rescue StandardError
|
|
58
|
+
# Ignore errors during help display if config is missing/invalid
|
|
59
|
+
end
|
|
60
|
+
end
|
|
21
61
|
end
|
|
22
62
|
end
|