dorian-commit 0.4.1 → 0.4.3
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/bin/commit +54 -17
- metadata +18 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8277450427f579a722a664da512e6cee4b3a31fa00699c6506a6b5ec53271115
|
4
|
+
data.tar.gz: '08f33e3dd2936e5c881e5cb21ffcf7699104b5a68cbbce8b1c9940a251bba861'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f30d67a1bb421eab3e523d8bc58dba9691ec53cbcf0420b470acf28dc17cc05b2edef192e45510cf96ae524fd830c67833aa3530f521371f28c1f734ce3c55aa
|
7
|
+
data.tar.gz: c84cf08482ef6e85183f1063933f9a4c2c38a98678bde8b736f8185dd9bde4494d28c2a3776f9789846aa94006b49b9b983a57d1ebd9c35a11b1f6830e63b59d
|
data/bin/commit
CHANGED
@@ -1,15 +1,13 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
+
require "dorian/arguments"
|
5
|
+
require "git"
|
4
6
|
require "json"
|
5
7
|
require "net/http"
|
6
8
|
require "uri"
|
7
|
-
require "git"
|
8
|
-
|
9
|
-
abort "USAGE: commit" if ARGV.any?
|
10
9
|
|
11
10
|
TOKEN_FILE = File.join(Dir.home, ".commit")
|
12
|
-
PROMPT = "simple, clear, short, lowercase commit message for the following diff:"
|
13
11
|
|
14
12
|
if File.exist?(TOKEN_FILE)
|
15
13
|
TOKEN = File.read(TOKEN_FILE).strip
|
@@ -20,29 +18,68 @@ else
|
|
20
18
|
puts "token written to #{TOKEN_FILE}"
|
21
19
|
end
|
22
20
|
|
23
|
-
|
21
|
+
PROMPT_1 = "simple, clear, short, lowercase commit message"
|
22
|
+
PROMPT_2 = "for the following diff:"
|
23
|
+
PROMPT_3 = "for the following git status:"
|
24
|
+
PROMPT_4 = "for the following comment:"
|
25
|
+
|
26
|
+
parsed = Dorian::Arguments.parse(version: { alias: :v }, help: { alias: :h })
|
27
|
+
|
28
|
+
abort parsed.help if parsed.options.help
|
29
|
+
|
30
|
+
if parsed.options.version
|
31
|
+
abort File.read(File.expand_path("../../VERSION", __FILE__))
|
32
|
+
end
|
33
|
+
|
34
|
+
content_2 = `git diff --staged`
|
35
|
+
content_3 = `git status`
|
36
|
+
content_4 = parsed.arguments.join(" ")
|
37
|
+
content_4 += parsed.files.map { |file| File.read(file) }.join("\n")
|
24
38
|
|
25
|
-
|
39
|
+
if content_4.empty?
|
40
|
+
messages_4 = []
|
41
|
+
else
|
42
|
+
messages_4 = [
|
43
|
+
{ role: :system, content: PROMPT_4 },
|
44
|
+
{ role: :user, content: content_4 }
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
uri = URI.parse("https://api.openai.com/v1/chat/completions")
|
26
49
|
|
27
|
-
uri = URI("https://api.openai.com/v1/chat/completions")
|
28
50
|
http = Net::HTTP.new(uri.host, uri.port)
|
29
51
|
http.use_ssl = true
|
30
52
|
|
31
|
-
request =
|
32
|
-
|
33
|
-
|
34
|
-
|
53
|
+
request =
|
54
|
+
Net::HTTP::Post.new(
|
55
|
+
uri.path,
|
56
|
+
{
|
57
|
+
"Content-Type" => "application/json",
|
58
|
+
"Authorization" => "Bearer #{TOKEN}"
|
59
|
+
}
|
60
|
+
)
|
35
61
|
|
36
62
|
request.body = {
|
37
63
|
model: "gpt-4o",
|
38
64
|
messages: [
|
39
|
-
{ role:
|
40
|
-
{ role:
|
41
|
-
|
65
|
+
{ role: :system, content: PROMPT_1 },
|
66
|
+
{ role: :system, content: PROMPT_2 },
|
67
|
+
{ role: :user, content: content_2 },
|
68
|
+
{ role: :system, content: PROMPT_3 },
|
69
|
+
{ role: :user, content: content_3 },
|
70
|
+
*messages_4
|
71
|
+
]
|
42
72
|
}.to_json
|
43
73
|
|
44
74
|
response = http.request(request)
|
75
|
+
|
45
76
|
json = JSON.parse(response.body)
|
46
|
-
|
47
|
-
|
48
|
-
|
77
|
+
|
78
|
+
message = json.dig("choices", 0, "message", "content")
|
79
|
+
|
80
|
+
if message
|
81
|
+
Git.open(".").commit(message)
|
82
|
+
puts message
|
83
|
+
else
|
84
|
+
puts JSON.pretty_generate(json)
|
85
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dorian-commit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-08-
|
11
|
+
date: 2024-08-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -24,10 +24,21 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dorian-arguments
|
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'
|
41
|
+
description: commit with ai
|
31
42
|
email: dorian@dorianmarie.com
|
32
43
|
executables:
|
33
44
|
- commit
|
@@ -58,5 +69,5 @@ requirements: []
|
|
58
69
|
rubygems_version: 3.5.11
|
59
70
|
signing_key:
|
60
71
|
specification_version: 4
|
61
|
-
summary: commit with
|
72
|
+
summary: commit with ai
|
62
73
|
test_files: []
|