matheus 0.6.4 → 0.7.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: 3242a48a3b7fe938a403c8e5585e3b1fa1e8c5ba444d0bd9d504410c1fb66d40
4
- data.tar.gz: d0687724e54eb42d206c41b9d22960249b8aef9adb30538c206950fdb0fc30a3
3
+ metadata.gz: a5a35e65053e7e649e79f1a2e2fc75b7a03e0cdcbe711374d6dd7f91c18f9316
4
+ data.tar.gz: bc5fbdbb8df7b80dcf5fbe64290a4319cbcdc9e4f3dbbb3c8b6a8b06b6caaae2
5
5
  SHA512:
6
- metadata.gz: b5adab4e860c1a9948419654f467a0d7b3cace6c63d427f22906fe5c7bd63ed50944653cf0d1e63fc729ed36ca424b84252ac87694e2fb04d09372e6eb8b8ea3
7
- data.tar.gz: 43d1385804ba40942a75aaa4bf533f77beb920bb88f67568a9cc7cb230db609680869610096c0c198a44693849afd398e0a4d62e76fd1a26f20b2410bc2cb3fe
6
+ metadata.gz: af2982cd118538f93f5092dbbd2c1ef0af7716f9a31f94ae44211b91b64f407373cbec566cf465a97ae2cdfc885c2b7f718511f8775d08a68b73d4a62b5cf2f9
7
+ data.tar.gz: e87d00e609c751f9330a444cffc131af5784f2be706d831534a8e421c196c517c1e8d0473fef5f4b192d9e2455d28108a4d9e5a2edd34f2ab887f9967271592a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.7.0]
4
+
5
+ _Released 2025-03-03_
6
+
7
+ - Add `quick-commit` command to commit staged changes with a generated message.
8
+
3
9
  ## [0.6.0]
4
10
 
5
11
  _Released 2025-01-07_
data/README.md CHANGED
@@ -54,6 +54,14 @@ $ puts 10.days.ago
54
54
  2024-08-17 15:50:11 -0300
55
55
  ```
56
56
 
57
+ ### [`quick-commit`](./lib/matheus/quick_commit.rb)
58
+
59
+ Commits the staged changes with a generated commit message.
60
+
61
+ ```sh
62
+ $ quick-commit
63
+ ```
64
+
57
65
  ## Contributing
58
66
 
59
67
  Probably not accepting contributions at the moment, but feel free to open an issue if you have any ideas or suggestions.
data/exe/quick-commit ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift("#{__dir__}/../lib")
4
+
5
+ require "matheus"
6
+
7
+ Matheus::QuickCommit.call ARGV
@@ -5,9 +5,9 @@ module Matheus
5
5
  include Result::Methods
6
6
  extend StringFormat
7
7
 
8
- def self.call(argv)
8
+ def self.call(...)
9
9
  new
10
- .call(argv)
10
+ .call(...)
11
11
  .then { Result.from(_1) } # ensure it's a Result object
12
12
  .on_failure { |error_msg| abort error(error_msg) }
13
13
  end
data/lib/matheus/q.rb CHANGED
@@ -10,18 +10,18 @@ module Matheus
10
10
  class Q < Command
11
11
  BASE_PROMPT = "Answer this question in a short and concise way. You can use markdown in the response: "
12
12
 
13
- def call(question)
13
+ def call(*question, skip_cache: false)
14
14
  question = question.join(" ")
15
15
  existing_entry = search_question_in_history(question)
16
16
 
17
- if existing_entry && use_existing_answer?
17
+ if existing_entry && use_existing_answer?(skip_cache)
18
18
  answer = existing_entry["answer"]
19
19
  else
20
20
  answer = ask_llm(question)
21
21
  save_qa(question, answer)
22
22
  end
23
23
 
24
- print_markdown(answer)
24
+ answer.tap { |it| print_markdown(it) }
25
25
  rescue => e
26
26
  Failure(e.message)
27
27
  end
@@ -67,7 +67,9 @@ module Matheus
67
67
  load_history.reverse.find { |entry| entry["question"].downcase.strip == question.downcase.strip }
68
68
  end
69
69
 
70
- def use_existing_answer?
70
+ def use_existing_answer?(skip_cache)
71
+ return false if skip_cache
72
+
71
73
  prompt = TTY::Prompt.new
72
74
  prompt.yes?("An existing answer was found. Do you want to use it?") do |q|
73
75
  q.default true
@@ -0,0 +1,25 @@
1
+ module Matheus
2
+
3
+ class QuickCommit < Command
4
+ # Usage:
5
+ # $ quick-commit
6
+ def call(*)
7
+ diff = `git diff --cached`
8
+ return Failure("No changes to commit.") if diff.blank?
9
+
10
+ Q.call(["Please write a good one-line commit message for the following diff. Return only plain-text. Diff:\n#{diff}"], skip_cache: true)
11
+ .on_success { |msg| confirm("Accept commit message?", return_value: msg) }
12
+ .on_success { |commit_message| system(%(git commit -m "#{commit_message}"), :out => :close) }
13
+ end
14
+
15
+ private
16
+
17
+ def confirm(message, return_value:)
18
+ response = TTY::Prompt.new.yes?(message) do |q|
19
+ q.default true
20
+ end
21
+
22
+ response ? Success(return_value) : Failure("Cancelled by user.")
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Matheus
4
- VERSION = "0.6.4"
4
+ VERSION = "0.7.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matheus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matheus Richard
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-02-12 00:00:00.000000000 Z
11
+ date: 2025-03-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: zeitwerk
@@ -118,6 +118,7 @@ executables:
118
118
  - puts
119
119
  - q
120
120
  - qs
121
+ - quick-commit
121
122
  extensions: []
122
123
  extra_rdoc_files: []
123
124
  files:
@@ -133,6 +134,7 @@ files:
133
134
  - exe/puts
134
135
  - exe/q
135
136
  - exe/qs
137
+ - exe/quick-commit
136
138
  - lib/matheus.rb
137
139
  - lib/matheus/alert_me.rb
138
140
  - lib/matheus/command.rb
@@ -141,6 +143,7 @@ files:
141
143
  - lib/matheus/puts.rb
142
144
  - lib/matheus/q.rb
143
145
  - lib/matheus/qs.rb
146
+ - lib/matheus/quick_commit.rb
144
147
  - lib/matheus/result.rb
145
148
  - lib/matheus/string_format.rb
146
149
  - lib/matheus/version.rb