diff --git a/.rubocop.yml b/.rubocop.yml index 5be3d3c..0d3cce5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,5 @@ AllCops: - TargetRubyVersion: 3.1 + TargetRubyVersion: 3.2 Exclude: - 'exe/**/*' - 'vendor/**/*' diff --git a/Gemfile b/Gemfile index 1281f97..18975cb 100644 --- a/Gemfile +++ b/Gemfile @@ -6,5 +6,6 @@ source "https://rubygems.org" gemspec gem "rake", "~> 13.0" +gem "rbs", "~> 3.4" gem "rspec", "~> 3.0" gem "rubocop", "~> 1.21" diff --git a/Gemfile.lock b/Gemfile.lock index 4b8134c..de4830f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -16,17 +16,20 @@ GEM json (2.13.2) language_server-protocol (3.17.0.5) lint_roller (1.1.0) + logger (1.7.0) openai (0.22.1) connection_pool parallel (1.27.0) parser (3.3.9.0) ast (~> 2.4.1) racc - prism (1.4.0) + prism (1.5.1) racc (1.8.1) rainbow (3.1.1) rake (13.3.0) - regexp_parser (2.11.2) + rbs (3.9.5) + logger + regexp_parser (2.11.3) rspec (3.13.1) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) @@ -67,8 +70,9 @@ PLATFORMS DEPENDENCIES ai_git_commit! rake (~> 13.0) + rbs (~> 3.4) rspec (~> 3.0) rubocop (~> 1.21) BUNDLED WITH - 2.6.9 + 2.7.2 diff --git a/ai_git_commit.gemspec b/ai_git_commit.gemspec index a9666d7..3816e0e 100644 --- a/ai_git_commit.gemspec +++ b/ai_git_commit.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |spec| DESCRIPTION spec.homepage = "https://github.com/drkmen/ai_git_commit" spec.license = "MIT" - spec.required_ruby_version = ">= 3.1.0" + spec.required_ruby_version = ">= 3.2.0" spec.metadata["allowed_push_host"] = "https://rubygems.org" diff --git a/sig/ai_git_commit.rbs b/sig/ai_git_commit.rbs index 16cf48b..d068cdc 100644 --- a/sig/ai_git_commit.rbs +++ b/sig/ai_git_commit.rbs @@ -1,4 +1,3 @@ module AiGitCommit VERSION: String - # See the writing guide of rbs: https://github.com/ruby/rbs#guides end diff --git a/sig/ai_git_commit/cli.rbs b/sig/ai_git_commit/cli.rbs new file mode 100644 index 0000000..7240659 --- /dev/null +++ b/sig/ai_git_commit/cli.rbs @@ -0,0 +1,14 @@ +module AiGitCommit + class CLI < Thor + HOOK_PATH: String + + def install: () -> void + + private + + def create_hook: () -> void + def copy_initializer: () -> void + def script: () -> ::String + def hook_file_exists?: () -> bool + end +end diff --git a/sig/ai_git_commit/config.rbs b/sig/ai_git_commit/config.rbs new file mode 100644 index 0000000..8a40bb4 --- /dev/null +++ b/sig/ai_git_commit/config.rbs @@ -0,0 +1,15 @@ +module AiGitCommit + class Config + attr_accessor openai_api_key: String + attr_accessor model: String + attr_accessor program_language: String + attr_accessor max_tokens: Integer + attr_accessor temperature: Float + attr_accessor system_role_message: String + + def initialize: () -> void + end + + def self.config: () -> Config + def self.configure: () { (Config) -> void } -> void +end diff --git a/sig/ai_git_commit/generator.rbs b/sig/ai_git_commit/generator.rbs new file mode 100644 index 0000000..74ddaa8 --- /dev/null +++ b/sig/ai_git_commit/generator.rbs @@ -0,0 +1,33 @@ +module AiGitCommit + class Generator + self.@openai: OpenAI::Client + self.@config: Config + + def self.commit_message: () -> String + + private + + def self.fetch_message: (String diff) -> String + def self.completion_payload: (String diff) -> { + model: String, + messages: ::Array[ + { + role: String, + content: String + } | { + role: String, + content: String + } + ], + max_tokens: Integer, + temperature: Float + } + + def self.user_role_message: (String diff) -> String + def self.openai: () -> OpenAI::Client + def self.config: () -> Config + def self.openai_api_key: () -> String? + def self.staged_diff: () -> String + end +end +