pr_ai_gen 0.1.1 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +37 -0
- data/lib/pull_request_ai_generator.rb +46 -7
- data/pr_ai_gen.gemspec +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: f4f268ae0b385a4fa49eeceaef9162bb365312e4fdbe0d10e2d7d4f524eeb7ba
|
4
|
+
data.tar.gz: af463bc198f734340918e3111218256c8f10ed5d0da04619b3d903d2190f66e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc5fe7e238c9ee8277f74568b2e8cc3cba953b4dc4f95d6de559b5da547e93f7a4828e2f1d7a6ca4d73f23be09ece3b42e1df66ef5a9538f2b4bd5e851347d2e
|
7
|
+
data.tar.gz: 2c9eb8d5dbd3806a6132521e98f80cd4334c3d3ec879b094eef8fef67f347f8127fb912851b10a8343276ec8a33307319db488f098cc492742e2652e8d1f1133
|
data/README.md
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# pr_ai_gen
|
2
|
+
|
3
|
+
## Description
|
4
|
+
|
5
|
+
pr_ai_gen is a CLI tool that acelerate the process of creating pull requests by Generate the PR description in markdown format.
|
6
|
+
It uses OpenAI to generate the content based on the differences between the two git branches beeing merged.
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Install the gem by running:
|
11
|
+
|
12
|
+
```bash
|
13
|
+
gem install pr_ai_gen
|
14
|
+
```
|
15
|
+
|
16
|
+
### Setup
|
17
|
+
|
18
|
+
```bash
|
19
|
+
pr_ai_gen init
|
20
|
+
```
|
21
|
+
The tool will ask you to input the OPENAI_TOKEN to make the ChatGPT calls. If you don't have one, please generate one [here](https://platform.openai.com/api-keys).
|
22
|
+
After input the token if you want to change it you can change it in `~/.pr_gem/credentials`.
|
23
|
+
|
24
|
+
### Usage
|
25
|
+
|
26
|
+
When the setup is already done you will be good to use the tool.
|
27
|
+
|
28
|
+
Commands:
|
29
|
+
- `generate <directory_location> <branch>:<target-branch=main>`: Generate the PR description based on diff from the branch and target-branch (default main)
|
30
|
+
|
31
|
+
## Development
|
32
|
+
|
33
|
+
To develop you must:
|
34
|
+
1. make the script in exe directory executable
|
35
|
+
`chmod -x ./exe/pr_ai_gen`
|
36
|
+
2. run the script directly as it is the cli tool
|
37
|
+
`./exe/pr_ai_gen generate <directory_location> <branch>:<target-branch=main>`
|
@@ -14,6 +14,7 @@ class PullRequestAIGenerator
|
|
14
14
|
@diff = nil
|
15
15
|
@pr_content = nil
|
16
16
|
@git_repo = nil
|
17
|
+
@config = nil
|
17
18
|
end
|
18
19
|
|
19
20
|
def init
|
@@ -28,13 +29,41 @@ class PullRequestAIGenerator
|
|
28
29
|
|
29
30
|
if File.exist?(credentials_path)
|
30
31
|
puts 'Credentials file already exists!'
|
31
|
-
|
32
|
+
else
|
33
|
+
puts 'Please enter your OpenAI API key:'
|
34
|
+
openai_token = STDIN.gets.chomp
|
35
|
+
File.write(credentials_path, "OPENAI_TOKEN=#{openai_token}\n")
|
36
|
+
puts 'Credentials file created successfully!'
|
37
|
+
end
|
38
|
+
|
39
|
+
puts 'Configuring ChatGPT integration'
|
40
|
+
puts 'Please choose the OpenAI API model:'
|
41
|
+
puts '1. gpt-4-turbo-preview'
|
42
|
+
puts '2. gpt-4'
|
43
|
+
puts '3. gpt-3.5-turbo'
|
44
|
+
|
45
|
+
model = nil
|
46
|
+
while model.nil?
|
47
|
+
case STDIN.gets.chomp
|
48
|
+
when '1'
|
49
|
+
model = 'gpt-4-turbo-preview'
|
50
|
+
when '2'
|
51
|
+
model = 'gpt-4'
|
52
|
+
when '3'
|
53
|
+
model = 'gpt-3.5-turbo'
|
54
|
+
else
|
55
|
+
puts 'Invalid model! Please choose a valid model:'
|
56
|
+
end
|
32
57
|
end
|
33
58
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
59
|
+
config = {
|
60
|
+
openai: {
|
61
|
+
model: model,
|
62
|
+
max_tokens: 1024
|
63
|
+
}
|
64
|
+
}
|
65
|
+
|
66
|
+
File.write(File.join(pr_gem_path, 'config.yml'), config.to_yaml)
|
38
67
|
end
|
39
68
|
|
40
69
|
def run
|
@@ -42,6 +71,7 @@ class PullRequestAIGenerator
|
|
42
71
|
fetch_diff
|
43
72
|
load_template
|
44
73
|
get_openai_token
|
74
|
+
get_config
|
45
75
|
generate_pr_content
|
46
76
|
print_content
|
47
77
|
end
|
@@ -110,6 +140,15 @@ class PullRequestAIGenerator
|
|
110
140
|
end
|
111
141
|
end
|
112
142
|
|
143
|
+
def get_config
|
144
|
+
config_path = File.join(File.expand_path('~/.pr-gem'), 'config.yml')
|
145
|
+
if File.exist?(config_path)
|
146
|
+
@config = YAML.load_file(config_path)
|
147
|
+
else
|
148
|
+
raise "Config file not found!"
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
113
152
|
def get_openai_token
|
114
153
|
credentials_path = File.expand_path('~/.pr-gem/credentials')
|
115
154
|
if File.exist?(credentials_path)
|
@@ -132,14 +171,14 @@ class PullRequestAIGenerator
|
|
132
171
|
"Authorization" => "Bearer #{@openai_token}"
|
133
172
|
},
|
134
173
|
body: {
|
135
|
-
model:
|
174
|
+
model: @config[:openai][:model],
|
136
175
|
messages: [
|
137
176
|
{
|
138
177
|
role: "user",
|
139
178
|
content: "fill this templete:\n #{@template}\n with the following changes:\n #{@diff.to_s}"
|
140
179
|
},
|
141
180
|
],
|
142
|
-
max_tokens:
|
181
|
+
max_tokens: @config[:openai][:max_tokens]
|
143
182
|
}.to_json
|
144
183
|
)
|
145
184
|
|
data/pr_ai_gen.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pr_ai_gen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lucas Stoller
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- ".gitignore"
|
79
79
|
- Gemfile
|
80
80
|
- Gemfile.lock
|
81
|
+
- README.md
|
81
82
|
- exe/pr_ai_gen
|
82
83
|
- lib/pull_request_ai_generator.rb
|
83
84
|
- pr_ai_gen.gemspec
|