soapstone 0.1.1

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.
Files changed (41) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/.standard.yml +3 -0
  4. data/CHANGELOG.md +5 -0
  5. data/CODE_OF_CONDUCT.md +132 -0
  6. data/LICENSE.txt +21 -0
  7. data/README.md +43 -0
  8. data/Rakefile +20 -0
  9. data/bin/sgn +6 -0
  10. data/lib/soapstone/.DS_Store +0 -0
  11. data/lib/soapstone/config/configuration.rb +31 -0
  12. data/lib/soapstone/config/load.rb +40 -0
  13. data/lib/soapstone/config/wizard.rb +40 -0
  14. data/lib/soapstone/core/ai/anthropic_provider.rb +33 -0
  15. data/lib/soapstone/core/ai/client.rb +36 -0
  16. data/lib/soapstone/core/ai/open_ai_provider.rb +39 -0
  17. data/lib/soapstone/core/ai/prompt_builder.rb +91 -0
  18. data/lib/soapstone/core/commit_message_generator.rb +20 -0
  19. data/lib/soapstone/core/context/git_branch.rb +42 -0
  20. data/lib/soapstone/core/context/linear.rb +57 -0
  21. data/lib/soapstone/core/fetch_linear_issue.rb +72 -0
  22. data/lib/soapstone/core/git_command.rb +19 -0
  23. data/lib/soapstone/core/message_presenter.rb +91 -0
  24. data/lib/soapstone/operations/commit.rb +85 -0
  25. data/lib/soapstone/ui/components/box.rb +29 -0
  26. data/lib/soapstone/ui/components/prompt.rb +17 -0
  27. data/lib/soapstone/ui/menus/ai_settings.rb +131 -0
  28. data/lib/soapstone/ui/menus/git_settings.rb +55 -0
  29. data/lib/soapstone/ui/menus/linear_settings.rb +59 -0
  30. data/lib/soapstone/ui/prompts/ask.rb +24 -0
  31. data/lib/soapstone/ui/prompts/select.rb +50 -0
  32. data/lib/soapstone/ui/prompts/select_answer.rb +10 -0
  33. data/lib/soapstone/ui/prompts/yes_no.rb +25 -0
  34. data/lib/soapstone/ui/screens/utils.rb +5 -0
  35. data/lib/soapstone/ui/screens/welcome.rb +103 -0
  36. data/lib/soapstone/ui/screens/wizard.rb +40 -0
  37. data/lib/soapstone/version.rb +5 -0
  38. data/lib/soapstone.rb +49 -0
  39. data/sig/soapstone.rbs +4 -0
  40. data/soapstone-0.1.0.gem +0 -0
  41. metadata +269 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 75af8da5c41a7f4b05c31f4d5402d008976e07db89f006437000791f6e079bdc
