commit_ai 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/exe/commit_ai +9 -0
- data/lib/commit_ai/version.rb +5 -0
- data/lib/commit_ai.rb +83 -0
- metadata +67 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4c2024d0852ec8b42072eb400dc56cc2d7e1bcc3a1485f65995736e901f8acdb
|
4
|
+
data.tar.gz: 15c4a169ffbec2cc5259f1c0ea29b5b1276f262b0e61fb9fb34e455a87c02f19
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f8db400d8318e101630e53d0f6d7991e532c05f24a90608c0ade11fe845b2ceda8ffc97422b37832c9d8ed1283ab9ec3499036d40b8ee24c8e011cc36ccc1c0f
|
7
|
+
data.tar.gz: 75afc116076f717a97017f158ada3fa726d339fed6602895b61cfe157590679084d5e64d347b59cb8e940c06fffbbf98cc2de12cfa6bb0b980b7eda7bba8ee18
|
data/exe/commit_ai
ADDED
data/lib/commit_ai.rb
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'openai'
|
2
|
+
|
3
|
+
class CommitAI
|
4
|
+
def initialize
|
5
|
+
@client = OpenAI::Client.new(access_token: ENV['OPENAI_API_KEY'])
|
6
|
+
end
|
7
|
+
|
8
|
+
def analyze_codebase
|
9
|
+
codebase_summary = ""
|
10
|
+
|
11
|
+
files = Dir.glob("**/*").reject { |f| f =~ %r{/(node_modules|\.git|\.DS_Store)} }
|
12
|
+
|
13
|
+
files.each do |file|
|
14
|
+
next unless File.file?(file)
|
15
|
+
|
16
|
+
file_content = File.read(file)
|
17
|
+
codebase_summary += "File: #{file}\n"
|
18
|
+
codebase_summary += "Content Preview:\n#{file_content[0..500]}\n"
|
19
|
+
codebase_summary += "\n---\n"
|
20
|
+
end
|
21
|
+
|
22
|
+
codebase_summary
|
23
|
+
end
|
24
|
+
|
25
|
+
def analyze_git_history
|
26
|
+
git_history = `git log --pretty=format:"%h - %an, %ar: %s"`.strip
|
27
|
+
if git_history.empty?
|
28
|
+
"No commits found"
|
29
|
+
else
|
30
|
+
git_history
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def generate_commit_message(diff)
|
35
|
+
codebase_summary = analyze_codebase
|
36
|
+
git_history = analyze_git_history
|
37
|
+
prompt = <<~PROMPT
|
38
|
+
This is the codebase summary: #{codebase_summary}
|
39
|
+
This is the git history: #{git_history}
|
40
|
+
This is the git diff: #{diff}
|
41
|
+
|
42
|
+
Please generate a **single-line** commit message that is concise and follows best practices.
|
43
|
+
**Do not include any extra text or formatting** like triple backticks (```) or code block delimiters.
|
44
|
+
Only return the commit message.
|
45
|
+
PROMPT
|
46
|
+
|
47
|
+
response = @client.chat(
|
48
|
+
parameters: {
|
49
|
+
model: "gpt-3.5-turbo",
|
50
|
+
messages: [
|
51
|
+
{ role: "system", content: "You are a helpful assistant." },
|
52
|
+
{ role: "user", content: prompt }
|
53
|
+
],
|
54
|
+
max_tokens: 50,
|
55
|
+
temperature: 0.5
|
56
|
+
}
|
57
|
+
)
|
58
|
+
|
59
|
+
response.dig("choices", 0, "message", "content").strip
|
60
|
+
end
|
61
|
+
|
62
|
+
def execute
|
63
|
+
system("git add --all")
|
64
|
+
diff = `git diff --staged`
|
65
|
+
|
66
|
+
loop do
|
67
|
+
commit_message = generate_commit_message(diff)
|
68
|
+
puts "Generated Commit Message: #{commit_message}"
|
69
|
+
print "Do you want to proceed with the commit? (y/n) or regenerate (r): "
|
70
|
+
response = STDIN.gets.chomp
|
71
|
+
case response.downcase
|
72
|
+
when 'y'
|
73
|
+
system("git commit -m '#{commit_message}'")
|
74
|
+
break
|
75
|
+
when 'r'
|
76
|
+
next
|
77
|
+
else
|
78
|
+
puts "Commit aborted."
|
79
|
+
break
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: commit_ai
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ken Vitug
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-10-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruby-openai
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Commit AI automates the generation of insightful one-liner commit messages
|
28
|
+
by analyzing staged git diffs with the help of OpenAI's advanced language models.
|
29
|
+
email:
|
30
|
+
- ken@narralabs.com
|
31
|
+
executables:
|
32
|
+
- commit_ai
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- exe/commit_ai
|
37
|
+
- lib/commit_ai.rb
|
38
|
+
- lib/commit_ai/version.rb
|
39
|
+
homepage: https://github.com/ken-narra/commit_ai
|
40
|
+
licenses:
|
41
|
+
- MIT
|
42
|
+
metadata:
|
43
|
+
allowed_push_host: https://rubygems.org
|
44
|
+
homepage_uri: https://github.com/ken-narra/commit_ai
|
45
|
+
source_code_uri: https://github.com/ken-narra/commit_ai
|
46
|
+
changelog_uri: https://github.com/ken-narra/commit_ai/blob/main/CHANGELOG.md
|
47
|
+
post_install_message:
|
48
|
+
rdoc_options: []
|
49
|
+
require_paths:
|
50
|
+
- lib
|
51
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 2.3.0
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubygems_version: 3.5.3
|
63
|
+
signing_key:
|
64
|
+
specification_version: 4
|
65
|
+
summary: A Ruby gem that utilizes OpenAI to create concise and meaningful commit messages
|
66
|
+
based on the differences in your git changes.
|
67
|
+
test_files: []
|