prreview 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5f2f069cb89df983a3f80577654a74fbafdf49d419a03f21ec1a2118d7cfa1c3
4
+ data.tar.gz: e55dc7c94887fa7f351b65f6ffa1fc50e9645635a3dac40bb83b3c69b9d75a8a
5
+ SHA512:
6
+ metadata.gz: 70f1ff5e19ad21774e7314ef3d2c262e1f0807dd3a0d8c47c254f24bad4ab03ab225c0aaf6898b34ea4634dc72f2a8ca72cf943962472100bf32e7ec2ac07484
7
+ data.tar.gz: c03dc8a2def91204b92d47d74a3fb1b4b10558c83e8f396e19e69edab2a77165ea2d61c75189c0ca511728a0747bbcd4fc902f51a8db381e6deea4fe39fc84b7
data/.rubocop.yml ADDED
@@ -0,0 +1,29 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Metrics/AbcSize:
5
+ Enabled: false
6
+
7
+ Metrics/BlockLength:
8
+ Enabled: false
9
+
10
+ Metrics/ClassLength:
11
+ Enabled: false
12
+
13
+ Metrics/MethodLength:
14
+ Enabled: false
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Layout/LineLength:
20
+ Enabled: false
21
+
22
+ Metrics/CyclomaticComplexity:
23
+ Enabled: false
24
+
25
+ Metrics/ParameterLists:
26
+ Enabled: false
27
+
28
+ Naming/MethodParameterName:
29
+ Enabled: false
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.4.1
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Evgenii Morozov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ ## How to use
2
+
3
+ Run this command with a PR URL:
4
+
5
+ ```sh
6
+ bundle exec ruby prreview.rb --help
7
+ bundle exec ruby prreview.rb -u https://github.com/evmorov/prreview/pull/2
8
+ bundle exec ruby prreview.rb --url https://github.com/evmorov/prreview/pull/2 --all-content --prompt "Are there any security issues?"
9
+ ```
10
+
11
+ Now, just paste the PR details into ChatGPT, Claude, or any LLM for review.
12
+
13
+ ## What it does
14
+
15
+ PrReview collects key details about a PR, including:
16
+
17
+ - PR description, commits, and comments
18
+ - Linked issues
19
+ - Changed files and their content
20
+ - The full PR diff
21
+
22
+ It then copies everything to your clipboard.
23
+
24
+ ## Requirements
25
+
26
+ - Ruby
27
+ - `GITHUB_TOKEN` environment variable
28
+
29
+ ## License
30
+
31
+ MIT License
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/exe/prreview ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Add the lib directory to the load path
5
+ lib_path = File.expand_path('../lib', __dir__)
6
+ $LOAD_PATH.unshift(lib_path) unless $LOAD_PATH.include?(lib_path)
7
+
8
+ require 'prreview'
9
+
10
+ Prreview::CLI.new.process
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Prreview
4
+ VERSION = '0.1.0'
5
+ end
data/lib/prreview.rb ADDED
@@ -0,0 +1,218 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'prreview/version'
4
+
5
+ require 'base64'
6
+ require 'clipboard'
7
+ require 'nokogiri'
8
+ require 'octokit'
9
+ require 'optparse'
10
+
11
+ module Prreview
12
+ class CLI
13
+ DEFAULT_PROMPT = 'Your task is to review this pull request. Do you see any problems there?'
14
+ DEFAULT_ISSUES_LIMIT = 10
15
+
16
+ # url or owner/repo#123 or #123
17
+ URL_REGEX = %r{
18
+ https?://github\.com/
19
+ (?<owner>[\w.-]+) /
20
+ (?<repo>[\w.-]+) /
21
+ (?:pull|issues) /
22
+ (?<number>\d+)
23
+ |
24
+ (?:
25
+ (?<owner>[\w.-]+) /
26
+ (?<repo>[\w.-]+)
27
+ )?
28
+ \#
29
+ (?<number>\d+)
30
+ }x
31
+
32
+ def initialize
33
+ parse_options!
34
+ parse_url!
35
+ initialize_client
36
+ end
37
+
38
+ def process
39
+ fetch_pull_request
40
+ fetch_issues
41
+ build_xml
42
+ copy_result_to_clipboard
43
+ end
44
+
45
+ private
46
+
47
+ def parse_options!
48
+ @prompt = DEFAULT_PROMPT
49
+ @include_content = false
50
+ @issues_limit = DEFAULT_ISSUES_LIMIT
51
+
52
+ parser = OptionParser.new do |opts|
53
+ opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} -u URL [options]"
54
+
55
+ opts.on('-u', '--url URL', 'Pull‑request URL (https://github.com/owner/repo/pull/1)') { |v| @url = v }
56
+ opts.on('-p', '--prompt PROMPT', 'Custom LLM prompt') { |v| @prompt = v }
57
+ opts.on('-a', '--all-content', 'Include full file contents') { @include_content = true }
58
+ opts.on('-l', '--limit LIMIT', Integer, "Limit number of issues fetched (default: #{DEFAULT_ISSUES_LIMIT})") { |v| @issues_limit = v }
59
+ opts.on('-h', '--help', 'Show help') do
60
+ puts opts
61
+ exit
62
+ end
63
+ end
64
+
65
+ parser.parse!
66
+ end
67
+
68
+ def parse_url!
69
+ abort 'Error: Pull-request URL missing. Use -u or --url.' if @url.to_s.empty?
70
+
71
+ match = @url.match(URL_REGEX)
72
+ abort 'Error: Invalid URL format. See --help for usage.' unless match
73
+
74
+ @owner = match[:owner]
75
+ @repo = match[:repo]
76
+ @pr_number = match[:number].to_i
77
+ @full_repo = "#{@owner}/#{@repo}"
78
+ end
79
+
80
+ def initialize_client
81
+ access_token = ENV.fetch('GITHUB_TOKEN', nil)
82
+ abort 'Error: GITHUB_TOKEN is not set' if access_token.to_s.empty?
83
+
84
+ @client = Octokit::Client.new(access_token:, auto_paginate: true)
85
+ rescue Octokit::Unauthorized
86
+ abort 'Error: Invalid GITHUB_TOKEN'
87
+ end
88
+
89
+ def fetch_pull_request
90
+ puts "Fetching PR ##{@pr_number} for #{@full_repo}"
91
+
92
+ @pull_request = @client.pull_request(@full_repo, @pr_number)
93
+ @comments = @client.issue_comments(@full_repo, @pr_number).map(&:body)
94
+ @commits = @client.pull_request_commits(@full_repo, @pr_number).map { |c| c.commit.message }
95
+ @files = @client.pull_request_files(@full_repo, @pr_number).map do |file|
96
+ {
97
+ filename: file.filename,
98
+ patch: file.patch || '(no patch data)',
99
+ content: @include_content ? fetch_file_content(file.filename) : '(no content)'
100
+ }
101
+ end
102
+ end
103
+
104
+ def fetch_file_content(path)
105
+ puts "Fetching file content for #{path}"
106
+
107
+ content = @client.contents(@full_repo, path:, ref: @pull_request.head.sha)
108
+ Base64.decode64(content[:content])
109
+ rescue Octokit::NotFound
110
+ '(file content not found)'
111
+ end
112
+
113
+ def fetch_issues
114
+ @issues = []
115
+
116
+ text = [@pull_request.body, *@comments].join("\n")
117
+ queue = extract_refs(text, URL_REGEX)
118
+ seen = Set.new
119
+
120
+ until queue.empty? || @issues.length >= @issues_limit
121
+ ref = queue.shift
122
+ key = ref[:key]
123
+ next if seen.include?(key)
124
+
125
+ seen << key
126
+
127
+ issue = fetch_issue(ref)
128
+ next unless issue
129
+
130
+ @issues << issue
131
+
132
+ new_text = [issue[:description], *issue[:comments]].join("\n")
133
+ new_refs = extract_refs(new_text, URL_REGEX).reject { |nref| seen.include?(nref[:key]) }
134
+ queue.concat(new_refs)
135
+ end
136
+
137
+ puts "Fetched #{@issues.length} issues (limit: #{@issues_limit})"
138
+ end
139
+
140
+ def extract_refs(text, pattern)
141
+ text.to_enum(:scan, pattern).filter_map do
142
+ m = Regexp.last_match
143
+ next unless m[:number]
144
+
145
+ {
146
+ owner: m[:owner] || @owner,
147
+ repo: m[:repo] || @repo,
148
+ number: m[:number].to_i,
149
+ key: "#{m[:owner]}/#{m[:repo]}##{m[:number]}"
150
+ }
151
+ end
152
+ end
153
+
154
+ def fetch_issue(ref)
155
+ full_repo = "#{ref[:owner]}/#{ref[:repo]}"
156
+ number = ref[:number]
157
+
158
+ puts "Fetching issue ##{number} for #{full_repo}"
159
+
160
+ issue = @client.issue(full_repo, number)
161
+ {
162
+ full_repo:,
163
+ number:,
164
+ title: issue.title,
165
+ description: issue.body,
166
+ comments: @client.issue_comments(full_repo, number).map(&:body)
167
+ }
168
+ rescue Octokit::NotFound
169
+ puts "Issue #{number} for #{full_repo} not found, skipping"
170
+ nil
171
+ end
172
+
173
+ def build_xml
174
+ builder = Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |x|
175
+ x.prompt do
176
+ x.task @prompt
177
+
178
+ x.pull_request do
179
+ x.number @pr_number
180
+ x.title @pull_request.title
181
+ x.description @pull_request.body
182
+
183
+ @comments.each { |c| x.comment_ c }
184
+ @commits.each { |m| x.commit m }
185
+
186
+ @files.each do |file|
187
+ x.file do
188
+ x.filename file[:filename]
189
+ x.content file[:content]
190
+ x.patch file[:patch]
191
+ end
192
+ end
193
+ end
194
+
195
+ @issues.each do |issue|
196
+ x.issue do
197
+ x.repo issue[:full_repo]
198
+ x.number issue[:number]
199
+ x.title issue[:title]
200
+ x.description issue[:description]
201
+
202
+ issue[:comments].each { |c| x.comment_ c }
203
+ end
204
+ end
205
+
206
+ x.task @prompt
207
+ end
208
+ end
209
+
210
+ @xml = builder.doc.root.to_xml
211
+ end
212
+
213
+ def copy_result_to_clipboard
214
+ Clipboard.copy(@xml)
215
+ puts 'XML prompt generated and copied to clipboard.'
216
+ end
217
+ end
218
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: prreview
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Evgenii Morozov
8
+ - Iurii Alekseev
9
+ - Quint
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2025-05-14 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: base64
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: '0.2'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: '0.2'
28
+ - !ruby/object:Gem::Dependency
29
+ name: clipboard
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.0'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.0'
42
+ - !ruby/object:Gem::Dependency
43
+ name: faraday-retry
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.3'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.3'
56
+ - !ruby/object:Gem::Dependency
57
+ name: nokogiri
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: '1.18'
63
+ type: :runtime
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: '1.18'
70
+ - !ruby/object:Gem::Dependency
71
+ name: octokit
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '10.0'
77
+ type: :runtime
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '10.0'
84
+ description: PrReview collects PR data from GitHub (description, commits, comments,
85
+ linked issues, and code changes) and formats it as XML. Paste this XML into any
86
+ LLM like ChatGPT or Claude to get helpful code reviews.
87
+ email:
88
+ - evmorov@gmail.com
89
+ - iurii.alekseev.inbox@gmail.com
90
+ - quintgorssel@gmail.com
91
+ executables:
92
+ - prreview
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".rubocop.yml"
97
+ - ".ruby-version"
98
+ - LICENSE
99
+ - README.md
100
+ - Rakefile
101
+ - exe/prreview
102
+ - lib/prreview.rb
103
+ - lib/prreview/version.rb
104
+ homepage: https://github.com/evmorov/prreview
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ source_code_uri: https://github.com/evmorov/prreview
109
+ rubygems_mfa_required: 'true'
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: 3.1.0
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubygems_version: 3.6.2
125
+ specification_version: 4
126
+ summary: A CLI tool that formats GitHub PRs for LLM code reviews.
127
+ test_files: []