gitlore 0.1.0
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 +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +8 -0
- data/CHANGELOG.md +5 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +12 -0
- data/bin/gitlore +4 -0
- data/lib/gitlore/version.rb +5 -0
- data/lib/gitlore.rb +124 -0
- data/sig/gitlore.rbs +4 -0
- metadata +54 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 83df2ec7f1aeb81a17d1981379cad4d58b7215b9dcc25efdebbda0efe0953c60
|
4
|
+
data.tar.gz: 40ef139142e1c2d80f63e1ff5df5fa6c900fab2b7f55164b938eb8b6254ebaa6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 33a1492a53f6503a83547c1c0a0f76984484d55b782ff0e7fdbf84a29e08926a050b8b56cc9c5f95f2e97f6d5b8103f425e437da0794531946f8d0f28fa0945c
|
7
|
+
data.tar.gz: d37d5e112e2a14407a605ba85841e53bc85e45deb8b4546579e1f0215137b9607b338163d93240f40046593c72685092d90735149f6740992d7088366553ae45
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2025 Johnny
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Gitlore
|
2
|
+
|
3
|
+
Gitlore is a simple cli tool to summarize git commits. Run gitlore in a git repository to select the number of commits to summarize, choose the style of the summary, and the model either one from OpenAI or a locally running model via Ollama.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
```bash
|
10
|
+
bundle add gitlore
|
11
|
+
```
|
12
|
+
|
13
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
14
|
+
|
15
|
+
```bash
|
16
|
+
gem install gitlore
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Navigate to a git repository and run gitlore in that directory.
|
22
|
+
|
23
|
+
## Development
|
24
|
+
|
25
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
26
|
+
|
27
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
28
|
+
|
29
|
+
## Contributing
|
30
|
+
|
31
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jtheol/gitlore.
|
32
|
+
|
33
|
+
## License
|
34
|
+
|
35
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/gitlore
ADDED
data/lib/gitlore.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "gitlore/version"
|
4
|
+
require "openai"
|
5
|
+
require "tty-prompt"
|
6
|
+
require "tty-markdown"
|
7
|
+
require "pastel"
|
8
|
+
require "faraday"
|
9
|
+
require "json"
|
10
|
+
|
11
|
+
# Gitlore: Summarize git commits with AI.
|
12
|
+
# A CLI tool that transforms git commits into natural summaries.
|
13
|
+
module Gitlore
|
14
|
+
@prompt = TTY::Prompt.new
|
15
|
+
@pastel = Pastel.new
|
16
|
+
|
17
|
+
def self.client
|
18
|
+
@client ||= OpenAI::Client.new(api_key: ENV["OPENAI_API_KEY"]) if ENV["OPENAI_API_KEY"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.choose_openai_model
|
22
|
+
return nil unless client && api_key_error
|
23
|
+
|
24
|
+
begin
|
25
|
+
model_names = client.models.list.data.map(&:id).sort.select do |model|
|
26
|
+
model.include?("gpt")
|
27
|
+
end
|
28
|
+
@prompt.select("Choose an OpenAI model:", model_names, per_page: 10)
|
29
|
+
rescue StandardError => e
|
30
|
+
puts "#{@pastel.red("Error listing models:")} #{e.message}"
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.summarize_git
|
36
|
+
count = @prompt.ask("How many recent commits do you want to summarize?", default: "10").to_i
|
37
|
+
provider = @prompt.select("Choose model provider", %w[openai ollama])
|
38
|
+
style = @prompt.select("Choose summary style:", %w[narrative technical])
|
39
|
+
|
40
|
+
git_log = `git log -n #{count} --pretty=format:"%h %s (%an)"`
|
41
|
+
puts "\n#{@pastel.cyan("🧾 Git Log:")}\n\n#{git_log}\n\n"
|
42
|
+
|
43
|
+
system_prompts = {
|
44
|
+
"narrative" => "You are a skilled storyteller. Given a list of git commits, your task is to craft a concise and
|
45
|
+
engaging narrative that captures the essence of the changes, making them accessible and compelling for a
|
46
|
+
non-technical audience.",
|
47
|
+
"technical" => "You are a senior software engineer. Given a list of git commits, your task is
|
48
|
+
to produce a precise, technically accurate summary of the changes, suitable for other developers and engineers."
|
49
|
+
}
|
50
|
+
|
51
|
+
case provider
|
52
|
+
when "openai"
|
53
|
+
summarize_with_openai(git_log, system_prompts[style])
|
54
|
+
else
|
55
|
+
summarize_with_ollama(git_log, system_prompts[style])
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def self.summarize_with_openai(git_log, system_prompt)
|
60
|
+
selected_model = choose_openai_model
|
61
|
+
response = client.chat.completions.create(
|
62
|
+
model: selected_model,
|
63
|
+
messages: [
|
64
|
+
{ role: "system", content: system_prompt },
|
65
|
+
{ role: "user", content: "Summarize these commits:\n\n#{git_log}" }
|
66
|
+
],
|
67
|
+
temperature: 0
|
68
|
+
)
|
69
|
+
summary = response.choices[0].message.content
|
70
|
+
puts TTY::Markdown.parse(summary)
|
71
|
+
summary
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.summarize_with_ollama(git_log, system_prompt)
|
75
|
+
conn = Faraday.new(url: "http://localhost:11434") do |f|
|
76
|
+
f.request :json
|
77
|
+
f.adapter Faraday.default_adapter
|
78
|
+
end
|
79
|
+
|
80
|
+
models_response = conn.get("/api/tags")
|
81
|
+
if models_response.status != 200
|
82
|
+
puts "#{@pastel.red("Error:")} Could not fetch models from Ollama server. Check if Ollama is running."
|
83
|
+
return "Failed to connect to Ollama."
|
84
|
+
end
|
85
|
+
|
86
|
+
models = JSON.parse(models_response.body)["models"]
|
87
|
+
model_names = models.map { |m| m["name"] }
|
88
|
+
|
89
|
+
if model_names.empty?
|
90
|
+
puts "#{@pastel.red("Error:")} No models found on Ollama server."
|
91
|
+
return "No models available."
|
92
|
+
end
|
93
|
+
|
94
|
+
local_model = @prompt.select("Choose the local model to use", model_names)
|
95
|
+
|
96
|
+
chat_response = conn.post("/api/chat") do |req|
|
97
|
+
req.headers["Content-Type"] = "application/json"
|
98
|
+
req.body = {
|
99
|
+
model: local_model,
|
100
|
+
messages: [
|
101
|
+
{ role: "system", content: system_prompt },
|
102
|
+
{ role: "user", content: "Summarize these commits:\n\n#{git_log}" }
|
103
|
+
],
|
104
|
+
stream: false
|
105
|
+
}
|
106
|
+
end
|
107
|
+
|
108
|
+
if chat_response.status != 200
|
109
|
+
puts "#{@pastel.red("Error:")} Failed to get response from Ollama."
|
110
|
+
return "Failed to get Ollama response."
|
111
|
+
end
|
112
|
+
|
113
|
+
summary = JSON.parse(chat_response.body)["message"]["content"]
|
114
|
+
puts TTY::Markdown.parse(summary)
|
115
|
+
summary
|
116
|
+
end
|
117
|
+
|
118
|
+
def self.api_key_error
|
119
|
+
return true if ENV["OPENAI_API_KEY"]
|
120
|
+
|
121
|
+
puts "#{@pastel.red("Error:")} OPENAI_API_KEY environment variable is not set."
|
122
|
+
false
|
123
|
+
end
|
124
|
+
end
|
data/sig/gitlore.rbs
ADDED
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitlore
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jtheol
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-05-03 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: A simple cli tool to create summaries of git commits using LLMs.
|
14
|
+
email:
|
15
|
+
- jtheol
|
16
|
+
executables:
|
17
|
+
- gitlore
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- CHANGELOG.md
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/gitlore
|
28
|
+
- lib/gitlore.rb
|
29
|
+
- lib/gitlore/version.rb
|
30
|
+
- sig/gitlore.rbs
|
31
|
+
homepage: https://github.com/jtheol/gitlore
|
32
|
+
licenses:
|
33
|
+
- MIT
|
34
|
+
metadata: {}
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options: []
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: 3.0.0
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
requirements: []
|
50
|
+
rubygems_version: 3.5.22
|
51
|
+
signing_key:
|
52
|
+
specification_version: 4
|
53
|
+
summary: A simple cli tool to create summaries of git commits using LLMs.
|
54
|
+
test_files: []
|