dorian-commit 0.4.2 → 0.4.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/bin/commit +45 -13
  3. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 52b83c8fffda78584363b2d97d26a5da277b13fb640f5eb0a9e935446848f4d0
4
- data.tar.gz: 2a8ee8d66bbdc09844a2a8850549b8e74a32dd93527c4623c48dcb63e1f4e4fb
3
+ metadata.gz: 8277450427f579a722a664da512e6cee4b3a31fa00699c6506a6b5ec53271115
4
+ data.tar.gz: '08f33e3dd2936e5c881e5cb21ffcf7699104b5a68cbbce8b1c9940a251bba861'
5
5
  SHA512:
6
- metadata.gz: b6ec2f80ae82311479444e59b6ad51c66bb731cf59979ef14756840c03fc4f675aa413a6223bfaef11811e5855cc0181e94c02cfe59c436d31186b747079ecf1
7
- data.tar.gz: 9504f8ffae772c26fe24c3de06755a6c71b140b1a6a9255d4052f014e5276c3a3a9482fccca22d26a27c85da1e59a6640c35898669ff9f7f80b6609d7b5fdf4e
6
+ metadata.gz: f30d67a1bb421eab3e523d8bc58dba9691ec53cbcf0420b470acf28dc17cc05b2edef192e45510cf96ae524fd830c67833aa3530f521371f28c1f734ce3c55aa
7
+ data.tar.gz: c84cf08482ef6e85183f1063933f9a4c2c38a98678bde8b736f8185dd9bde4494d28c2a3776f9789846aa94006b49b9b983a57d1ebd9c35a11b1f6830e63b59d
data/bin/commit CHANGED
@@ -1,16 +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 =
13
- "simple, clear, short, lowercase commit message for the following diff:"
14
11
 
15
12
  if File.exist?(TOKEN_FILE)
16
13
  TOKEN = File.read(TOKEN_FILE).strip
@@ -21,11 +18,35 @@ else
21
18
  puts "token written to #{TOKEN_FILE}"
22
19
  end
23
20
 
24
- STAGED = `git diff --staged`
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
25
 
26
- abort "no staged files" if STAGED.strip.empty?
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")
38
+
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")
27
49
 
28
- uri = URI("https://api.openai.com/v1/chat/completions")
29
50
  http = Net::HTTP.new(uri.host, uri.port)
30
51
  http.use_ssl = true
31
52
 
@@ -41,13 +62,24 @@ request =
41
62
  request.body = {
42
63
  model: "gpt-4o",
43
64
  messages: [
44
- { role: "system", content: PROMPT },
45
- { role: "user", content: STAGED }
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
46
71
  ]
47
72
  }.to_json
48
73
 
49
74
  response = http.request(request)
75
+
50
76
  json = JSON.parse(response.body)
51
- message = json.dig("choices", 0, "message", "content").strip
52
- Git.open(".").commit(message)
53
- puts message
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.2
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-18 00:00:00.000000000 Z
11
+ date: 2024-08-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
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'
27
41
  description: commit with ai
28
42
  email: dorian@dorianmarie.com
29
43
  executables: