Skip to content

Commit 5428479

Browse files
authored
Use different GitHub API call to circumvent 300 file limit on PRs (#68)
1 parent 88dfdca commit 5428479

4 files changed

Lines changed: 37 additions & 30 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
# Changelog
22

3-
## v1.4.1
3+
## v1.4.2
44

55
<!--Releasenotes start-->
6-
- Fixed the default value of the `additional_lines` configuration option not being set to 1.
6+
- Fixed the app not being able to run on PRs with more than 300 changed files.
77
<!--Releasenotes end-->
88

9+
## v1.4.1
10+
11+
- Fixed the default value of the `additional_lines` configuration option not being set to 1.
12+
913
## v1.4.0
1014

1115
- Added a new `additional_lines` configuration option to control how many lines below action items are rendered in code snippets.

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ To configure options, add a `todo-pr-checker` key at the top-level of your `.git
4242
```yaml
4343
todo-pr-checker:
4444
post_comment: 'items_found'
45+
ignore_files: ['testFolder/', '*.js']
4546
(...)
4647
```
4748

app.rb

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -236,48 +236,50 @@ def get_app_options(full_repo_name, head_sha)
236236

237237
# (4) Retrieves all changes in a pull request from the GitHub API and formats them to be usable by the app
238238
def get_pull_request_changes(full_repo_name, pull_number, ignore_files_regex)
239-
diff = @installation_client.pull_request(full_repo_name, pull_number, accept: 'application/vnd.github.diff')
240-
241239
ignore_files_regex.map! do |pattern|
242240
pattern.gsub!('.', '\.')
243241
pattern.gsub!('*', '.*')
244242
pattern.gsub!('/', '\/')
245243
Regexp.new(pattern)
246244
end
247245

248-
current_file = ''
249-
line_number = 0
250246
changes = {}
251247
ignored_files = []
252248

253-
diff_enum = diff.each_line
254-
line = diff_enum.next rescue nil
249+
# Paginate through all files in the pull request
250+
page = 1
251+
per_page = 100
255252
loop do
256-
break if line.nil?
257-
258-
if line.start_with?('+++')
259-
while line&.start_with?('+++')
260-
current_file = line[6..].strip
261-
if ignore_files_regex.any? { |pattern| pattern.match?(current_file) }
262-
ignored_files << current_file
263-
loop do
264-
line = diff_enum.next rescue nil
265-
break if line.nil? || line.start_with?('+++')
266-
end
267-
else
268-
changes[current_file] = []
269-
break
253+
files = @installation_client.pull_request_files(full_repo_name, pull_number, per_page: per_page, page: page)
254+
break if files.empty?
255+
256+
files.each do |file|
257+
filename = file.filename
258+
if ignore_files_regex.any? { |pattern| pattern.match?(filename) }
259+
ignored_files << filename
260+
next
261+
end
262+
263+
changes[filename] = []
264+
# Parse the patch to get added lines and their line numbers
265+
next unless file.patch
266+
line_number = 0
267+
file.patch.each_line do |line|
268+
if line.start_with?('@@')
269+
# Extract the new file's starting line number from the hunk header
270+
# Example: @@ -1,6 +1,7 @@
271+
m = line.match(/\+([0-9]+)/)
272+
line_number = m ? m[1].to_i - 1 : line_number
273+
elsif line.start_with?('+') && !line.start_with?('+++')
274+
changes[filename] << { line: line_number, text: line[1..] }
275+
line_number += 1
276+
elsif !line.start_with?('-') && !line.chomp.eql?('\ No newline at end of file')
277+
line_number += 1
270278
end
271279
end
272-
break if line.nil?
273-
elsif line.start_with?('+')
274-
changes[current_file] << { line: line_number, text: line[1..] }
275-
elsif line.start_with?('@@')
276-
line_number = line.split()[2].split(',')[0].to_i - 1
277280
end
278281

279-
line_number += 1 unless line.start_with?('-') || line.chomp == '\ No newline at end of file'
280-
line = diff_enum.next rescue nil
282+
page += 1
281283
end
282284

283285
[changes, ignored_files]

version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# frozen_string_literal: true
22

3-
VERSION = '1.4.1'
3+
VERSION = '1.4.2'

0 commit comments

Comments
 (0)