dorian-commit 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/commit +48 -0
- metadata +62 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1755970ac251ca93f075f8377be124343de1bd927127e8dd98739527d0dec435
|
4
|
+
data.tar.gz: 55f49464c33b2e61c9c81e5f30c3a1354fa34a0168f4edb050d1aa4d07a04e54
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: caec97a14207833cc2bb3958a8c3d96a58ea8428b933da382f807d64db15d46b11a26374597a94370082d6125428c86a4e980b5161d419c6484e5d7708c2d52e
|
7
|
+
data.tar.gz: 4d151d4dc995c2affd1c7cef5b755815d3d88c751334c14037555e71835685eb699cb4d68cb586195b1871c9b65486c7922a4e4ad602aafbd8f855d3e721fdc7
|
data/bin/commit
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "json"
|
5
|
+
require "net/http"
|
6
|
+
require "uri"
|
7
|
+
require "git"
|
8
|
+
|
9
|
+
abort "USAGE: commit" if ARGV.any?
|
10
|
+
|
11
|
+
TOKEN_FILE = File.join(Dir.home, ".commit")
|
12
|
+
PROMPT = "simple, clear, short, lowercase commit message for the following diff:"
|
13
|
+
|
14
|
+
if File.exist?(TOKEN_FILE)
|
15
|
+
TOKEN = File.read(TOKEN_FILE).strip
|
16
|
+
else
|
17
|
+
print "token: "
|
18
|
+
TOKEN = gets.strip
|
19
|
+
File.write(TOKEN_FILE, TOKEN)
|
20
|
+
puts "token written to #{TOKEN_FILE}"
|
21
|
+
end
|
22
|
+
|
23
|
+
STAGED = `git diff --staged`
|
24
|
+
|
25
|
+
abort "no staged files" if STAGED.strip.empty?
|
26
|
+
|
27
|
+
uri = URI("https://api.openai.com/v1/chat/completions")
|
28
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
29
|
+
http.use_ssl = true
|
30
|
+
|
31
|
+
request = Net::HTTP::Post.new(uri.path, {
|
32
|
+
"Content-Type" => "application/json",
|
33
|
+
"Authorization" => "Bearer #{TOKEN}"
|
34
|
+
})
|
35
|
+
|
36
|
+
request.body = {
|
37
|
+
model: "gpt-4o",
|
38
|
+
messages: [
|
39
|
+
{ role: "system", content: PROMPT },
|
40
|
+
{ role: "user", content: STAGED }
|
41
|
+
],
|
42
|
+
}.to_json
|
43
|
+
|
44
|
+
response = http.request(request)
|
45
|
+
json = JSON.parse(response.body)
|
46
|
+
message = json.dig('choices', 0, 'message', 'content').strip
|
47
|
+
Git.open(".").commit(message)
|
48
|
+
puts message
|
metadata
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dorian-commit
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dorian Marié
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-08-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
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: |-
|
28
|
+
commit with openai api
|
29
|
+
|
30
|
+
e.g. `commit`
|
31
|
+
email: dorian@dorianmarie.com
|
32
|
+
executables:
|
33
|
+
- commit
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- bin/commit
|
38
|
+
homepage: https://github.com/dorianmariecom/dorian-commit
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
rubygems_mfa_required: 'true'
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
version: '0'
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
requirements: []
|
58
|
+
rubygems_version: 3.5.11
|
59
|
+
signing_key:
|
60
|
+
specification_version: 4
|
61
|
+
summary: commit with openai api
|
62
|
+
test_files: []
|