commit_ai 0.2.0 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/exe/commit_ai +2 -1
- data/lib/commit_ai/version.rb +1 -1
- data/lib/commit_ai.rb +22 -15
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf636d90172c3a58382dbfda99f0b4cb43daf3256fcad2e39a24a4ed7bcd31ac
|
4
|
+
data.tar.gz: 7a12f3d41dcd098fd8328f427c52974b6e231250ca97022309d4c934fbd0feb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 512eff1fdd7c5b9025c0c87f09b788498723734166cbaaa5a1515c3ca94dfb9fdccc85c46231527f2270c780c56d5bc3581968bb4688f4413a3e77575a0be137
|
7
|
+
data.tar.gz: e1a8a1d097b06e8d6bb1e9eed20969c240c249f9a68403a84ca2a177b298656fc7d1d1908847e77ee485da50f321b422afae5881d0d2ec08fe25b22ec28a83f7
|
data/exe/commit_ai
CHANGED
@@ -4,9 +4,10 @@
|
|
4
4
|
$LOAD_PATH.unshift(File.expand_path('../lib', __dir__))
|
5
5
|
|
6
6
|
require 'commit_ai'
|
7
|
+
require 'colorize'
|
7
8
|
|
8
9
|
if ENV['OPENAI_ACCESS_TOKEN'].nil?
|
9
|
-
puts "OPENAI_ACCESS_TOKEN is not set. Please set it in your environment variables."
|
10
|
+
puts "OPENAI_ACCESS_TOKEN is not set. Please set it in your environment variables.".colorize(:red)
|
10
11
|
exit
|
11
12
|
end
|
12
13
|
|
data/lib/commit_ai/version.rb
CHANGED
data/lib/commit_ai.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'openai'
|
2
|
+
require 'colorize'
|
2
3
|
|
3
4
|
class CommitAI
|
4
5
|
def initialize
|
5
6
|
@client = OpenAI::Client.new(access_token: ENV['OPENAI_ACCESS_TOKEN'])
|
7
|
+
@enabled_pretext = ENV['COMMIT_AI_ENABLED_PRETEXT'] == '1'
|
6
8
|
end
|
7
9
|
|
8
10
|
def execute
|
@@ -10,41 +12,50 @@ class CommitAI
|
|
10
12
|
diff = `git diff -U10 --staged`
|
11
13
|
|
12
14
|
if diff.empty?
|
13
|
-
puts
|
15
|
+
puts "No changes to commit. No need to proceed.".colorize(:red)
|
14
16
|
return
|
15
17
|
end
|
16
18
|
|
17
|
-
|
19
|
+
if @enabled_pretext
|
20
|
+
puts "Please provide a pretext for the commit message (optional):".colorize(:cyan)
|
21
|
+
pretext = STDIN.gets.chomp
|
22
|
+
end
|
23
|
+
|
24
|
+
puts "Please provide a brief description of the change made (optional):".colorize(:cyan)
|
18
25
|
user_description = STDIN.gets.chomp
|
19
26
|
|
20
|
-
puts
|
27
|
+
puts "Do you want a multi-line commit message? (y/n) (optional):".colorize(:cyan)
|
21
28
|
message_style_input = STDIN.gets.chomp.downcase
|
22
29
|
message_style = message_style_input == 'y' ? 'multi' : 'single'
|
23
30
|
|
24
31
|
commit_message = generate_commit_message(diff, message_style, user_description)
|
25
32
|
loop do
|
26
|
-
|
33
|
+
if @enabled_pretext
|
34
|
+
puts "\nGenerated Commit Message:\n#{pretext}: #{commit_message}".colorize(:green)
|
35
|
+
else
|
36
|
+
puts "\nGenerated Commit Message:\n#{commit_message}".colorize(:green)
|
37
|
+
end
|
27
38
|
puts ""
|
28
|
-
puts
|
39
|
+
puts "Do you want to proceed with the commit? (y/n), regenerate (r), or edit (e):".colorize(:cyan)
|
29
40
|
response = STDIN.gets.chomp
|
30
41
|
case response.downcase
|
31
42
|
when 'y'
|
32
|
-
system("git commit -m '#{commit_message}'")
|
33
|
-
puts
|
43
|
+
system(@enabled_pretext ? "git commit -m '#{pretext}: #{commit_message}'" : "git commit -m '#{commit_message}'")
|
44
|
+
puts "Commit successful!".colorize(:green)
|
34
45
|
break
|
35
46
|
when 'r'
|
36
47
|
commit_message = generate_commit_message(diff, message_style, user_description)
|
37
|
-
puts
|
48
|
+
puts "Regenerating commit message...".colorize(:yellow)
|
38
49
|
next
|
39
50
|
when 'e'
|
40
51
|
system("git commit -m '#{commit_message}' -e")
|
41
|
-
puts
|
52
|
+
puts "Commit successful after editing!".colorize(:green)
|
42
53
|
break
|
43
54
|
when 'n'
|
44
|
-
puts
|
55
|
+
puts "Commit aborted. No changes committed.".colorize(:red)
|
45
56
|
break
|
46
57
|
else
|
47
|
-
puts
|
58
|
+
puts "Invalid input. Please try again.".colorize(:red)
|
48
59
|
puts ""
|
49
60
|
next
|
50
61
|
end
|
@@ -116,8 +127,4 @@ class CommitAI
|
|
116
127
|
|
117
128
|
minified_diff.join
|
118
129
|
end
|
119
|
-
|
120
|
-
def colorize(text, color_code)
|
121
|
-
"\e[#{color_code}m#{text}\e[0m"
|
122
|
-
end
|
123
130
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: commit_ai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Vitug
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-openai
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: colorize
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
description: Commit AI automates the generation of insightful single-line and multi-line
|
28
42
|
commit messages by analyzing staged git diffs with OpenAI's advanced language models.
|
29
43
|
It allows users to provide optional change descriptions for better context, and
|