Skip to content

Commit

Permalink
allow max files no limit option (coderabbitai#31)
Browse files Browse the repository at this point in the history
<!-- This is an auto-generated comment: release notes by openai -->
### Summary by OpenAI

**Release Notes**

This pull request adds new features to the codebase that allow users to
exclude certain files from being reviewed and specify the maximum number
of files to be reviewed. The `max_files` option has been added to
`README.md` and the default value has been changed from 30 to 40 in
`src/options.ts`. A new `exclude_paths` option has been added to
`src/review.ts` to support excluding files from review.
<!-- end of auto-generated comment: release notes by openai -->
  • Loading branch information
harjotgill committed Mar 14, 2023
1 parent 93e82ef commit 38e3691
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 18 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ See also: [./action.yml](./action.yml)

- `debug`: Enable debug mode, will show messages and responses between OpenAI
server in CI logs.
- `max_files`: Maximum number of files to be reviewed. Less than or equal to 0
means no limit.
- `review_comment_lgtm`: Leave comments even the patch is LGTM
- `path_filters`: Rules to filter files to be reviewed.
- `temperature`: Temperature of the GPT-3 model.
Expand Down
4 changes: 2 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ inputs:
default: 'false'
max_files:
required: false
description: 'Max files to review'
default: '30'
description: 'Max files to review. Less than or equal to 0 means no limit.'
default: '40'
temperature:
required: false
description: 'Temperature for GPT model'
Expand Down
23 changes: 15 additions & 8 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ export class Options {

constructor(
debug: boolean,
max_files = '30',
max_files = '40',
review_comment_lgtm = false,
path_filters: string[] | null = null,
system_message = '',
Expand Down
21 changes: 14 additions & 7 deletions src/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,19 @@ export const codeReview = async (
return
}

// check if we are exceeding max_files
if (files.length > options.max_files) {
// skip files if they are filtered out
const filtered_files = []
for (const file of files) {
if (!options.check_path(file.filename)) {
core.info(`skip for excluded path: ${file.filename}`)
continue
} else {
filtered_files.push(file)
}
}

// check if we are exceeding max_files and if max_files is <= 0 (no limit)
if (filtered_files.length > options.max_files && options.max_files > 0) {
core.warning("Skipped: too many files to review, can't handle it")
await commenter.comment(
`Skipped: too many files to review, can't handle it`,
Expand All @@ -79,11 +90,7 @@ export const codeReview = async (

// find patches to review
const files_to_review: [string, string, string, [number, string][]][] = []
for (const file of files) {
if (!options.check_path(file.filename)) {
core.info(`skip for excluded path: ${file.filename}`)
continue
}
for (const file of filtered_files) {
// retrieve file contents
let file_content = ''
try {
Expand Down

0 comments on commit 38e3691

Please sign in to comment.