Skip to content

Commit

Permalink
add MAX_PATCH_LENGTH
Browse files Browse the repository at this point in the history
  • Loading branch information
anc95 committed Jun 14, 2023
1 parent cc48506 commit 8b1ece3
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions action/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -148133,7 +148133,9 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.robot = void 0;
const chat_js_1 = __nccwpck_require__(85365);
const OPENAI_API_KEY = 'OPENAI_API_KEY';
const MAX_PATCH_COUNT = 4000;
const MAX_PATCH_COUNT = process.env.MAX_PATCH_LENGTH
? +process.env.MAX_PATCH_LENGTH
: Infinity;
const robot = (app) => {
const loadChat = async (context) => {
if (process.env.OPENAI_API_KEY) {
Expand Down Expand Up @@ -148196,9 +148198,12 @@ const robot = (app) => {
base: commits[commits.length - 2].sha,
head: commits[commits.length - 1].sha,
});
const ignoreList = (process.env.IGNORE || process.env.ignore || '').split('\n').filter(v => v !== '');
const ignoreList = (process.env.IGNORE || process.env.ignore || '')
.split('\n')
.filter((v) => v !== '');
const filesNames = files?.map((file) => file.filename) || [];
changedFiles = changedFiles?.filter((file) => filesNames.includes(file.filename) && !ignoreList.includes(file.filename));
changedFiles = changedFiles?.filter((file) => filesNames.includes(file.filename) &&
!ignoreList.includes(file.filename));
}
if (!changedFiles?.length) {
console.log('no target label attached');
Expand All @@ -148215,17 +148220,22 @@ const robot = (app) => {
console.log(`${file.filename} skipped caused by its diff is too large`);
continue;
}
const res = await chat?.codeReview(patch);
if (!!res) {
await context.octokit.pulls.createReviewComment({
repo: repo.repo,
owner: repo.owner,
pull_number: context.pullRequest().pull_number,
commit_id: commits[commits.length - 1].sha,
path: file.filename,
body: res,
position: patch.split('\n').length - 1,
});
try {
const res = await chat?.codeReview(patch);
if (!!res) {
await context.octokit.pulls.createReviewComment({
repo: repo.repo,
owner: repo.owner,
pull_number: context.pullRequest().pull_number,
commit_id: commits[commits.length - 1].sha,
path: file.filename,
body: res,
position: patch.split('\n').length - 1,
});
}
}
catch (e) {
console.error(`review ${file.filename} failed`, e);
}
}
console.timeEnd('gpt cost');
Expand Down

0 comments on commit 8b1ece3

Please sign in to comment.