Skip to content

Commit cc48506

Browse files
committed
add MAX_PATCH_LENGTH
1 parent 1432c3f commit cc48506

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

.env.example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ temperature=
1919
top_p=
2020
max_tokens=
2121
TARGET_LABEL=
22+
MAX_PATCH_LENGTH=
2223
PROMPT=Below there is a code diff please help me do a code review

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ jobs:
6666
top_p: 1
6767
temperature: 1
6868
max_tokens: 10000
69+
MAX_PATCH_LENGTH: 10000 # if the patch/diff length is large than MAX_PATCH_LENGTH, will be ignored and won't review. By default, with no MAX_PATCH_LENGTH set, there is also no limit for the patch/diff length.
6970
```
7071
7172
## Self-hosting

src/bot.ts

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import { Context, Probot } from 'probot';
33
import { Chat } from './chat.js';
44

55
const OPENAI_API_KEY = 'OPENAI_API_KEY';
6-
const MAX_PATCH_COUNT = 4000;
6+
const MAX_PATCH_COUNT = process.env.MAX_PATCH_LENGTH
7+
? +process.env.MAX_PATCH_LENGTH
8+
: Infinity;
79

810
export const robot = (app: Probot) => {
911
const loadChat = async (context: Context) => {
@@ -90,11 +92,15 @@ export const robot = (app: Probot) => {
9092
head: commits[commits.length - 1].sha,
9193
});
9294

93-
const ignoreList = (process.env.IGNORE || process.env.ignore || '').split('\n').filter(v => v !== '');
95+
const ignoreList = (process.env.IGNORE || process.env.ignore || '')
96+
.split('\n')
97+
.filter((v) => v !== '');
9498

9599
const filesNames = files?.map((file) => file.filename) || [];
96-
changedFiles = changedFiles?.filter((file) =>
97-
filesNames.includes(file.filename) && !ignoreList.includes(file.filename)
100+
changedFiles = changedFiles?.filter(
101+
(file) =>
102+
filesNames.includes(file.filename) &&
103+
!ignoreList.includes(file.filename)
98104
);
99105
}
100106

@@ -119,18 +125,22 @@ export const robot = (app: Probot) => {
119125
);
120126
continue;
121127
}
122-
const res = await chat?.codeReview(patch);
123-
124-
if (!!res) {
125-
await context.octokit.pulls.createReviewComment({
126-
repo: repo.repo,
127-
owner: repo.owner,
128-
pull_number: context.pullRequest().pull_number,
129-
commit_id: commits[commits.length - 1].sha,
130-
path: file.filename,
131-
body: res,
132-
position: patch.split('\n').length - 1,
133-
});
128+
try {
129+
const res = await chat?.codeReview(patch);
130+
131+
if (!!res) {
132+
await context.octokit.pulls.createReviewComment({
133+
repo: repo.repo,
134+
owner: repo.owner,
135+
pull_number: context.pullRequest().pull_number,
136+
commit_id: commits[commits.length - 1].sha,
137+
path: file.filename,
138+
body: res,
139+
position: patch.split('\n').length - 1,
140+
});
141+
}
142+
} catch (e) {
143+
console.error(`review ${file.filename} failed`, e);
134144
}
135145
}
136146

0 commit comments

Comments
 (0)