ai-commit-message 0.1.1 → 0.1.2
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 +107 -2
- data/lib/ai-commit-message/cli.rb +24 -7
- data/lib/ai-commit-message/config_manager.rb +4 -4
- data/lib/ai-commit-message/suggester.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 829bf4eb533e768334fd7f8ff083f2ec00d1c113a4b394b55e2802f4a30eb9db
|
4
|
+
data.tar.gz: 962c1f333ecde972d3710884f5c9cbfcd9afb72755af66bdf6de0d6e44eb8a88
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 65391923463e9a944a0974962acec6510a2615437b83394f19c7418565a25ab0ceb3f2e5058928df14352f7dd92950367b5529f05bb74fc756364f220cace722
|
7
|
+
data.tar.gz: c6e7f071038a300f68316dc8e9c31a66c8dba1a4e4060f9c06950e0094f42b90d5db23a1fdfdbc0d72718da8a791a57fac18a9746cccb113abc627089b95cb2f
|
data/README.md
CHANGED
@@ -1,2 +1,107 @@
|
|
1
|
-
#
|
2
|
-
|
1
|
+
# AI git commit message
|
2
|
+
|
3
|
+
A Ruby gem that automatically generates concise and meaningful git commit messages using AI models via [Ollama](https://github.com/ollama/ollama) or any OpenAI-compatible API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem using:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
gem install ai-commit-message
|
11
|
+
```
|
12
|
+
|
13
|
+
Or add it to your Gemfile:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
gem 'ai-commit-message'
|
17
|
+
```
|
18
|
+
|
19
|
+
And then run:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
bundle install
|
23
|
+
```
|
24
|
+
|
25
|
+
## Requirements
|
26
|
+
|
27
|
+
- Ruby 3.0 or newer
|
28
|
+
- Git repository
|
29
|
+
- [Ollama](https://github.com/ollama/ollama) model running locally or other OpenAI-compatible API endpoint
|
30
|
+
|
31
|
+
## Usage
|
32
|
+
|
33
|
+
### Basic Usage
|
34
|
+
|
35
|
+
Generate a commit message for your staged changes:
|
36
|
+
|
37
|
+
```bash
|
38
|
+
ai-commit-message commit
|
39
|
+
```
|
40
|
+
|
41
|
+
This will:
|
42
|
+
1. Analyze your staged changes (`git diff --cached`)
|
43
|
+
2. Review your recent commit history for style consistency
|
44
|
+
3. Consider your current branch name
|
45
|
+
4. Generate an appropriate commit message
|
46
|
+
|
47
|
+
### Configuration
|
48
|
+
|
49
|
+
You can configure the gem using the built-in configuration command:
|
50
|
+
|
51
|
+
```bash
|
52
|
+
ai-commit-message config
|
53
|
+
```
|
54
|
+
|
55
|
+
This interactive prompt allows you to set:
|
56
|
+
- **API URL**: The endpoint for your AI model (defaults to `http://localhost:11434/api/generate`)
|
57
|
+
- **Model name**: The AI model to use (defaults to `qwen2.5-coder:7b`, which I personally recommend)
|
58
|
+
|
59
|
+
### Command Line Options
|
60
|
+
|
61
|
+
Override configuration settings directly:
|
62
|
+
|
63
|
+
```bash
|
64
|
+
ai-commit-message commit --url=http://your-api-endpoint --model=your-model-name
|
65
|
+
```
|
66
|
+
|
67
|
+
## How It Works
|
68
|
+
|
69
|
+
The gem:
|
70
|
+
1. Collects your staged changes using `git diff --cached`
|
71
|
+
2. Retrieves your recent commit history for context
|
72
|
+
3. Identifies your current branch name
|
73
|
+
4. Sends this information to the specified AI model
|
74
|
+
5. Returns a concise, contextual commit message (limited to 250 characters)
|
75
|
+
|
76
|
+
## Configuration File
|
77
|
+
|
78
|
+
The gem stores your configuration in `~/.ai-commit-message.conf`. You can manually edit this file if needed. Example:
|
79
|
+
|
80
|
+
```bash
|
81
|
+
url=http://localhost:11434/api/generate
|
82
|
+
model=qwen2.5-coder:7b
|
83
|
+
```
|
84
|
+
|
85
|
+
## Models
|
86
|
+
|
87
|
+
The default configuration uses Ollama with the `qwen2.5-coder:7b` model, but you can use any model available through your API endpoint.
|
88
|
+
|
89
|
+
### Recommended Models
|
90
|
+
|
91
|
+
- **qwen2.5-coder:7b**: Good balance of quality and speed (default)
|
92
|
+
- **llama3:8b**: Excellent for general commit messages
|
93
|
+
- **codellama:7b**: Specialized for code-related commits
|
94
|
+
|
95
|
+
## Contributing
|
96
|
+
|
97
|
+
1. Fork the repository
|
98
|
+
2. Create your feature branch: `git checkout -b my-new-feature`
|
99
|
+
3. Install dependencies: `bundle install`
|
100
|
+
4. Make your changes and add tests if applicable
|
101
|
+
5. Commit your changes: `git commit -m 'Add some feature'`
|
102
|
+
6. Push to the branch: `git push origin my-new-feature`
|
103
|
+
7. Submit a pull request
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
This gem is available as open source free to use/alter without restrictions.
|
@@ -5,17 +5,20 @@ require_relative 'config_manager'
|
|
5
5
|
|
6
6
|
module AiCommitMessage
|
7
7
|
class CLI < Thor
|
8
|
+
DEFAULT_URL = 'http://localhost:11434'
|
9
|
+
DEFAULT_MODEL_NAME = 'qwen2.5-coder:7b'
|
10
|
+
|
8
11
|
desc "commit", "Generate git commit message"
|
9
|
-
method_option :url, type: :string, default:
|
10
|
-
method_option :model, type: :string, default:
|
12
|
+
method_option :url, type: :string, default: DEFAULT_URL
|
13
|
+
method_option :model, type: :string, default: DEFAULT_MODEL_NAME
|
11
14
|
|
12
|
-
def commit
|
15
|
+
def commit
|
13
16
|
git_diff_output = `git diff --cached --no-color`
|
14
17
|
git_log_output = `git log --format=%s -n 30`
|
15
18
|
git_current_branch = `git branch --show-current`
|
16
19
|
|
17
|
-
url = options
|
18
|
-
model = options
|
20
|
+
url = url_to_be_used(options.url)
|
21
|
+
model = model_to_be_used(options.model)
|
19
22
|
|
20
23
|
suggester = AiCommitMessage::Suggester.new(git_diff_output, git_log_output, git_current_branch)
|
21
24
|
commit_message = suggester.generate_commit_message(url:, model:)
|
@@ -27,14 +30,28 @@ module AiCommitMessage
|
|
27
30
|
def config
|
28
31
|
prompt = TTY::Prompt.new
|
29
32
|
|
30
|
-
url = prompt.ask("API URL:", default: ConfigManager.get_url ||
|
31
|
-
model = prompt.ask("Model name:", default: ConfigManager.get_model ||
|
33
|
+
url = prompt.ask("API URL:", default: ConfigManager.get_url || DEFAULT_URL)
|
34
|
+
model = prompt.ask("Model name:", default: ConfigManager.get_model || DEFAULT_MODEL_NAME)
|
32
35
|
|
33
36
|
ConfigManager.set_url(url)
|
34
37
|
ConfigManager.set_model(model)
|
35
38
|
|
36
39
|
puts "Configuration updated successfully!"
|
37
40
|
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def url_to_be_used(options_url)
|
45
|
+
return options_url if !options_url.empty? && (options_url != DEFAULT_URL)
|
46
|
+
|
47
|
+
ConfigManager.get_url || DEFAULT_URL
|
48
|
+
end
|
49
|
+
|
50
|
+
def model_to_be_used(options_model)
|
51
|
+
return options_model if !options_model.empty? && (options_model != DEFAULT_MODEL_NAME)
|
52
|
+
|
53
|
+
ConfigManager.get_model || DEFAULT_MODEL_NAME
|
54
|
+
end
|
38
55
|
end
|
39
56
|
end
|
40
57
|
|
@@ -3,17 +3,17 @@ require 'fileutils'
|
|
3
3
|
class ConfigManager
|
4
4
|
CONFIG_FILE = File.expand_path('~/.ai-commit-message.conf')
|
5
5
|
|
6
|
-
def self.get_url = config[
|
6
|
+
def self.get_url = config[:url]
|
7
7
|
|
8
8
|
def self.set_url(url)
|
9
|
-
config[
|
9
|
+
config[:url] = url
|
10
10
|
save_config
|
11
11
|
end
|
12
12
|
|
13
|
-
def self.get_model = config[
|
13
|
+
def self.get_model = config[:model]
|
14
14
|
|
15
15
|
def self.set_model(model)
|
16
|
-
config[
|
16
|
+
config[:model] = model
|
17
17
|
save_config
|
18
18
|
end
|
19
19
|
|
@@ -11,7 +11,7 @@ module AiCommitMessage
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def generate_commit_message(url:, model:)
|
14
|
-
url = URI(url)
|
14
|
+
url = URI(url + '/api/generate')
|
15
15
|
body = {
|
16
16
|
model: model,
|
17
17
|
prompt: "Create a concise git commit message with no more than 250 characters. Exclude anything unnecessary such as translation, backticks characters or multiple suggestions, since your entire response will be passed directly into git commit. Consider the following messages as example to follow: #{@git_log_output}.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ai-commit-message
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Afonso Neto
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|