commitgpt 0.1.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a73fe2965f7f3fedb44a5173fcd2dfb888c909c3ea275bed72ae1474f6bfe7cc
4
- data.tar.gz: 22388d33280bd6c90a4febff1964eab35b558befc777465374b420567d080e35
3
+ metadata.gz: 39ba14207dd3a3821b77597f628a3a5eb5c4d350bac6f5aac1828feda130f7df
4
+ data.tar.gz: d03c824c7e5f6b31a3e16dc1175def59b85980da67e9767a643242ea5d65b1df
5
5
  SHA512:
6
- metadata.gz: 5d0af4dacb622f9c893bafadf5bafe45a48fdd7664a29c804e122ae9cddafea13d7d8a61a0345215cffe6552e15ba4e8e6d0888515a12527b7e79f7305a3e238
7
- data.tar.gz: bc785e338d404f12f8d6e5b94659ae4aa8dc9301507722ec78b73f7f85ea7824e2e8ce718563fa5a1cf69c1c56d62e0ad8cb8f66646418b56865ebc9a061be4a
6
+ metadata.gz: 84fed7c25c40981c4ac1c6d29e26c5260b3b79a59e7e7921aec5d0f176d826f07c06d21d354fd7168d3b0a0f17a9bcd834271d17cd5a2db0cf63964de02a4dd0
7
+ data.tar.gz: e443c012f0ddb35f03551a4d7b943dd207c5500f647e6cacf429f20e3ce1e6863eced86f9292232c7ce49a6aa6fb2d088e180d3c59b8bc268e24fd07d980b097
data/README.md CHANGED
@@ -8,53 +8,271 @@
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
- $ gem install commitgpt
19
+ brew tap ZPVIP/commitgpt https://github.com/ZPVIP/commitgpt
20
+ brew install commitgpt
13
21
  ```
14
22
 
15
- ## Usage
16
- ### API key
17
- grab your [OpenAI key](https://openai.com/api/) and add it as an env variable.
23
+ **Upgrade:**
24
+
25
+ ```bash
26
+ brew update
27
+ brew upgrade commitgpt
28
+ ```
29
+
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)
51
+
52
+ ```bash
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
+ ```
57
+
58
+ **2. Install Ruby dependencies**
59
+
60
+ ```bash
61
+ brew install openssl@3 libyaml gmp rust
62
+ ```
63
+
64
+ </details>
65
+
66
+ <details>
67
+ <summary><strong>Ubuntu / Debian</strong></summary>
68
+
69
+ **Install Ruby dependencies**
70
+
71
+ ```bash
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
+
18
105
  ```bash
19
- $ export OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxx
106
+ gem install commitgpt
20
107
  ```
21
- It's recommended to add the first line to your `.zshrc` or `.bashrc` so it persists instead of having to define it in each terminal session.
22
-
23
- ### aicm
24
- `aicm` is an abbreviation for `AI commits`, after `git add .` add your file to stage, then use `aicm` to commit with an AI generated commit message.
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
121
+ ```
122
+
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`:
25
137
  ```bash
26
- $ cd /path/to/your/repo
27
138
  $ git add .
28
139
  $ aicm
140
+ ```
141
+
142
+ ### Switch Provider
143
+ Switch between configured providers easily:
144
+ ```bash
145
+ $ aicm -p
146
+ # or
147
+ $ aicm --provider
148
+ ```
149
+
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
+ ```
157
+
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)
164
+
165
+ ### View Git Diff
166
+ Preview the diff that will be sent to the AI:
167
+ ```bash
168
+ $ aicm -v
169
+ ```
170
+
171
+ ### Update
172
+ To update to the latest version (if installed via Gem):
173
+ ```bash
174
+ $ gem update commitgpt
175
+ ```
176
+
177
+ ---
178
+
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)
191
+
192
+ ### Recommended Providers
29
193
 
30
- Welcome to AI Commits!
31
- ▲ Generating your AI commit message...
194
+ **OpenAI** ([https://platform.openai.com](https://platform.openai.com))
195
+ ```
196
+ gpt-4o
197
+ gpt-4o-mini
198
+ ```
32
199
 
33
- Commit message: git commit -am "Update README.md with contribution instructions and OpenAI API key instructions."
200
+ **Cerebras** ([https://cloud.cerebras.ai](https://cloud.cerebras.ai)) Recommended
201
+ ```
202
+ zai-glm-4.7 # ⭐ Best for commit messages - fast & accurate
203
+ llama3.1-8b
204
+ llama-3.3-70b
205
+ ```
34
206
 
35
- Do you want to commit this message? [y/n]
36
- [main c082637] Update README.md with contribution instructions and OpenAI API key instructions.
37
- 4 files changed, 24 insertions(+), 19 deletions(-)
207
+ **Groq** ([https://console.groq.com](https://console.groq.com))
38
208
  ```
209
+ llama-3.3-70b-versatile
210
+ llama-3.1-8b-instant
211
+ ```
212
+
213
+ ## How It Works
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.
39
215
 
40
216
  ## Special Thanks
41
- I used chatGPT to convert `AICommits`(JS) to `CommitGPT`(Ruby). Thanks to [https://github.com/Nutlope/aicommits](https://github.com/Nutlope/aicommits)
217
+ I used ChatGPT to convert `AICommits` from TypeScript to Ruby. Special thanks to [https://github.com/Nutlope/aicommits](https://github.com/Nutlope/aicommits)
42
218
 
43
- ## How it works
44
- This CLI tool runs a git diff command to grab all the latest changes, sends this to OpenAI's GPT-3, then returns the AI generated commit message. I also want to note that it does cost money since GPT-3 generations aren't free. However, OpenAI gives folks $18 of free credits and commit message generations are cheap so it should be free for a long time.
219
+ ---
45
220
 
46
- ## Limitations
47
- Only supports git diffs of up to 200 lines of code for now
48
- The generated commit message can't be edited yet, but you can choose `n` and copy the commit command and edit it manually.
221
+ ## Development Guide
49
222
 
50
- ## Contributing
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
51
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
+
271
+ ## Contributing
52
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).
53
273
 
54
274
  ## License
55
-
56
275
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
57
276
 
58
277
  ## Code of Conduct
59
-
60
278
  Everyone interacting in the CommitGpt project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/ZPVIP/commitgpt/blob/master/CODE_OF_CONDUCT.md).
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,15 +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 :aicm
10
+ default_task :generate
10
11
 
11
- desc "aicm", "AI commits for you!"
12
- def aicm
13
- CommitGpt::CommitAi.new.aicm
12
+ desc "generate", "AI commits for you!"
13
+ method_option :models, aliases: "-m", type: :boolean, desc: "List/Select available models"
14
+ method_option :verbose, aliases: "-v", type: :boolean, desc: "Show git diff being sent to AI"
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
21
+ else
22
+ CommitGpt::CommitAi.new.aicm(verbose: options[:verbose])
23
+ end
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
14
60
  end
15
61
  end
16
62
  end