autogitc 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/autogitc +4 -1
  3. data/lib/autogitc.rb +10 -6
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 70b587912c12f437a8ca1cd98093680920df43c9633af60648e9484e4aab1a6c
4
- data.tar.gz: 343bee76fd891b344208493bc9b6e2a798d86d8a94b77e56c6eec07b871d1ad9
3
+ metadata.gz: 8338488482249d5ff2943379b1149b5da9db670f57821c6d827b1ba4b1c3f601
4
+ data.tar.gz: 271f9833f533852180a7598a0710006765a11b108a0d20d6876bb0b0985f81ce
5
5
  SHA512:
6
- metadata.gz: d65c18d727898e03938a5445cd3f1839b89b710e354eddc7b2cb2a8362ba036012461a17434a42bae1cd9c525fcff09d594c765b02a5301a02c38570475e8f47
7
- data.tar.gz: bb0e40f88bcb44d2455eca7a80b92a6805efe54a309e912bbdb4cc3023257d65a71d890d64592b592d9fb0a9bae4600718c9a4a1ddd2f4e9818e1535710c73c3
6
+ metadata.gz: 7d182292cf4a0fe32fc1bb27e886a50a21a813a66902e07ee9557dbb6a6a3dc03f261723b2976414eddb990096f1cdaf3b4664cfb98c94e66d500cf96e8a0f1b
7
+ data.tar.gz: fcd92b63be81c3aae8b0678aea18b062cfffc5f070d18e280ce0133b59b44401d9f786fcccfefa41251d09f6a98add35f4c8614eb405264f3e6f18bdf2e41ac1
data/bin/autogitc CHANGED
@@ -2,5 +2,8 @@
2
2
  require 'bundler/setup'
3
3
  require_relative '../lib/autogitc'
4
4
 
5
+ no_commit = ARGV.include?('--nocommit') || ARGV.include?('--nc')
6
+ must_have_text = ARGV.find { |arg| arg.start_with?('--text=') }&.split('=')&.last
7
+
5
8
  puts 'Running autogitc...'
6
- Autogitc.main
9
+ Autogitc.main(no_commit: no_commit, must_have_text: must_have_text)
data/lib/autogitc.rb CHANGED
@@ -15,7 +15,7 @@ module Autogitc
15
15
  `git diff --staged #{file_path}`
16
16
  end
17
17
 
18
- def self.generate_commit_message(changes_summary)
18
+ def self.generate_commit_message(changes_summary:, must_have_text: nil)
19
19
  uri = URI('https://api.openai.com/v1/chat/completions')
20
20
 
21
21
  http = Net::HTTP.new(uri.host, uri.port)
@@ -37,7 +37,7 @@ module Autogitc
37
37
  },
38
38
  {
39
39
  role: 'user',
40
- content: "Generate a conventional git commit message limited to 72 characters for the following changes in a JSON format with a key 'commit_message':\n\n#{changes_summary}"
40
+ content: "Generate a conventional git commit message limited to 72 characters for the following changes in a JSON format with a key 'commit_message', ensuring it includes the text: '#{must_have_text}':\n\n#{changes_summary}"
41
41
  }
42
42
  ],
43
43
  response_format: { "type": 'json_object' }
@@ -49,7 +49,7 @@ module Autogitc
49
49
  JSON.parse(output_text)['commit_message']
50
50
  end
51
51
 
52
- def self.main
52
+ def self.main(no_commit: false, must_have_text: nil)
53
53
  if openai_api_key.nil?
54
54
  puts 'No AUTOGITC_KEY key found in environment variables.'
55
55
  return
@@ -67,9 +67,13 @@ module Autogitc
67
67
  "Changes in #{file}:\n#{diff}\n"
68
68
  end.join("\n")
69
69
 
70
- commit_message = generate_commit_message(changes_summary)
71
- puts "Generated commit message:\n#{commit_message}"
70
+ commit_message = generate_commit_message(
71
+ changes_summary: changes_summary,
72
+ must_have_text: must_have_text
73
+ )
74
+ puts 'Generated commit message:'
75
+ puts commit_message
72
76
 
73
- `git commit -m "#{commit_message}"`
77
+ `git commit -m "#{commit_message}"` unless no_commit
74
78
  end
75
79
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autogitc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adrian Goh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-27 00:00:00.000000000 Z
11
+ date: 2024-08-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: This gem simplifies the commit process by automatically generating descriptive
14
14
  commit messages based on the files that have been added to the Git staging area.