aicommit 0.0.7 → 1.0.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0cd5fd61fe0b6342c4a58f1f2c3e5bcb3a406cc3088df91772ab2a9b43716dd0
4
- data.tar.gz: 2cecba681f7a7f4b83d5390d945aa33ecb54a539a2386f513b551669ef580cfe
3
+ metadata.gz: a54077b306374f9d14782240041e70fd59c7df3b4fe8bb857e10833f966bca9b
4
+ data.tar.gz: 1e275b03d0b9aa2c130551f9d2b01604297b5106e6febd23fe3422c32322e476
5
5
  SHA512:
6
- metadata.gz: '08acb35449d5e7e78983d6f4f066cdbb31c9a2089a1d3adeed944ef7efbca95199eced51992c12c076dbebf2c19347da95807ce51ebc159b9425842a84ebc178'
7
- data.tar.gz: 4b34a6394d6614f02c65d6cfe59858648921443a35de8e06d02c451be2fc60a19146f6a19a9f689e9b60177abf0a652ee34d6c7283a416d861f280aa3c964c16
6
+ metadata.gz: fb9964cdb1786755eb22f97f6c6f91c86679c96d321038b889579c9a075198d0c789f9e110009d4518987f73544e6db462f0aa0a4a7cf1e63a2b8b2db194e4d5
7
+ data.tar.gz: 1dfa6e905ff28a3ffed5209a5ed7703be7e84acc61cf6c6a3594474a3caba2973189cb47e8b0398a4ae72dcd316b4983096a42d3de1b114a42cf43ceaa9ca11e
data/bin/aicommit CHANGED
@@ -1,5 +1,30 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require "optparse"
3
4
  require_relative "../lib/aicommit"
5
+ require_relative "../lib/aicommit/version"
4
6
 
5
- Aicommit.new.run
7
+ options = {}
8
+ parser = OptionParser.new do |op|
9
+ op.banner = "Usage: aicommit [options]"
10
+
11
+ op.on("-v", "--version", "Show version") do |v|
12
+ options[:version] = v
13
+ end
14
+
15
+ op.on("-c", "--config", "Set OpenAI API token") do |c|
16
+ options[:config] = c
17
+ end
18
+ end
19
+
20
+ parser.parse!
21
+
22
+ if options[:version]
23
+ puts Aicommit::VERSION
24
+ elsif options[:config]
25
+ TokenManager.new.write!("OPENAI_API_TOKEN")
26
+ elsif ARGV.empty?
27
+ Aicommit.new.run
28
+ else
29
+ puts parser.help
30
+ end
@@ -0,0 +1,3 @@
1
+ class Aicommit
2
+ VERSION = "1.0.0"
3
+ end
data/lib/aicommit.rb CHANGED
@@ -12,7 +12,7 @@ class Aicommit
12
12
  def run
13
13
  patch_diffs = git_client.get_patch_str
14
14
 
15
- commit_message = get_commit_message(patch_diffs)
15
+ commit_message = get_commit_message!(patch_diffs)
16
16
 
17
17
  loop do
18
18
  puts "commit_message: #{commit_message}"
@@ -24,7 +24,7 @@ class Aicommit
24
24
  exit
25
25
  when /^[Rr]$/
26
26
  puts "Regenerating..."
27
- commit_message = get_commit_message(patch_diffs)
27
+ commit_message = get_commit_message!(patch_diffs)
28
28
  when /^[Nn]$/
29
29
  puts "Please enter your new commit_message:"
30
30
  commit_message = gets.chomp
@@ -39,13 +39,17 @@ class Aicommit
39
39
 
40
40
  private
41
41
 
42
- def get_commit_message(diff)
42
+ def get_commit_message!(diff)
43
43
  response = commit_message_generator.generate(diff)
44
- if response[:code] == 401
44
+ case response[:code]
45
+ when 401
45
46
  puts "Invalid API key."
46
47
  @token_manager.write!("OPENAI_API_TOKEN")
47
48
 
48
- get_commit_message(diff)
49
+ get_commit_message!(diff)
50
+ when 500
51
+ puts "OpenAI connection timeout."
52
+ exit
49
53
  else
50
54
  response[:result]
51
55
  end
@@ -14,6 +14,8 @@ class CommitMessageGenerator
14
14
  )
15
15
 
16
16
  {result: response.dig("choices", 0, "message", "content")&.strip, code: response.code}
17
+ rescue Net::ReadTimeout => e
18
+ {result: e.message, code: 500}
17
19
  end
18
20
 
19
21
  private
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aicommit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - jackal998
8
8
  - LinGaryTW
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2023-03-21 00:00:00.000000000 Z
12
+ date: 2023-03-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: git
@@ -62,9 +62,9 @@ extensions: []
62
62
  extra_rdoc_files: []
63
63
  files:
64
64
  - LICENSE
65
- - Readme.md
66
65
  - bin/aicommit
67
66
  - lib/aicommit.rb
67
+ - lib/aicommit/version.rb
68
68
  - lib/commit_message_generator.rb
69
69
  - lib/git_client.rb
70
70
  - lib/token_manager.rb
@@ -72,7 +72,7 @@ homepage: https://github.com/jackal998/aicommit
72
72
  licenses:
73
73
  - MIT
74
74
  metadata: {}
75
- post_install_message:
75
+ post_install_message:
76
76
  rdoc_options: []
77
77
  require_paths:
78
78
  - lib
@@ -87,8 +87,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 3.3.7
91
- signing_key:
90
+ rubygems_version: 3.2.33
91
+ signing_key:
92
92
  specification_version: 4
93
93
  summary: Use your own spell against you.
94
94
  test_files: []
data/Readme.md DELETED
@@ -1,53 +0,0 @@
1
- # AICommit
2
- Use your own spell against you.
3
-
4
- ## Setup
5
- ### Prerequisites
6
- - Ruby 2.5 or later
7
- - An OpenAI API key
8
-
9
- ### Installation
10
- Install the aicommit gem:
11
- ```bash
12
- gem install aicommit
13
- ```
14
- ### Upgrading
15
- To upgrade to the latest version of AICommit, run:
16
-
17
- ```bash
18
- gem update aicommit
19
- ```
20
-
21
- ### Usage
22
- #### Generate a commit message
23
- To generate a commit message based on the changes in your Git repository:
24
-
25
- 1. Run the following command at the root of your project:
26
- ```bash
27
- aicommit
28
- ```
29
-
30
- 2. The AI model will generate a commit message based on the changes in your Git repository.
31
-
32
- 3. Review the generated commit message.
33
-
34
- 4. To commit the changes with the generated commit message, enter Y at the prompt.
35
- To enter a new commit message, enter N.
36
- To quit without committing, enter Q.
37
-
38
- #### Uninstallation
39
- To uninstall AICommit, run:
40
-
41
- ```bash
42
- gem uninstall aicommit
43
- ```
44
- ### How it works
45
- AICommit uses OpenAI's GPT-3.5 AI model to generate commit messages based on the changes in your Git repository.
46
-
47
- ### Contributing
48
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
49
-
50
- Please make sure to update tests as appropriate.
51
-
52
- ### License
53
- This project is licensed under the MIT License - see the LICENSE.md file for details.