ai_refactor 0.4.0 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +21 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +165 -1
- data/README.md +145 -16
- data/examples/.gitignore +1 -0
- data/examples/ex1_convert_a_rspec_test_to_minitest.yml +7 -0
- data/examples/ex1_input_spec.rb +32 -0
- data/examples/rails_helper.rb +21 -0
- data/examples/test_helper.rb +14 -0
- data/exe/ai_refactor +96 -42
- data/lib/ai_refactor/cli.rb +60 -8
- data/lib/ai_refactor/command_file_parser.rb +27 -0
- data/lib/ai_refactor/context.rb +1 -1
- data/lib/ai_refactor/file_processor.rb +1 -1
- data/lib/ai_refactor/prompt.rb +4 -4
- data/lib/ai_refactor/refactors/base_refactor.rb +9 -7
- data/lib/ai_refactor/refactors/{generic.rb → custom.rb} +2 -2
- data/lib/ai_refactor/refactors/minitest/write_test_for_class.md +5 -1
- data/lib/ai_refactor/refactors/minitest/write_test_for_class.rb +2 -2
- data/lib/ai_refactor/refactors/rails/minitest/rspec_to_minitest.rb +2 -2
- data/lib/ai_refactor/refactors/ruby/refactor_ruby.md +10 -0
- data/lib/ai_refactor/refactors/ruby/refactor_ruby.rb +29 -0
- data/lib/ai_refactor/refactors/ruby/write_ruby.md +7 -0
- data/lib/ai_refactor/refactors/ruby/write_ruby.rb +33 -0
- data/lib/ai_refactor/run_configuration.rb +115 -0
- data/lib/ai_refactor/templated_path.rb +48 -0
- data/lib/ai_refactor/test_runners/minitest_runner.rb +1 -1
- data/lib/ai_refactor/version.rb +1 -1
- metadata +16 -4
@@ -0,0 +1,115 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module AIRefactor
|
4
|
+
class RunConfiguration
|
5
|
+
def self.add_new_option(key)
|
6
|
+
self.class.define_method(key) { instance_variable_get("@#{key}") }
|
7
|
+
self.class.define_method("#{key}=") { |v| instance_variable_set("@#{key}", v) }
|
8
|
+
end
|
9
|
+
|
10
|
+
attr_reader :refactor,
|
11
|
+
:input_file_paths,
|
12
|
+
:output_file_path,
|
13
|
+
:output_template_path,
|
14
|
+
:context_file_paths,
|
15
|
+
:context_text,
|
16
|
+
:review_prompt,
|
17
|
+
:prompt,
|
18
|
+
:prompt_file_path,
|
19
|
+
:ai_max_attempts,
|
20
|
+
:ai_model,
|
21
|
+
:ai_temperature,
|
22
|
+
:ai_max_tokens,
|
23
|
+
:ai_timeout,
|
24
|
+
:overwrite,
|
25
|
+
:diff,
|
26
|
+
:verbose,
|
27
|
+
:debug
|
28
|
+
|
29
|
+
def set!(hash)
|
30
|
+
hash.each do |key, value|
|
31
|
+
raise StandardError, "Invalid option: #{key}" unless respond_to?("#{key}=")
|
32
|
+
send("#{key}=", value)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
attr_writer :refactor
|
37
|
+
|
38
|
+
# @deprecated
|
39
|
+
def [](key)
|
40
|
+
send(key)
|
41
|
+
end
|
42
|
+
|
43
|
+
def input_file_paths=(paths)
|
44
|
+
@input_file_paths ||= []
|
45
|
+
paths = [paths] unless paths.is_a?(Array)
|
46
|
+
@input_file_paths.concat(paths)
|
47
|
+
end
|
48
|
+
|
49
|
+
attr_writer :output_file_path
|
50
|
+
|
51
|
+
attr_writer :output_template_path
|
52
|
+
|
53
|
+
def context_file_paths=(paths)
|
54
|
+
@context_file_paths ||= []
|
55
|
+
paths = [paths] unless paths.is_a?(Array)
|
56
|
+
@context_file_paths.concat(paths)
|
57
|
+
end
|
58
|
+
|
59
|
+
def context_text=(text)
|
60
|
+
@context_text ||= ""
|
61
|
+
@context_text += text
|
62
|
+
end
|
63
|
+
|
64
|
+
attr_writer :review_prompt
|
65
|
+
attr_writer :prompt
|
66
|
+
attr_writer :prompt_file_path
|
67
|
+
|
68
|
+
def rspec_run_command
|
69
|
+
@rspec_run_command || "bundle exec rspec __FILE__"
|
70
|
+
end
|
71
|
+
|
72
|
+
def minitest_run_command
|
73
|
+
@minitest_run_command || "ruby __FILE__"
|
74
|
+
end
|
75
|
+
|
76
|
+
attr_writer :rspec_run_command
|
77
|
+
attr_writer :minitest_run_command
|
78
|
+
|
79
|
+
def ai_max_attempts=(value)
|
80
|
+
@ai_max_attempts = value || 3
|
81
|
+
end
|
82
|
+
|
83
|
+
def ai_model=(value)
|
84
|
+
@ai_model = value || "gpt-4"
|
85
|
+
end
|
86
|
+
|
87
|
+
def ai_temperature=(value)
|
88
|
+
@ai_temperature = value || 0.7
|
89
|
+
end
|
90
|
+
|
91
|
+
def ai_max_tokens=(value)
|
92
|
+
@ai_max_tokens = value || 1500
|
93
|
+
end
|
94
|
+
|
95
|
+
def ai_timeout=(value)
|
96
|
+
@ai_timeout = value || 60
|
97
|
+
end
|
98
|
+
|
99
|
+
def overwrite=(value)
|
100
|
+
@overwrite = value || "a"
|
101
|
+
end
|
102
|
+
|
103
|
+
attr_writer :diff
|
104
|
+
|
105
|
+
attr_writer :verbose
|
106
|
+
|
107
|
+
attr_writer :debug
|
108
|
+
|
109
|
+
def to_options
|
110
|
+
instance_variables.each_with_object({}) do |var, hash|
|
111
|
+
hash[var.to_s.delete("@").to_sym] = instance_variable_get(var)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
module AIRefactor
|
2
|
+
class TemplatedPath
|
3
|
+
def initialize(input_file, refactor_name, template)
|
4
|
+
@input_file = input_file
|
5
|
+
@refactor_name = refactor_name
|
6
|
+
raise ArgumentError unless template.length.positive?
|
7
|
+
@template = template
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate
|
11
|
+
path_from_template
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def path_from_template
|
17
|
+
path = @template.dup
|
18
|
+
@template.scan(/\[(FILE|NAME|DIR|REFACTOR|EXT)(\|([^|]+)\|([^\]]*))?\]/).each do |match|
|
19
|
+
type, sub, old_value, new_value = match
|
20
|
+
puts "type: #{type}, sub: #{sub}, old_value: #{old_value}, new_value: #{new_value}"
|
21
|
+
value = send(type.downcase.to_sym)
|
22
|
+
value = value.gsub(old_value, new_value) if sub
|
23
|
+
path.gsub!("[#{type}#{sub}]", value)
|
24
|
+
end
|
25
|
+
path
|
26
|
+
end
|
27
|
+
|
28
|
+
def file
|
29
|
+
File.basename(@input_file)
|
30
|
+
end
|
31
|
+
|
32
|
+
def name
|
33
|
+
File.basename(@input_file, ".*")
|
34
|
+
end
|
35
|
+
|
36
|
+
def dir
|
37
|
+
File.dirname(@input_file)
|
38
|
+
end
|
39
|
+
|
40
|
+
def refactor
|
41
|
+
@refactor_name
|
42
|
+
end
|
43
|
+
|
44
|
+
def ext
|
45
|
+
File.extname(@input_file)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -5,7 +5,7 @@ require "open3"
|
|
5
5
|
module AIRefactor
|
6
6
|
module TestRunners
|
7
7
|
class MinitestRunner
|
8
|
-
def initialize(file_path, command_template: "
|
8
|
+
def initialize(file_path, command_template: "ruby __FILE__")
|
9
9
|
@file_path = file_path
|
10
10
|
@command_template = command_template
|
11
11
|
end
|
data/lib/ai_refactor/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ai_refactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|
@@ -89,9 +89,15 @@ files:
|
|
89
89
|
- README.md
|
90
90
|
- Rakefile
|
91
91
|
- ai_refactor.gemspec
|
92
|
+
- examples/.gitignore
|
93
|
+
- examples/ex1_convert_a_rspec_test_to_minitest.yml
|
94
|
+
- examples/ex1_input_spec.rb
|
95
|
+
- examples/rails_helper.rb
|
96
|
+
- examples/test_helper.rb
|
92
97
|
- exe/ai_refactor
|
93
98
|
- lib/ai_refactor.rb
|
94
99
|
- lib/ai_refactor/cli.rb
|
100
|
+
- lib/ai_refactor/command_file_parser.rb
|
95
101
|
- lib/ai_refactor/context.rb
|
96
102
|
- lib/ai_refactor/file_processor.rb
|
97
103
|
- lib/ai_refactor/logger.rb
|
@@ -100,7 +106,7 @@ files:
|
|
100
106
|
- lib/ai_refactor/prompts/input.md
|
101
107
|
- lib/ai_refactor/refactors.rb
|
102
108
|
- lib/ai_refactor/refactors/base_refactor.rb
|
103
|
-
- lib/ai_refactor/refactors/
|
109
|
+
- lib/ai_refactor/refactors/custom.rb
|
104
110
|
- lib/ai_refactor/refactors/minitest/write_test_for_class.md
|
105
111
|
- lib/ai_refactor/refactors/minitest/write_test_for_class.rb
|
106
112
|
- lib/ai_refactor/refactors/project/write_changelog_from_history.md
|
@@ -109,6 +115,12 @@ files:
|
|
109
115
|
- lib/ai_refactor/refactors/rails/minitest/rspec_to_minitest.rb
|
110
116
|
- lib/ai_refactor/refactors/rspec/minitest_to_rspec.md
|
111
117
|
- lib/ai_refactor/refactors/rspec/minitest_to_rspec.rb
|
118
|
+
- lib/ai_refactor/refactors/ruby/refactor_ruby.md
|
119
|
+
- lib/ai_refactor/refactors/ruby/refactor_ruby.rb
|
120
|
+
- lib/ai_refactor/refactors/ruby/write_ruby.md
|
121
|
+
- lib/ai_refactor/refactors/ruby/write_ruby.rb
|
122
|
+
- lib/ai_refactor/run_configuration.rb
|
123
|
+
- lib/ai_refactor/templated_path.rb
|
112
124
|
- lib/ai_refactor/test_runners/minitest_runner.rb
|
113
125
|
- lib/ai_refactor/test_runners/rspec_runner.rb
|
114
126
|
- lib/ai_refactor/test_runners/test_run_diff_report.rb
|
@@ -135,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
135
147
|
- !ruby/object:Gem::Version
|
136
148
|
version: '0'
|
137
149
|
requirements: []
|
138
|
-
rubygems_version: 3.4.
|
150
|
+
rubygems_version: 3.4.19
|
139
151
|
signing_key:
|
140
152
|
specification_version: 4
|
141
153
|
summary: Use AI to convert a Rails RSpec test suite to minitest.
|