Skip to content

Commit 8b1ece3

Browse files
committed
add MAX_PATCH_LENGTH
1 parent cc48506 commit 8b1ece3

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

action/index.cjs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -148133,7 +148133,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
148133148133
exports.robot = void 0;
148134148134
const chat_js_1 = __nccwpck_require__(85365);
148135148135
const OPENAI_API_KEY = 'OPENAI_API_KEY';
148136-
const MAX_PATCH_COUNT = 4000;
148136+
const MAX_PATCH_COUNT = process.env.MAX_PATCH_LENGTH
148137+
? +process.env.MAX_PATCH_LENGTH
148138+
: Infinity;
148137148139
const robot = (app) => {
148138148140
const loadChat = async (context) => {
148139148141
if (process.env.OPENAI_API_KEY) {
@@ -148196,9 +148198,12 @@ const robot = (app) => {
148196148198
base: commits[commits.length - 2].sha,
148197148199
head: commits[commits.length - 1].sha,
148198148200
});
148199-
const ignoreList = (process.env.IGNORE || process.env.ignore || '').split('\n').filter(v => v !== '');
148201+
const ignoreList = (process.env.IGNORE || process.env.ignore || '')
148202+
.split('\n')
148203+
.filter((v) => v !== '');
148200148204
const filesNames = files?.map((file) => file.filename) || [];
148201-
changedFiles = changedFiles?.filter((file) => filesNames.includes(file.filename) && !ignoreList.includes(file.filename));
148205+
changedFiles = changedFiles?.filter((file) => filesNames.includes(file.filename) &&
148206+
!ignoreList.includes(file.filename));
148202148207
}
148203148208
if (!changedFiles?.length) {
148204148209
console.log('no target label attached');
@@ -148215,17 +148220,22 @@ const robot = (app) => {
148215148220
console.log(`${file.filename} skipped caused by its diff is too large`);
148216148221
continue;
148217148222
}
148218-
const res = await chat?.codeReview(patch);
148219-
if (!!res) {
148220-
await context.octokit.pulls.createReviewComment({
148221-
repo: repo.repo,
148222-
owner: repo.owner,
148223-
pull_number: context.pullRequest().pull_number,
148224-
commit_id: commits[commits.length - 1].sha,
148225-
path: file.filename,
148226-
body: res,
148227-
position: patch.split('\n').length - 1,
148228-
});
148223+
try {
148224+
const res = await chat?.codeReview(patch);
148225+
if (!!res) {
148226+
await context.octokit.pulls.createReviewComment({
148227+
repo: repo.repo,
148228+
owner: repo.owner,
148229+
pull_number: context.pullRequest().pull_number,
148230+
commit_id: commits[commits.length - 1].sha,
148231+
path: file.filename,
148232+
body: res,
148233+
position: patch.split('\n').length - 1,
148234+
});
148235+
}
148236+
}
148237+
catch (e) {
148238+
console.error(`review ${file.filename} failed`, e);
148229148239
}
148230148240
}
148231148241
console.timeEnd('gpt cost');

0 commit comments

Comments
 (0)