ai_refactor 0.5.0 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- 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 +47 -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: 9ebe9a5f356fd432e2e0fdba9c96bc78ea6e5d9b8f2b98357f7a75bd1a53be35
|
4
|
+
data.tar.gz: 035fb030362ff96600eee4a57939077ae6b1d2c1c0faf2b6f2ec5cfd5c3b8570
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 764bde690ee5d65522a91e11642e830cb60a1704a20811d00ee522b33b358c36ad7a4193bf437373ce735434fad4f824ddf378ad55c83cce205eeac3311da1f5
|
7
|
+
data.tar.gz: a19722433c2ed1778a45779383a51dbeb21d0f421efc9b41510c581c96318f7b04b5914bfbea4ca155155742a573b9d3c6a3e0e75b1d0eed43b25b19d6081c62
|
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,47 @@
|
|
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
|
+
value = send(type.downcase.to_sym)
|
21
|
+
value = value.gsub(old_value, new_value) if sub
|
22
|
+
path.gsub!("[#{type}#{sub}]", value)
|
23
|
+
end
|
24
|
+
path
|
25
|
+
end
|
26
|
+
|
27
|
+
def file
|
28
|
+
File.basename(@input_file)
|
29
|
+
end
|
30
|
+
|
31
|
+
def name
|
32
|
+
File.basename(@input_file, ".*")
|
33
|
+
end
|
34
|
+
|
35
|
+
def dir
|
36
|
+
File.dirname(@input_file)
|
37
|
+
end
|
38
|
+
|
39
|
+
def refactor
|
40
|
+
@refactor_name
|
41
|
+
end
|
42
|
+
|
43
|
+
def ext
|
44
|
+
File.extname(@input_file)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
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.2
|
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
|