4
+ data.tar.gz: c955a7ba722a885967b82720bdaf36d492a4f5d563934b82ed8ac20c3e50bb73
5
+ SHA512:
6
+ metadata.gz: ccb04876369fcebe2c5e321b07055e9a3b52d11cc4c46e26e26ef8790a161cfb3a4caa2929ffec5b1b0029c2d1c544e06ec22c17740e5f6646b45e2ea476af6b
7
+ data.tar.gz: 73b23908bbc5d1c6c0e91de531b9993af310197a8061c682400679366a7f0b2828bde0b003f301d2e882aa164eadf7ee0c3bbf0535489f41a91c6796d1b328e2
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.1
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-06-14
4
+
5
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Dan Frenette
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # Soapstone
2
+
3
+ TODO: Delete this and the text below, and describe your gem
4
+
5
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/soapstone`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ ```bash
14
+ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
15
+ ```
16
+
17
+ If bundler is not being used to manage dependencies, install the gem by executing:
18
+
19
+ ```bash
20
+ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
21
+ ```
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/danfrenette/soapstone. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/danfrenette/soapstone/blob/main/CODE_OF_CONDUCT.md).
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Soapstone project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/danfrenette/soapstone/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
11
+
12
+ desc "Run the standardrb linter"
13
+ task :standard do
14
+ sh "standardrb"
15
+ end
16
+
17
+ desc "Fix Standard Ruby linting issues"
18
+ task :standard_fix do
19
+ sh "bundle exec standardrb --fix"
20
+ end
data/bin/sgn ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "soapstone"
5
+
6
+ Soapstone::CLI.start(ARGV)
Binary file
@@ -0,0 +1,31 @@
1
+ require "active_support/core_ext/hash/indifferent_access"
2
+
3
+ class Soapstone::Config::Configuration
4
+ DEFAULT_CONFIG = {}.with_indifferent_access
5
+
6
+ def initialize(config = DEFAULT_CONFIG)
7
+ @config = config.with_indifferent_access
8
+ end
9
+
10
+ def get(*keys)
11
+ config.dig(*keys)
12
+ end
13
+
14
+ def set(value:, path:)
15
+ current = config
16
+ path[0...-1].each do |key|
17
+ current[key] ||= {}.with_indifferent_access
18
+ current = current[key]
19
+ end
20
+ current[path.last] = value
21
+ config
22
+ end
23
+
24
+ def to_yaml
25
+ config.to_yaml
26
+ end
27
+
28
+ private
29
+
30
+ attr_reader :config
31
+ end
@@ -0,0 +1,40 @@
1
+ require "active_support/core_ext/hash/indifferent_access"
2
+
3
+ class Soapstone::Config::Load
4
+ DEFAULT_CONFIG_FILE = File.expand_path("~/.soapstone/config.yml")
5
+
6
+ def self.call
7
+ new.call
8
+ end
9
+
10
+ def initialize
11
+ @config_file = DEFAULT_CONFIG_FILE
12
+ ensure_config_directory
13
+ setup_config
14
+ end
15
+
16
+ def call
17
+ Soapstone::Config::Configuration.new(config)
18
+ end
19
+
20
+ private
21
+
22
+ attr_reader :config, :config_file
23
+
24
+ def ensure_config_directory
25
+ config_dir = File.dirname(config_file)
26
+ FileUtils.mkdir_p(config_dir) unless Dir.exist?(config_dir)
27
+ end
28
+
29
+ def setup_config
30
+ @config = if File.exist?(config_file)
31
+ YAML.load_file(
32
+ config_file,
33
+ permitted_classes: [ActiveSupport::HashWithIndifferentAccess, Symbol],
34
+ aliases: true
35
+ )
36
+ else
37
+ {}
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ class Soapstone::Config::Wizard
2
+ def self.start
3
+ new.start
4
+ end
5
+
6
+ def initialize
7
+ @config = Soapstone::LoadConfiguration.call
8
+ @pastel = Pastel.new
9
+ end
10
+
11
+ def start
12
+ loop do
13
+ choice = Soapstone::Config::WelcomeScreen.call
14
+ break if main_menu(choice) == :exit
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ attr_reader :config, :pastel
21
+
22
+ def main_menu(choice)
23
+ case choice
24
+ when :git_settings
25
+ Soapstone::Config::GitSettingsMenu.call(config: config)
26
+ when :ai_settings
27
+ Soapstone::Config::AISettingsMenu.call(config: config)
28
+ when :linear_settings
29
+ Soapstone::Config::LinearSettingsMenu.call(config: config)
30
+ when :save_and_exit
31
+ save_configuration
32
+ :exit
33
+ end
34
+ end
35
+
36
+ def save_configuration
37
+ File.write(Soapstone::LoadConfiguration::DEFAULT_CONFIG_FILE, config.to_yaml)
38
+ puts pastel.green("Configuration saved to #{Soapstone::LoadConfiguration::DEFAULT_CONFIG_FILE}")
39
+ end
40
+ end
@@ -0,0 +1,33 @@
1
+ class Soapstone::AI::AnthropicProvider
2
+ def initialize(api_key:, model: "claude-3-haiku-20240307", **options)
3
+ @client = Anthropic::Client.new(api_key: api_key)
4
+ @model = options[:model] || model
5
+ end
6
+
7
+ def generate_commit_message(prompt)
8
+ response = make_anthropic_request(prompt.system, prompt.user)
9
+ parse_response(response)
10
+ rescue => e
11
+ "AI generation failed: #{e.message}"
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :client, :model
17
+
18
+ def make_anthropic_request(system_prompt, user_prompt)
19
+ client.messages.create(
20
+ model: model,
21
+ system: system_prompt,
22
+ messages: [
23
+ {role: "user", content: user_prompt}
24
+ ],
25
+ temperature: 0.3,
26
+ max_tokens: 500
27
+ )
28
+ end
29
+
30
+ def parse_response(response)
31
+ response.content.map(&:text).join.strip
32
+ end
33
+ end
@@ -0,0 +1,36 @@
1
+ class Soapstone::AI::Client
2
+ PROVIDERS = {
3
+ "open_ai" => Soapstone::AI::OpenAIProvider,
4
+ "anthropic" => Soapstone::AI::AnthropicProvider
5
+ }.freeze
6
+
7
+ def initialize(provider: nil)
8
+ @config = Soapstone::Config::Load.call
9
+ return if ai_is_not_enabled?
10
+
11
+ @provider_class = PROVIDERS[default_provider]
12
+ end
13
+
14
+ def generate_commit_message(prompt)
15
+ raise "No API key configured for AI provider" if default_api_key.nil?
16
+
17
+ provider = @provider_class.new(api_key: default_api_key)
18
+ provider.generate_commit_message(prompt)
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :provider_class, :config
24
+
25
+ def ai_is_not_enabled?
26
+ config.get(:ai, :enabled) == false
27
+ end
28
+
29
+ def default_provider
30
+ @default_provider ||= config.get(:ai, :default_provider) || config.get(:ai, :api_keys).keys.first
31
+ end
32
+
33
+ def default_api_key
34
+ @default_api_key ||= config.get(:ai, :api_keys, default_provider)
35
+ end
36
+ end
@@ -0,0 +1,39 @@
1
+ class Soapstone::AI::OpenAIProvider
2
+ def initialize(api_key:, model: "gpt-4o-mini", **options)
3
+ @client = OpenAI::Client.new(api_key: api_key)
4
+ @model = options[:model] || model
5
+ end
6
+
7
+ def generate_commit_message(prompt)
8
+ response = make_openai_request(prompt.system, prompt.user)
9
+ parse_response(response)
10
+ rescue => e
11
+ "AI generation failed: #{e.message}"
12
+ end
13
+
14
+ private
15
+
16
+ attr_reader :client, :model
17
+
18
+ def make_openai_request(system_prompt, user_prompt)
19
+ client.chat.completions.create(
20
+ model: model,
21
+ messages: [
22
+ {
23
+ role: "system",
24
+ content: system_prompt
25
+ },
26
+ {
27
+ role: "user",
28
+ content: user_prompt
29
+ }
30
+ ],
31
+ temperature: 0.3,
32
+ max_tokens: 500
33
+ )
34
+ end
35
+
36
+ def parse_response(response)
37
+ response.choices.first.message.content.strip
38
+ end
39
+ end
@@ -0,0 +1,91 @@
1
+ class Soapstone::AI::PromptBuilder
2
+ Prompt = Data.define(:system, :user)
3
+
4
+ def self.build_prompt
5
+ new.build_prompt
6
+ end
7
+
8
+ def initialize
9
+ @config = Soapstone::Config::Load.call
10
+ end
11
+
12
+ def build_prompt
13
+ Prompt.new(system: system_prompt, user: user_prompt)
14
+ end
15
+
16
+ private
17
+
18
+ attr_reader :config
19
+
20
+ def system_prompt
21
+ <<~SYSTEM_PROMPT
22
+ You are an expert at writing #{commit_type} commit messages.
23
+ Generate a clean, concise #{commit_type} commit message based on the git diff provided.
24
+ The user will provide the diff and you will generate the commit message.
25
+ The commit subject will be cut off at 50 characters.
26
+
27
+ #{format_instructions}
28
+ SYSTEM_PROMPT
29
+ end
30
+
31
+ def user_prompt
32
+ <<~USER_PROMPT
33
+ #{preface}
34
+ #{diff_content}
35
+ #{linear_integration_prompt}
36
+ USER_PROMPT
37
+ end
38
+
39
+ def preface
40
+ "Please write a git commit message and provide a detailed description of the changes from the following diff:\n\n"
41
+ end
42
+
43
+ def diff_content
44
+ <<~DIFF
45
+ Diff:
46
+ ```
47
+ #{Soapstone::GitCommand.staged_diff}
48
+ ```
49
+ DIFF
50
+ end
51
+
52
+ def linear_integration_prompt
53
+ return unless linear_enabled?
54
+
55
+ issue_data = Soapstone::FetchLinearIssue.call
56
+
57
+ return if issue_data.nil? || issue_data.empty? || issue_data["identifier"].nil?
58
+
59
+ <<~CONTEXT
60
+ Linear Issue: #{issue_data["identifier"]} - #{issue_data["title"]} (https://linear.app/issue/#{issue_data["identifier"]})
61
+ Description: #{issue_data["description"]}
62
+ CONTEXT
63
+ end
64
+
65
+ def format_instructions
66
+ # Add instructions about commit message format based on config
67
+ case commit_type
68
+ when "conventional"
69
+ "Use conventional commit format (type: description)."
70
+
71
+ when "issue_tracker_driven"
72
+ "Use issue tracker driven format. Similar to conventional, but with the issue key in the beginning: Jira-123: message"
73
+
74
+ when "gitmoji"
75
+ "Use gitmoji format. Similar to conventional, but with the emoji in the beginning: :bug: message"
76
+
77
+ when "hybrid"
78
+ "A hybrid of issue-tracker-driven and conventional. Issue keys are the context for the commit message. Example: feat(Jira-123): message"
79
+ else
80
+ ""
81
+ end
82
+ end
83
+
84
+ def commit_type
85
+ config.get(:git_settings, :type_style)
86
+ end
87
+
88
+ def linear_enabled?
89
+ config.get("linear", "enabled")
90
+ end
91
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Soapstone::CommitMessageGenerator
4
+ def initialize
5
+ @config = Soapstone::Config::Load.call
6
+ @ai_client = Soapstone::AI::Client.new(provider: default_provider)
7
+ end
8
+
9
+ def call(prompt)
10
+ ai_client.generate_commit_message(prompt)
11
+ end
12
+
13
+ private
14
+
15
+ attr_reader :ai_client, :config
16
+
17
+ def default_provider
18
+ config.get(:ai, :default_provider) || config.get(:ai, :api_keys).keys.first
19
+ end
20
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Soapstone::Context::GitBranch
4
+ def self.call
5
+ new.call
6
+ end
7
+
8
+ def initialize
9
+ @config = Soapstone::Config::Load.call
10
+ @current_branch = Soapstone::GitCommand.current_branch
11
+ end
12
+
13
+ def call
14
+ BranchContext.new(
15
+ current_branch: current_branch,
16
+ default_branch: default_branch,
17
+ on_default_branch: on_default_branch?
18
+ )
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :config, :current_branch
24
+
25
+ def default_branch
26
+ config.get("git_settings", "default_branch") || "main"
27
+ end
28
+
29
+ def on_default_branch?
30
+ current_branch == default_branch
31
+ end
32
+
33
+ BranchContext = Data.define(
34
+ :current_branch,
35
+ :default_branch,
36
+ :on_default_branch
37
+ ) do
38
+ def default_branch?
39
+ on_default_branch
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Soapstone::Context::Linear
4
+ def self.call(branch_name)
5
+ new(branch_name).call
6
+ end
7
+
8
+ def initialize(branch_name)
9
+ @config = Soapstone::Config::Load.call
10
+ @branch_name = branch_name
11
+ end
12
+
13
+ def call
14
+ LinearInfo.new(
15
+ enabled: linear_enabled?,
16
+ pattern: linear_pattern,
17
+ matches_pattern: matches_linear_pattern?
18
+ )
19
+ end
20
+
21
+ private
22
+
23
+ attr_reader :config, :branch_name
24
+
25
+ def linear_enabled?
26
+ config.get("linear", "enabled")
27
+ end
28
+
29
+ def linear_pattern
30
+ config.get("linear", "ticket_regex")
31
+ end
32
+
33
+ def matches_linear_pattern?
34
+ return false unless linear_pattern && !linear_pattern.empty?
35
+
36
+ begin
37
+ regex = Regexp.new(linear_pattern, Regexp::IGNORECASE)
38
+ !!branch_name.match(regex)
39
+ rescue RegexpError
40
+ false
41
+ end
42
+ end
43
+
44
+ LinearInfo = Data.define(
45
+ :enabled,
46
+ :pattern,
47
+ :matches_pattern
48
+ ) do
49
+ def enabled?
50
+ enabled
51
+ end
52
+
53
+ def matches_pattern?
54
+ matches_pattern
55
+ end
56
+ end
57
+ end