ai_refactor 0.5.0 → 0.5.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/Gemfile.lock +1 -1
- data/README.md +29 -0
- data/exe/ai_refactor +2 -1
- data/lib/ai_refactor/cli.rb +1 -1
- data/lib/ai_refactor/context.rb +1 -1
- data/lib/ai_refactor/refactors/base_refactor.rb +1 -6
- data/lib/ai_refactor/refactors/minitest/write_test_for_class.md +2 -2
- data/lib/ai_refactor/refactors/minitest/write_test_for_class.rb +2 -2
- data/lib/ai_refactor/templated_path.rb +48 -0
- data/lib/ai_refactor/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e50d610e50fdbccc133cd5951cee61244602b402917aa2eb1ab37713b3a6b276
|
4
|
+
data.tar.gz: eee461b016a3dec20476828383da3571999649097472eedc68f736d6ea759057
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4c913a3263949687e98681697e5fe2631748aa57dbc3ea4c7aa3f367a3ce98cb6d2d3ea86653f2e949fd65d055dd9c0f67d93c79602742fb179a27568639ed6
|
7
|
+
data.tar.gz: 41324b5dd54d62f59d749638c7b813e4d2fcc4d75528aaf4e37ba4027773b87195a1dad6ffc4400b9ce34ba38004319d7385879b8d01f00a8161a86eec842a6a
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# AI Refactor Changelog
|
2
2
|
|
3
|
+
## [0.5.1] - 2023-09-21
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Support for substitutions in path templates.
|
8
|
+
|
9
|
+
### Fixed
|
10
|
+
|
11
|
+
- Fixes issue with refactor type specified on command line not being picked up.
|
12
|
+
|
13
|
+
|
3
14
|
## [0.5.0] - 2023-09-21
|
4
15
|
|
5
16
|
### Added
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -21,6 +21,35 @@ AI Refactor currently uses [OpenAI's ChatGPT](https://platform.openai.com/).
|
|
21
21
|
|
22
22
|
See the [examples](examples/) directory for some examples of using the tool.
|
23
23
|
|
24
|
+
You can run the command files to run the example.
|
25
|
+
|
26
|
+
For example, the first example can be run with: (you can add options if desired, eg `-v` for verbose output and `-d` for debug output)
|
27
|
+
|
28
|
+
```shell
|
29
|
+
./exe/ai_refactor examples/ex1_convert_a_rspec_test_to_minitest.yml
|
30
|
+
```
|
31
|
+
|
32
|
+
You should see:
|
33
|
+
|
34
|
+
```
|
35
|
+
$ ./exe/ai_refactor examples/ex1_convert_a_rspec_test_to_minitest.yml
|
36
|
+
Loading refactor command file 'examples/ex1_convert_a_rspec_test_to_minitest.yml'...
|
37
|
+
AI Refactor 1 files(s)/dir(s) '["examples/ex1_input_spec.rb"]' with rails/minitest/rspec_to_minitest refactor
|
38
|
+
====================
|
39
|
+
Processing examples/ex1_input_spec.rb...
|
40
|
+
|
41
|
+
No differences found! Conversion worked!
|
42
|
+
Refactor succeeded on examples/ex1_input_spec.rb
|
43
|
+
|
44
|
+
All files processed successfully!
|
45
|
+
Done processing all files!
|
46
|
+
```
|
47
|
+
|
48
|
+
And find the file `examples/ex1_input_test.rb` has been created. Note the process above also ran the generated test file and compared the output to the original test file.
|
49
|
+
|
50
|
+
If you see an error, then try to run it again, or use a different GPT model.
|
51
|
+
|
52
|
+
|
24
53
|
## Available refactors
|
25
54
|
|
26
55
|
Write your own prompt:
|
data/exe/ai_refactor
CHANGED
@@ -179,7 +179,7 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
|
|
179
179
|
end
|
180
180
|
|
181
181
|
logger = AIRefactor::Logger.new(verbose: run_config.verbose, debug: run_config.debug)
|
182
|
-
logger.info "
|
182
|
+
logger.info "Also loaded options from '.ai_refactor' file..." if options_from_config_file&.size&.positive?
|
183
183
|
|
184
184
|
command_or_file = arguments.shift
|
185
185
|
if AIRefactor::CommandFileParser.command_file?(command_or_file)
|
@@ -191,6 +191,7 @@ if AIRefactor::CommandFileParser.command_file?(command_or_file)
|
|
191
191
|
end
|
192
192
|
else
|
193
193
|
logger.info "Requested to run refactor '#{command_or_file}'..."
|
194
|
+
run_config.refactor = command_or_file
|
194
195
|
end
|
195
196
|
|
196
197
|
run_config.input_file_paths = arguments
|
data/lib/ai_refactor/cli.rb
CHANGED
data/lib/ai_refactor/context.rb
CHANGED
@@ -79,7 +79,6 @@ module AIRefactor
|
|
79
79
|
output_content
|
80
80
|
rescue => e
|
81
81
|
logger.error "Request to AI failed: #{e.message}"
|
82
|
-
puts e.backtrace
|
83
82
|
logger.warn "Skipping #{input_file}..."
|
84
83
|
self.failed_message = "Request to OpenAI failed"
|
85
84
|
raise e
|
@@ -147,11 +146,7 @@ module AIRefactor
|
|
147
146
|
end
|
148
147
|
|
149
148
|
def output_file_path_from_template
|
150
|
-
path =
|
151
|
-
.gsub("[NAME]", File.basename(input_file, ".*"))
|
152
|
-
.gsub("[DIR]", File.dirname(input_file))
|
153
|
-
.gsub("[REFACTOR]", self.class.refactor_name)
|
154
|
-
.gsub("[EXT]", File.extname(input_file))
|
149
|
+
path = AIRefactor::TemplatedPath.new(input_file, refactor_name, output_template_path).generate
|
155
150
|
raise "Output template could not be used" unless path.length.positive?
|
156
151
|
path
|
157
152
|
end
|
@@ -6,10 +6,10 @@ The output file path is: __{{output_file_path}}__
|
|
6
6
|
|
7
7
|
__{{prompt_header}}__
|
8
8
|
|
9
|
-
Only show me the test file code. Do NOT provide any other description of your work. Always enclose the output code in triple backticks (```).
|
10
|
-
|
11
9
|
__{{context}}__
|
12
10
|
|
11
|
+
Only show me the test file code. Do NOT provide any other description of your work. Always enclose the output code in triple backticks (```).
|
12
|
+
|
13
13
|
__{{prompt_footer}}__
|
14
14
|
|
15
15
|
The class to test is:
|
@@ -19,9 +19,9 @@ module AIRefactor
|
|
19
19
|
|
20
20
|
logger.verbose "Generated #{output_file_path} from #{input_file} ..." if output_content
|
21
21
|
|
22
|
-
minitest_runner = AIRefactor::TestRunners::MinitestRunner.new(output_file_path, command_template:
|
22
|
+
minitest_runner = AIRefactor::TestRunners::MinitestRunner.new(output_file_path, command_template: options.minitest_run_command)
|
23
23
|
|
24
|
-
logger.verbose "Run generated test file #{output_file_path} (
|
24
|
+
logger.verbose "Run generated test file #{output_file_path} (`#{minitest_runner.command}`)..."
|
25
25
|
test_run = minitest_runner.run
|
26
26
|
|
27
27
|
if test_run.failed?
|
@@ -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
|
data/lib/ai_refactor/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ai_refactor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Ierodiaconou
|
@@ -120,6 +120,7 @@ files:
|
|
120
120
|
- lib/ai_refactor/refactors/ruby/write_ruby.md
|
121
121
|
- lib/ai_refactor/refactors/ruby/write_ruby.rb
|
122
122
|
- lib/ai_refactor/run_configuration.rb
|
123
|
+
- lib/ai_refactor/templated_path.rb
|
123
124
|
- lib/ai_refactor/test_runners/minitest_runner.rb
|
124
125
|
- lib/ai_refactor/test_runners/rspec_runner.rb
|
125
126
|
- lib/ai_refactor/test_runners/test_run_diff_report.rb
|