dotcodegen 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env.example +2 -1
- data/CHANGELOG.md +4 -0
- data/README.md +7 -0
- data/lib/dotcodegen/cli.rb +8 -4
- data/lib/dotcodegen/test_code_generator.rb +6 -3
- data/lib/dotcodegen/test_file_generator.rb +7 -4
- data/lib/dotcodegen/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e41d9807ea2ec1242cf2a9b438bb0185f57d925f4cf73ee68f830551bc435850
|
4
|
+
data.tar.gz: 0b81574b9fc3a64c6405b8e4a52412cb0e4e92207ae0fa3b07116ae1864d4ef7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dd48471f5c6a8bd144d36020a633202008bffe9be2c7b6bb38a5fa1d2cae80f2949e256f7298181399521e39a051c702e8635bc827773e6840b98be30e7edd0
|
7
|
+
data.tar.gz: 7607420b9797f58b3a8c8fdffb301575ccbe8fc16c6466ac5b42d38645d126bdf3b13651d737667138d82f1e71d184e4151d9782371343119793061458ffe2d6
|
data/.env.example
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
OPENAI_KEY=your-api-key
|
1
|
+
OPENAI_KEY=your-api-key
|
2
|
+
OPENAI_ORG_ID=your-openai-org-id
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -74,6 +74,13 @@ In order to do that you can add a task to your `tasks.json` file in the `.vscode
|
|
74
74
|
|
75
75
|
We're currently building a VSCode extension to be able to generate tests directly from your editor. Stay tuned!
|
76
76
|
|
77
|
+
## Organisation Id
|
78
|
+
CLI takes an optional openai_org_id parameter. Used to specify the organisation to which the user making the API request belongs, especially in cases where the user is part of multiple organisations. This can be important for billing and access control, ensuring that the API usage is attributed to the correct organisation.
|
79
|
+
```bash
|
80
|
+
codegen path/to/the/file/you/want/to/test --openai_key <your_openai_key> --openai_org_id <your_openai_organisation_id>
|
81
|
+
```
|
82
|
+
|
83
|
+
|
77
84
|
## How it works
|
78
85
|
|
79
86
|
The extension uses AI to generate tests for any file you open in your codebase. It uses a set of customizable templates to generate the tests. You can customize the templates to fit your team's needs.
|
data/lib/dotcodegen/cli.rb
CHANGED
@@ -22,11 +22,10 @@ module Dotcodegen
|
|
22
22
|
Dotenv.load unless defined?($running_tests) && $running_tests
|
23
23
|
options = parse(args)
|
24
24
|
return version if options.version
|
25
|
-
|
26
25
|
return Init.run if options.init
|
27
26
|
|
28
27
|
matchers = load_matchers('.codegen/instructions')
|
29
|
-
TestFileGenerator.new(file_path: options.file_path, matchers:, openai_key: options.openai_key).run
|
28
|
+
TestFileGenerator.new(file_path: options.file_path, matchers:, openai_key: options.openai_key, openai_org_id: options.openai_org_id).run
|
30
29
|
end
|
31
30
|
|
32
31
|
def self.version
|
@@ -41,11 +40,12 @@ module Dotcodegen
|
|
41
40
|
end
|
42
41
|
end
|
43
42
|
|
43
|
+
# rubocop:disable Metrics/MethodLength
|
44
44
|
def self.build_option_parser(options)
|
45
45
|
OptionParser.new do |opts|
|
46
46
|
opts.banner = 'Usage: dotcodegen [options] file_path'
|
47
|
-
|
48
47
|
opts.on('--openai_key KEY', 'OpenAI API Key') { |key| options.openai_key = key }
|
48
|
+
opts.on('--openai_org_id Org_Id', 'OpenAI Organisation Id') { |key| options.openai_org_id = key }
|
49
49
|
opts.on('--init', 'Initialize a .codegen configuration in the current directory') { options.init = true }
|
50
50
|
opts.on('--version', 'Show version') { options.version = true }
|
51
51
|
opts.on_tail('-h', '--help', 'Show this message') do
|
@@ -55,21 +55,25 @@ module Dotcodegen
|
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
# rubocop:disable Metrics/AbcSize
|
58
59
|
def self.handle_arguments(args, opt_parser, options)
|
59
60
|
opt_parser.parse!(args)
|
60
61
|
return if options.version || options.init
|
61
62
|
|
62
63
|
validate_file_path(args, opt_parser)
|
63
64
|
options.file_path = args.shift
|
64
|
-
|
65
65
|
options.openai_key ||= ENV['OPENAI_KEY']
|
66
|
+
options.openai_org_id ||= ENV['OPENAI_ORG_ID']
|
66
67
|
|
67
68
|
return unless options.openai_key.to_s.strip.empty?
|
68
69
|
|
69
70
|
puts 'Error: Missing --openai_key flag or OPENAI_KEY environment variable.'
|
71
|
+
|
70
72
|
puts opt_parser
|
71
73
|
exit 1
|
72
74
|
end
|
75
|
+
# rubocop:enable Metrics/MethodLength
|
76
|
+
# rubocop:enable Metrics/AbcSize
|
73
77
|
|
74
78
|
def self.validate_file_path(args, opt_parser)
|
75
79
|
return unless args.empty?
|
@@ -5,12 +5,13 @@ require_relative 'format_output'
|
|
5
5
|
|
6
6
|
module Dotcodegen
|
7
7
|
class TestCodeGenerator
|
8
|
-
attr_reader :config, :file_to_test_path, :openai_key
|
8
|
+
attr_reader :config, :file_to_test_path, :openai_key, :openai_org_id
|
9
9
|
|
10
|
-
def initialize(config:, file_to_test_path:, openai_key:)
|
10
|
+
def initialize(config:, file_to_test_path:, openai_key:, openai_org_id: nil)
|
11
11
|
@config = config
|
12
12
|
@file_to_test_path = file_to_test_path
|
13
13
|
@openai_key = openai_key
|
14
|
+
@openai_org_id = openai_org_id
|
14
15
|
end
|
15
16
|
|
16
17
|
def generate_test_code
|
@@ -55,7 +56,9 @@ module Dotcodegen
|
|
55
56
|
end
|
56
57
|
|
57
58
|
def openai_client
|
58
|
-
|
59
|
+
client_options = { access_token: openai_key }
|
60
|
+
client_options[:organization_id] = openai_org_id unless openai_org_id.nil?
|
61
|
+
@openai_client ||= OpenAI::Client.new(client_options)
|
59
62
|
end
|
60
63
|
end
|
61
64
|
end
|
@@ -5,12 +5,13 @@ require_relative 'test_code_generator'
|
|
5
5
|
|
6
6
|
module Dotcodegen
|
7
7
|
class TestFileGenerator
|
8
|
-
attr_reader :file_path, :matchers, :openai_key
|
8
|
+
attr_reader :file_path, :matchers, :openai_key, :openai_org_id
|
9
9
|
|
10
|
-
def initialize(file_path:, matchers:, openai_key:)
|
10
|
+
def initialize(file_path:, matchers:, openai_key:, openai_org_id: nil)
|
11
11
|
@file_path = file_path
|
12
12
|
@matchers = matchers
|
13
13
|
@openai_key = openai_key
|
14
|
+
@openai_org_id = openai_org_id
|
14
15
|
end
|
15
16
|
|
16
17
|
def run
|
@@ -35,8 +36,10 @@ module Dotcodegen
|
|
35
36
|
end
|
36
37
|
|
37
38
|
def write_generated_code_to_test_file
|
38
|
-
generated_code = Dotcodegen::TestCodeGenerator.new(config: matcher,
|
39
|
-
|
39
|
+
generated_code = Dotcodegen::TestCodeGenerator.new(config: matcher,
|
40
|
+
file_to_test_path: file_path,
|
41
|
+
openai_key:,
|
42
|
+
openai_org_id:).generate_test_code
|
40
43
|
File.write(test_file_path, generated_code)
|
41
44
|
end
|
42
45
|
|
data/lib/dotcodegen/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotcodegen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ferruccio Balestreri
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03-
|
11
|
+
date: 2024-03-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|