Class: CommitGpt::CommitAi
- Inherits:
-
Object
- Object
- CommitGpt::CommitAi
- Includes:
- DiffHelpers
- Defined in:
- lib/commitgpt/commit_ai.rb
Overview
Commit AI roboter based on GPT-3
Constant Summary collapse
- COMMIT_FORMATS =
Commit format templates
{ 'simple' => '<commit message>', 'conventional' => '<type>[optional (<scope>)]: <commit message>', 'gitmoji' => ':emoji: <commit message>' }.freeze
- CONVENTIONAL_TYPES =
Conventional commit types based on aicommits implementation
{ 'docs' => 'Documentation only changes', 'style' => 'Changes that do not affect the meaning of the code (white-space, formatting, missing semi-colons, etc)', 'refactor' => 'A code change that improves code structure without changing functionality (renaming, restructuring classes/methods, extracting functions, etc)', 'perf' => 'A code change that improves performance', 'test' => 'Adding missing tests or correcting existing tests', 'build' => 'Changes that affect the build system or external dependencies', 'ci' => 'Changes to our CI configuration files and scripts', 'chore' => "Other changes that don't modify src or test files", 'revert' => 'Reverts a previous commit', 'feat' => 'A new feature', 'fix' => 'A bug fix' }.freeze
- GITMOJI_TYPES =
Gitmoji mappings based on gitmoji.dev
{ '๐จ' => 'Improve structure / format of the code', 'โก' => 'Improve performance', '๐ฅ' => 'Remove code or files', '๐' => 'Fix a bug', '๐' => 'Critical hotfix', 'โจ' => 'Introduce new features', '๐' => 'Add or update documentation', '๐' => 'Deploy stuff', '๐' => 'Add or update the UI and style files', '๐' => 'Begin a project', 'โ ' => 'Add, update, or pass tests', '๐' => 'Fix security or privacy issues', '๐' => 'Add or update secrets', '๐' => 'Release / Version tags', '๐จ' => 'Fix compiler / linter warnings', '๐ง' => 'Work in progress', '๐' => 'Fix CI Build', 'โฌ๏ธ' => 'Downgrade dependencies', 'โฌ๏ธ' => 'Upgrade dependencies', '๐' => 'Pin dependencies to specific versions', '๐ท' => 'Add or update CI build system', '๐' => 'Add or update analytics or track code', 'โป๏ธ' => 'Refactor code', 'โ' => 'Add a dependency', 'โ' => 'Remove a dependency', '๐ง' => 'Add or update configuration files', '๐จ' => 'Add or update development scripts', '๐' => 'Internationalization and localization', 'โ๏ธ' => 'Fix typos', '๐ฉ' => 'Write bad code that needs to be improved', 'โช' => 'Revert changes', '๐' => 'Merge branches', '๐ฆ' => 'Add or update compiled files or packages', '๐ฝ' => 'Update code due to external API changes', '๐' => 'Move or rename resources (e.g.: files, paths, routes)', '๐' => 'Add or update license', '๐ฅ' => 'Introduce breaking changes', '๐ฑ' => 'Add or update assets', 'โฟ' => 'Improve accessibility', '๐ก' => 'Add or update comments in source code', '๐ป' => 'Write code drunkenly', '๐ฌ' => 'Add or update text and literals', '๐' => 'Perform database related changes', '๐' => 'Add or update logs', '๐' => 'Remove logs', '๐ฅ' => 'Add or update contributor(s)', '๐ธ' => 'Improve user experience / usability', '๐' => 'Make architectural changes', '๐ฑ' => 'Work on responsive design', '๐คก' => 'Mock things', '๐ฅ' => 'Add or update an easter egg', '๐' => 'Add or update a .gitignore file', '๐ธ' => 'Add or update snapshots', 'โ' => 'Perform experiments', '๐' => 'Improve SEO', '๐ท' => 'Add or update types', '๐ฑ' => 'Add or update seed files', '๐ฉ' => 'Add, update, or remove feature flags', '๐ฅ ' => 'Catch errors', '๐ซ' => 'Add or update animations and transitions', '๐' => 'Deprecate code that needs to be cleaned up', '๐' => 'Work on code related to authorization, roles and permissions', '๐ฉน' => 'Simple fix for a non-critical issue', '๐ง' => 'Data exploration/inspection', 'โฐ' => 'Remove dead code', '๐งช' => 'Add a failing test', '๐' => 'Add or update business logic', '๐ฉบ' => 'Add or update healthcheck', '๐งฑ' => 'Infrastructure related changes', '๐งโ๐ป' => 'Improve developer experience', '๐ธ' => 'Add sponsorships or money related infrastructure', '๐งต' => 'Add or update code related to multithreading or concurrency', '๐ฆบ' => 'Add or update code related to validation' }.freeze
Constants included from DiffHelpers
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#base_url ⇒ Object
readonly
Returns the value of attribute base_url.
-
#commit_format ⇒ Object
readonly
Returns the value of attribute commit_format.
-
#diff_len ⇒ Object
readonly
Returns the value of attribute diff_len.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #aicm(verbose: false) ⇒ Object
-
#initialize ⇒ CommitAi
constructor
A new instance of CommitAi.
- #list_models ⇒ Object
Methods included from DiffHelpers
#detect_lock_file_changes, #git_diff, #prompt_diff_handling, #prompt_no_staged_changes, #split_diff_by_length
Constructor Details
#initialize ⇒ CommitAi
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/commitgpt/commit_ai.rb', line 120 def initialize provider_config = ConfigManager.get_active_provider_config if provider_config @api_key = provider_config['api_key'] @base_url = provider_config['base_url'] @model = provider_config['model'] @diff_len = provider_config['diff_len'] || 32_768 else @api_key = nil @base_url = nil @model = nil @diff_len = 32_768 end @commit_format = ConfigManager.get_commit_format end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
19 20 21 |
# File 'lib/commitgpt/commit_ai.rb', line 19 def api_key @api_key end |
#base_url ⇒ Object (readonly)
Returns the value of attribute base_url.
19 20 21 |
# File 'lib/commitgpt/commit_ai.rb', line 19 def base_url @base_url end |
#commit_format ⇒ Object (readonly)
Returns the value of attribute commit_format.
19 20 21 |
# File 'lib/commitgpt/commit_ai.rb', line 19 def commit_format @commit_format end |
#diff_len ⇒ Object (readonly)
Returns the value of attribute diff_len.
19 20 21 |
# File 'lib/commitgpt/commit_ai.rb', line 19 def diff_len @diff_len end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
19 20 21 |
# File 'lib/commitgpt/commit_ai.rb', line 19 def model @model end |
Instance Method Details
#aicm(verbose: false) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/commitgpt/commit_ai.rb', line 138 def aicm(verbose: false) exit(1) unless welcome diff = git_diff || exit(1) if verbose puts "โ Git diff (#{diff.length} chars):".cyan puts diff puts "\n" end loop do = (diff) || exit(1) action = confirm_commit() case action when :commit commit_command = "git commit -m \"#{ai_commit_message}\"" puts "\nโ Executing: #{commit_command}".yellow system(commit_command) puts "\n\n" puts `git log -1` break when :regenerate puts "\n" next when :edit prompt = TTY::Prompt.new = prompt.ask('Enter your commit message:') if && !.strip.empty? commit_command = "git commit -m \"#{new_message}\"" system(commit_command) puts "\n" puts `git log -1` else puts 'โ Commit aborted (empty message).'.red end break when :exit puts 'โ Exit without commit.'.yellow break end end end |
#list_models ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
# File 'lib/commitgpt/commit_ai.rb', line 181 def list_models headers = { 'Content-Type' => 'application/json', 'User-Agent' => "Ruby/#{RUBY_VERSION}" } headers['Authorization'] = "Bearer #{@api_key}" if @api_key begin response = HTTParty.get("#{@base_url}/models", headers: headers) models = response['data'] || [] models.each { |m| puts m['id'] } rescue StandardError => e puts "โ Failed to list models: #{e.message}".red end end |