committer 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: bb99452bb04729fa6e0d6c2437222c3ef83ade61c7985b0bcef8ffb418f04166
4
+ data.tar.gz: 4f4f26950244b3ed7776e3764c8fb6a8b73c8178c4c03dad55357403a076875b
5
+ SHA512:
6
+ metadata.gz: b707c336ca8247e1cf685d264958f83fff4cd93945bf85efb63e98f13855217d1bfe7df8acbd9562ec9ca2ac537a70c8a6d699ec89eff70cfc20e58dee6e7648
7
+ data.tar.gz: 96fe270231433a099e89cb59f63f2ff7accd752c808f0bce83535785a2e78d61744a43b36c442f225c8e819fd931991ff844f1efdb4eea26872c269c80a00c40
data/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # Committer
2
+
3
+ An AI-powered git commit message generator using Claude.
4
+
5
+ ## Overview
6
+
7
+ Committer uses Claude AI to analyze your staged git changes and generate conventional commit messages for you. It detects the type of changes (feature, fix, refactor, etc.) and creates a well-formatted commit message that follows best practices.
8
+
9
+ ## Installation
10
+
11
+ ### Install from RubyGems
12
+
13
+ ```bash
14
+ gem install committer
15
+ ```
16
+
17
+ ### Manual Installation
18
+
19
+ 1. Install Bundler if you haven't already:
20
+
21
+ ```sh
22
+ gem install bundler
23
+ ```
24
+
25
+ 2. Install the project dependencies:
26
+ ```sh
27
+ bundle install
28
+ ```
29
+
30
+ 3. Link the executable:
31
+ ```bash
32
+ gem build committer.gemspec
33
+ gem install committer-0.1.0.gem
34
+ ```
35
+
36
+ ## Configuration
37
+
38
+ Before using Committer, you need to set up your configuration file:
39
+
40
+ ```bash
41
+ committer setup
42
+ ```
43
+
44
+ This will create a template config file at `~/.committer/config.yml`.
45
+
46
+ Next, edit this file to add your Anthropic API key and optionally change the model:
47
+
48
+ ```yaml
49
+ api_key: your_anthropic_api_key_here
50
+ model: claude-3-sonnet-20240229
51
+ ```
52
+
53
+ You only need to do this setup once.
54
+
55
+ ## Usage
56
+
57
+ When you have changes staged in git (after running `git add`), simply run:
58
+
59
+ ```bash
60
+ committer
61
+ ```
62
+
63
+ This will:
64
+ 1. Get the diff of your staged changes
65
+ 2. Send it to Claude for analysis
66
+ 3. Generate a commit message in conventional format
67
+ 4. Open your default git editor with the suggested message
68
+ 5. Allow you to edit the message if needed or simply save to confirm
69
+
70
+ ## Commands
71
+
72
+ - `committer` - Generate commit message for staged changes
73
+ - `committer setup` - Create the config file template
74
+ - `committer help` - Display help information
75
+
76
+ You can also run it directly through git:
77
+
78
+ ```bash
79
+ git smart-commit
80
+ ```
81
+
82
+ ## License
83
+
84
+ MIT
data/bin/committer ADDED
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/setup'
5
+ require 'open3'
6
+ require 'httparty'
7
+ require 'yaml'
8
+ require_relative '../lib/committer/config'
9
+ require_relative '../lib/clients/claude_client'
10
+
11
+ # Handle command line arguments
12
+ command = ARGV[0]
13
+
14
+ case command
15
+ when 'setup'
16
+ Committer::Config.setup
17
+ exit 0
18
+
19
+ when 'help', '--help', '-h'
20
+ puts 'Committer - AI-powered git commit message generator'
21
+ puts
22
+ puts 'Commands:'
23
+ puts ' committer setup - Create the config file template at ~/.committer/config.yml'
24
+ puts ' committer - Generate commit message for staged changes'
25
+ puts
26
+ exit 0
27
+ end
28
+
29
+ # Default behavior: generate commit message
30
+ def execute_git_diff_staged
31
+ stdout, stderr, status = Open3.capture3('git diff --staged')
32
+
33
+ if status.success?
34
+ if stdout.empty?
35
+ puts 'No changes are staged for commit.'
36
+ exit 0
37
+ else
38
+ begin
39
+ client = Clients::ClaudeClient.new
40
+ puts 'Sending diff to Claude...'
41
+
42
+ prompt = <<~PROMPT
43
+ Below is a git diff of staged changes. Please analyze it and create a commit message following the Conventional Commits format:
44
+
45
+ Format: <type>(<optional scope>): <description>
46
+
47
+ Types:
48
+ - feat: A new feature
49
+ - fix: A bug fix
50
+ - docs: Documentation only changes
51
+ - style: Changes that do not affect the meaning of the code
52
+ - refactor: A code change that neither fixes a bug nor adds a feature
53
+ - perf: A code change that improves performance
54
+ - test: Adding missing tests or correcting existing tests
55
+ - chore: Changes to the build process or auxiliary tools
56
+
57
+ Guidelines:
58
+ - Keep the first line under 70 characters
59
+ - Use imperative, present tense (e.g., "add" not "added" or "adds")
60
+ - Do not end with a period
61
+ - Be concise but descriptive
62
+
63
+ Git Diff:
64
+ ```
65
+ #{stdout}
66
+ ```
67
+
68
+ Respond ONLY with the commit message text, nothing else.
69
+ PROMPT
70
+
71
+ response = client.post(prompt)
72
+ commit_message = begin
73
+ response.dig('content', 0, 'text')
74
+ rescue StandardError
75
+ response.inspect
76
+ end
77
+
78
+ puts "\nOpening git commit with the suggested message..."
79
+
80
+ # Create git commit with the suggested message and open in editor
81
+ system('git', 'commit', '-m', commit_message, '-e')
82
+ rescue Clients::ClaudeClient::ConfigError => e
83
+ puts "Error: #{e.message}"
84
+ exit 1
85
+ rescue StandardError => e
86
+ puts "Error: #{e.message}"
87
+ exit 1
88
+ end
89
+ end
90
+ else
91
+ puts 'Error executing git diff --staged:'
92
+ puts stderr
93
+ exit 1
94
+ end
95
+ end
96
+
97
+ # Execute the function if no specific command was given
98
+ execute_git_diff_staged
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # This is a git integration script that allows users to run:
5
+ # git smart-commit
6
+ # which will forward to the committer command
7
+
8
+ require_relative 'committer'
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'httparty'
5
+ require_relative '../committer/config'
6
+
7
+ module Clients
8
+ class ClaudeClient
9
+ class OverloadError < StandardError; end
10
+ class UnknownError < StandardError; end
11
+ class ConfigError < StandardError; end
12
+
13
+ def initialize
14
+ @config = Committer::Config.load
15
+
16
+ return unless @config['api_key'].nil? || @config['api_key'].empty?
17
+
18
+ raise ConfigError,
19
+ "API key not configured. Run 'committer setup' and edit ~/.committer/config.yml to add your API key."
20
+ end
21
+
22
+ def post(message)
23
+ body = {
24
+ 'model': @config['model'],
25
+ 'max_tokens': 4096,
26
+ 'messages': [
27
+ { 'role': 'user', 'content': message }
28
+ ]
29
+ }
30
+ options = {
31
+ headers: {
32
+ 'anthropic-version': '2023-06-01',
33
+ 'content-type': 'application/json',
34
+ 'x-api-key': @config['api_key']
35
+ },
36
+ body: body.to_json
37
+ }
38
+ response = HTTParty.post(
39
+ 'https://api.anthropic.com/v1/messages', options
40
+ )
41
+ if response['type'] == 'error'
42
+ error = response['error']
43
+ raise OverloadError if error['type'] == 'overloaded_error'
44
+
45
+ puts response
46
+ raise UnknownError, "Claude API error: #{response.inspect}"
47
+ end
48
+ response
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'yaml'
4
+ require 'fileutils'
5
+
6
+ module Committer
7
+ class Config
8
+ CONFIG_DIR = File.join(Dir.home, '.committer')
9
+ CONFIG_FILE = File.join(CONFIG_DIR, 'config.yml')
10
+ DEFAULT_CONFIG = {
11
+ 'api_key' => nil,
12
+ 'model' => 'claude-3-sonnet-20240229'
13
+ }.freeze
14
+
15
+ def self.load
16
+ create_default_config unless File.exist?(CONFIG_FILE)
17
+ begin
18
+ YAML.load_file(CONFIG_FILE) || DEFAULT_CONFIG
19
+ rescue StandardError => e
20
+ puts "Error loading config: #{e.message}"
21
+ DEFAULT_CONFIG
22
+ end
23
+ end
24
+
25
+ def self.create_default_config
26
+ FileUtils.mkdir_p(CONFIG_DIR) unless Dir.exist?(CONFIG_DIR)
27
+ File.write(CONFIG_FILE, DEFAULT_CONFIG.to_yaml)
28
+ end
29
+
30
+ def self.setup
31
+ create_default_config
32
+ puts 'Created config file at:'
33
+ puts CONFIG_FILE
34
+ puts "\nPlease edit this file to add your Anthropic API key."
35
+ puts 'Example config format:'
36
+ puts '---'
37
+ puts 'api_key: your_api_key_here'
38
+ puts 'model: claude-3-sonnet-20240229'
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Committer
4
+ VERSION = '0.1.0'
5
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: committer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Sebastien Stettler
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-03-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.20'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.20'
27
+ description: A tool that uses Claude API to generate conventional commit messages
28
+ based on staged changes
29
+ email:
30
+ - sebastien@managerbot.dev
31
+ executables:
32
+ - git-smart-commit
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - README.md
37
+ - bin/committer
38
+ - bin/git-smart-commit
39
+ - lib/clients/claude_client.rb
40
+ - lib/committer/config.rb
41
+ - lib/committer/version.rb
42
+ homepage: https://github.com/Hyper-Unearthing/committer
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.6.0
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.5.22
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: AI-powered git commit message generator using Claude
65
+ test_files: []