pr_ai_gen 0.1.0 → 0.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9d88c164cc0b3c276e43759573219cc064e5d141cd264d46e184bca12f02926b
4
- data.tar.gz: 10041eea9b1b4465539cf00d260782692f84db5ea2347b8cbe5cc2bbdd725c57
3
+ metadata.gz: f4f268ae0b385a4fa49eeceaef9162bb365312e4fdbe0d10e2d7d4f524eeb7ba
4
+ data.tar.gz: af463bc198f734340918e3111218256c8f10ed5d0da04619b3d903d2190f66e4
5
5
  SHA512:
6
- metadata.gz: dc88eee40aed632629dc2bdb1eb2fc2fa9ee5017b95a4f6c0dba9d2c9ca70d998563c020c6640766af70d57bdf6d74bf4412abe6d532730788e04e204f75d2fa
7
- data.tar.gz: 553d015be904145afab53f9dde76bf605fe12d6d875ee5341522c18f637c84879c061e777c307edef44daba0a3c84dabff949153f37c29ede5c724812b1f5dce
6
+ metadata.gz: cc5fe7e238c9ee8277f74568b2e8cc3cba953b4dc4f95d6de559b5da547e93f7a4828e2f1d7a6ca4d73f23be09ece3b42e1df66ef5a9538f2b4bd5e851347d2e
7
+ data.tar.gz: 2c9eb8d5dbd3806a6132521e98f80cd4334c3d3ec879b094eef8fef67f347f8127fb912851b10a8343276ec8a33307319db488f098cc492742e2652e8d1f1133
data/Gemfile CHANGED
@@ -2,8 +2,5 @@ source "https://rubygems.org"
2
2
 
3
3
  gem 'git'
4
4
  gem 'httparty'
5
- gem 'octokit'
6
- gem 'capybara'
7
- gem 'selenium-webdriver'
8
5
  gem 'optparse'
9
6
  gem 'pry'
data/Gemfile.lock CHANGED
@@ -3,80 +3,34 @@ GEM
3
3
  specs:
4
4
  addressable (2.8.6)
5
5
  public_suffix (>= 2.0.2, < 6.0)
6
- base64 (0.2.0)
7
- capybara (3.39.2)
8
- addressable
9
- matrix
10
- mini_mime (>= 0.1.3)
11
- nokogiri (~> 1.8)
12
- rack (>= 1.6.0)
13
- rack-test (>= 0.6.3)
14
- regexp_parser (>= 1.5, < 3.0)
15
- xpath (~> 3.2)
16
6
  coderay (1.1.3)
17
- faraday (2.8.1)
18
- base64
19
- faraday-net_http (>= 2.0, < 3.1)
20
- ruby2_keywords (>= 0.0.4)
21
- faraday-net_http (3.0.2)
22
7
  git (1.19.1)
23
8
  addressable (~> 2.8)
24
9
  rchardet (~> 1.8)
25
10
  httparty (0.20.0)
26
11
  mime-types (~> 3.0)
27
12
  multi_xml (>= 0.5.2)
28
- matrix (0.4.2)
29
13
  method_source (1.0.0)
30
14
  mime-types (3.4.1)
31
15
  mime-types-data (~> 3.2015)
32
16
  mime-types-data (3.2022.0105)
33
- mini_mime (1.1.5)
34
17
  multi_xml (0.6.0)
35
- nokogiri (1.15.5-arm64-darwin)
36
- racc (~> 1.4)
37
- nokogiri (1.15.5-x86_64-linux)
38
- racc (~> 1.4)
39
- octokit (8.1.0)
40
- base64
41
- faraday (>= 1, < 3)
42
- sawyer (~> 0.9)
43
18
  optparse (0.4.0)
44
19
  pry (0.14.1)
45
20
  coderay (~> 1.1)
46
21
  method_source (~> 1.0)
47
22
  public_suffix (5.0.4)
