aicommit 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/aicommit +3 -0
- data/lib/aicommit.rb +75 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5ba45c59ec36dfb07db5dd8ded3a9ad82d18e09704af6d3f4b1cd1a52aea7dd7
|
4
|
+
data.tar.gz: 4bfe81b4701456aa93d6a79f107127e6dc80b319a9590ff38ecfed92555bc144
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 77658e495e9b2ab39e4bb7b487b0c55e538b38ab84d78239d1cc95ebc7c7ea591bdbcff261fe72add4c5d06049528ddda8ea835e7010d3b018143f363efe1ba5
|
7
|
+
data.tar.gz: '08473a1ed46acb3411bb070ccca89fbc7f0564a441f4bf1d215755d2463052b71362d0323af78654490fa518b703c9a93bfbbe540e68169435d50d9a1aa0003b'
|
data/bin/aicommit
ADDED
data/lib/aicommit.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require "git"
|
2
|
+
require "openai"
|
3
|
+
require "dotenv/load"
|
4
|
+
|
5
|
+
def save_api_key_to_env
|
6
|
+
puts "Please enter your OpenAI API key (or 'q' to quit):"
|
7
|
+
api_key = gets.chomp
|
8
|
+
if api_key.downcase == "q"
|
9
|
+
puts "Exiting program."
|
10
|
+
exit
|
11
|
+
end
|
12
|
+
File.write(".env", "OPENAI_API_KEY=#{api_key}")
|
13
|
+
ENV["OPENAI_API_KEY"] = api_key
|
14
|
+
puts "Your API key has been saved to .env"
|
15
|
+
end
|
16
|
+
|
17
|
+
def generate_commit_message(diff)
|
18
|
+
diff = diff[-3800..] || diff
|
19
|
+
client = OpenAI::Client.new(access_token: ENV["OPENAI_API_KEY"])
|
20
|
+
content = "Please generate a commit message based on the following diff in one sentance and less than 80 letters:\n#{diff}"
|
21
|
+
|
22
|
+
response = client.chat(
|
23
|
+
parameters: {
|
24
|
+
model: "gpt-3.5-turbo",
|
25
|
+
messages: [{role: "user", content: content}]
|
26
|
+
}
|
27
|
+
)
|
28
|
+
|
29
|
+
if response.code == 401
|
30
|
+
puts "Invalid API key."
|
31
|
+
save_api_key_to_env
|
32
|
+
|
33
|
+
return generate_commit_message(diff)
|
34
|
+
end
|
35
|
+
|
36
|
+
response.dig("choices", 0, "message", "content")
|
37
|
+
end
|
38
|
+
|
39
|
+
if !Dir.exist?(".git")
|
40
|
+
raise "Not a git repository!"
|
41
|
+
end
|
42
|
+
|
43
|
+
if ENV["OPENAI_API_KEY"].nil?
|
44
|
+
save_api_key_to_env
|
45
|
+
end
|
46
|
+
|
47
|
+
patch_str = ""
|
48
|
+
|
49
|
+
git = Git.open(".")
|
50
|
+
git.diff.each do |diff|
|
51
|
+
patch = diff.patch
|
52
|
+
patch_str += "\n\n#{diff.path}\n"
|
53
|
+
patch_str += patch
|
54
|
+
end
|
55
|
+
|
56
|
+
commit_message = generate_commit_message(patch_str)
|
57
|
+
|
58
|
+
loop do
|
59
|
+
puts "commit_message: #{commit_message}"
|
60
|
+
puts "Do you want to keep this commit_message? (Y/N) (or Q to quit)"
|
61
|
+
command = gets.chomp
|
62
|
+
if command.match?(/^[Yy]$/)
|
63
|
+
git.commit_all(commit_message)
|
64
|
+
puts "Committed all changes with message: #{commit_message}"
|
65
|
+
break
|
66
|
+
elsif command.match?(/^[Nn]$/)
|
67
|
+
puts "Please enter your new commit_message:"
|
68
|
+
commit_message = gets.chomp
|
69
|
+
elsif command.match?(/^[Qq]$/)
|
70
|
+
puts "Quit without committing."
|
71
|
+
exit
|
72
|
+
else
|
73
|
+
puts "Invalid command. Please enter Y, N, or Q."
|
74
|
+
end
|
75
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: aicommit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- jackal998
|
8
|
+
- LinGaryTW
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2023-03-06 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: git
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 1.14.0
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "~>"
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: 1.14.0
|
28
|
+
description: You dare use my own spells against me, Human?
|
29
|
+
email:
|
30
|
+
- ej_lin2000@yahoo.com.tw
|
31
|
+
executables:
|
32
|
+
- aicommit
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- bin/aicommit
|
37
|
+
- lib/aicommit.rb
|
38
|
+
homepage: https://github.com/jackal998/aicommit
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.3.7
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: Use your own spell against you.
|
61
|
+
test_files: []
|