48
- racc (1.7.3)
49
- rack (3.0.9.1)
50
- rack-test (2.1.0)
51
- rack (>= 1.3)
52
23
  rchardet (1.8.0)
53
- regexp_parser (2.9.0)
54
- rexml (3.2.6)
55
- ruby2_keywords (0.0.5)
56
- rubyzip (2.3.2)
57
- sawyer (0.9.2)
58
- addressable (>= 2.3.5)
59
- faraday (>= 0.17.3, < 3)
60
- selenium-webdriver (4.9.0)
61
- rexml (~> 3.2, >= 3.2.5)
62
- rubyzip (>= 1.2.2, < 3.0)
63
- websocket (~> 1.0)
64
- websocket (1.2.10)
65
- xpath (3.2.0)
66
- nokogiri (~> 1.8)
67
24
 
68
25
  PLATFORMS
69
26
  arm64-darwin-22
70
27
  x86_64-linux
71
28
 
72
29
  DEPENDENCIES
73
- capybara
74
30
  git
75
31
  httparty
76
- octokit
77
32
  optparse
78
33
  pry
79
- selenium-webdriver
80
34
 
81
35
  BUNDLED WITH
82
36
  2.4.21
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>`
@@ -1,16 +1,12 @@
1
1
  require 'optparse'
2
2
  require 'git'
3
3
  require 'httparty'
4
- require 'octokit'
5
- require 'capybara/dsl'
6
4
  require 'pry'
7
5
 
8
6
  # Define the CLI class
9
7
  class PullRequestAIGenerator
10
8
  OPEN_AI_URL = "https://api.openai.com/v1"
11
9
 
12
- include Capybara::DSL
13
-
14
10
  attr_reader :options
15
11
 
16
12
  def initialize(args)
@@ -18,10 +14,11 @@ class PullRequestAIGenerator
18
14
  @diff = nil
19
15
  @pr_content = nil
20
16
  @git_repo = nil
17
+ @config = nil
21
18
  end
22
19
 
23
20
  def init
24
- puts 'Initializing pr-ai-gen...'
21
+ puts 'Initializing PR AI Generator...'
25
22
  credentials_path = File.expand_path('~/.pr-gem/credentials')
26
23
  pr_gem_path = File.expand_path('~/.pr-gem')
27
24
 
@@ -32,20 +29,49 @@ class PullRequestAIGenerator
32
29
 
33
30
  if File.exist?(credentials_path)
34
31
  puts 'Credentials file already exists!'
35
- return
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
36
57
  end
37
58
 
38
- puts 'Please enter your OpenAI API key:'
39
- openai_token = STDIN.gets.chomp
40
- File.write(credentials_path, "OPENAI_TOKEN=#{openai_token}\n")
41
- puts 'Credentials file created successfully!'
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)
42
67
  end
43
68
 
44
69
  def run
45
- puts 'Running pr-ai-gen...'
70
+ puts 'Running PR AI Generator...'
46
71
  fetch_diff
47
72
  load_template
48
73
  get_openai_token
74
+ get_config
49
75
  generate_pr_content
50
76
  print_content
51
77
  end
@@ -53,7 +79,17 @@ class PullRequestAIGenerator
53
79
  private
54
80
 
55
81
  def parse_options(args)
56
- options = { target_branch: 'main', directory_location: File.expand_path("."), command: :run }
82
+ OptionParser.new do |opts|
83
+ opts.banner = "Usage: pr_ai_gen generate <directory_location> <branch>:<target-branch=main>"
84
+
85
+ opts.on("-h", "--help", "Prints this help") do
86
+ puts opts
87
+ exit
88
+ end
89
+
90
+ end.parse!(args)
91
+
92
+ options = { target_branch: 'main', directory_location: File.expand_path("."), command: :run }
57
93
 
58
94
  if args[0] == 'init'
59
95
  options[:command] = :init
@@ -73,16 +109,6 @@ class PullRequestAIGenerator
73
109
  raise Exception.new "Invalid command!"
74
110
  end
75
111
 
76
- OptionParser.new do |opts|
77
- opts.banner = "Usage: pr-ai-gen <directory_location> <branch>:<target-branch=main>"
78
-
79
- opts.on("-h", "--help", "Prints this help") do
80
- puts opts
81
- exit
82
- end
83
-
84
- end.parse!(args)
85
-
86
112
  options
87
113
  end
88
114
 
@@ -114,6 +140,15 @@ class PullRequestAIGenerator
114
140
  end
115
141
  end
116
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
+
117
152
  def get_openai_token
118
153
  credentials_path = File.expand_path('~/.pr-gem/credentials')
119
154
  if File.exist?(credentials_path)
@@ -136,14 +171,14 @@ class PullRequestAIGenerator
136
171
  "Authorization" => "Bearer #{@openai_token}"
137
172
  },
138
173
  body: {
139
- model: "gpt-4-turbo-preview",
174
+ model: @config[:openai][:model],
140
175
  messages: [
141
176
  {
142
177
  role: "user",
143
178
  content: "fill this templete:\n #{@template}\n with the following changes:\n #{@diff.to_s}"
144
179
  },
145
180
  ],
146
- max_tokens: 1024
181
+ max_tokens: @config[:openai][:max_tokens]
147
182
  }.to_json
148
183
  )
149
184
 
data/pr_ai_gen.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = "pr_ai_gen"
3
- spec.version = "0.1.0"
3
+ spec.version = "0.2.0"
4
4
  spec.authors = ["Lucas Stoller"]
5
5
  spec.email = ["l.s.stoller@gmail.com"]
6
6
  spec.summary = "A CLI tool to generate pull requests using OpenAI"
@@ -9,15 +9,11 @@ Gem::Specification.new do |spec|
9
9
 
10
10
  spec.files = `git ls-files`.split($/)
11
11
  spec.bindir = "exe"
12
- spec.executables = spec.executables = ['pr-ai-gen']
12
+ spec.executables = spec.executables = ['pr_ai_gen']
13
13
  spec.require_paths = ["lib"]
14
14
 
15
- spec.add_dependency "git"
15
+ spec.add_dependency "git", "~> 1.19.1"
16
16
  spec.add_dependency "openai"
17
- spec.add_dependency "octokit"
18
- spec.add_dependency "capybara"
19
- spec.add_dependency "selenium-webdriver"
20
-
21
17
  spec.add_development_dependency "bundler", "~> 2.0"
22
18
  spec.add_development_dependency "rake", "~> 13.0"
23
19
  end
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lucas Stoller
@@ -14,16 +14,16 @@ dependencies:
14
14
  name: git
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 1.19.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 1.19.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: openai
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -38,48 +38,6 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- - !ruby/object:Gem::Dependency
42
- name: octokit
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: capybara
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
- - !ruby/object:Gem::Dependency
70
- name: selenium-webdriver
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- version: '0'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- version: '0'
83
41
  - !ruby/object:Gem::Dependency
84
42
  name: bundler
85
43
  requirement: !ruby/object:Gem::Requirement
@@ -113,14 +71,15 @@ description: This tool automates the process of creating pull requests by using
113
71
  email:
114
72
  - l.s.stoller@gmail.com
115
73
  executables:
116
- - pr-ai-gen
74
+ - pr_ai_gen
117
75
  extensions: []
118
76
  extra_rdoc_files: []
119
77
  files:
120
78
  - ".gitignore"
121
79
  - Gemfile
122
80
  - Gemfile.lock
123
- - exe/pr-ai-gen
81
+ - README.md
82
+ - exe/pr_ai_gen
124
83
  - lib/pull_request_ai_generator.rb
125
84
  - pr_ai_gen.gemspec
126
85
  homepage: https://theright.dev
File without changes