Skip to content

Commit e0a0e1b

Browse files
committed
feat: PR 리뷰 프로세스 개선을 위한 패치 없는 파일에 대한 코멘트 생략 및 오류 로깅 강화
1 parent 934f1f5 commit e0a0e1b

2 files changed

Lines changed: 50 additions & 4 deletions

File tree

action/index.cjs

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150670,6 +150670,7 @@ const robot = (app) => {
150670150670
}
150671150671
// Fetch PR-wide file patches to compute accurate review comment positions
150672150672
let prFilePatchByPath = new Map();
150673+
let commentablePaths = new Set();
150673150674
try {
150674150675
const prFiles = await context.octokit.pulls.listFiles({
150675150676
owner: repo.owner,
@@ -150680,6 +150681,7 @@ const robot = (app) => {
150680150681
for (const f of prFiles.data) {
150681150682
if (f && typeof f.patch === "string") {
150682150683
prFilePatchByPath.set(f.filename, f.patch);
150684+
commentablePaths.add(f.filename);
150683150685
}
150684150686
}
150685150687
}
@@ -150716,6 +150718,10 @@ const robot = (app) => {
150716150718
continue;
150717150719
}
150718150720
if (!res.lgtm || (res.lgtm && REVIEW_ON_LGTM)) {
150721+
if (!commentablePaths.has(file.filename)) {
150722+
loglevel_1.default.info(`PR 파일에 patch가 없어 ${file.filename}에 대한 코멘트 생략`);
150723+
continue;
150724+
}
150719150725
// Compute position against the PR-wide patch to avoid misalignment
150720150726
const prWidePatch = prFilePatchByPath.get(file.filename) || patch;
150721150727
const position = firstChangedPosition(prWidePatch);
@@ -150727,7 +150733,16 @@ const robot = (app) => {
150727150733
}
150728150734
}
150729150735
catch (e) {
150730-
loglevel_1.default.info(`review ${file.filename} failed`, e);
150736+
const status = e?.status || e?.response?.status;
150737+
const data = e?.response?.data;
150738+
loglevel_1.default.error(`리뷰 실패: ${file.filename} (status=${status})`);
150739+
if (data) {
150740+
try {
150741+
loglevel_1.default.error(`GitHub API error payload: ${JSON.stringify(data, null, 2)}`);
150742+
}
150743+
catch { }
150744+
}
150745+
loglevel_1.default.error("원시 오류:", e);
150731150746
}
150732150747
}
150733150748
}
@@ -150753,6 +150768,15 @@ const robot = (app) => {
150753150768
});
150754150769
}
150755150770
catch (e) {
150771+
const status = e?.status || e?.response?.status;
150772+
const data = e?.response?.data;
150773+
loglevel_1.default.error(`리뷰 생성 실패 (status=${status})`);
150774+
if (data) {
150775+
try {
150776+
loglevel_1.default.error(`GitHub API error payload: ${JSON.stringify(data, null, 2)}`);
150777+
}
150778+
catch { }
150779+
}
150756150780
loglevel_1.default.info(`Failed to create review`, e);
150757150781
}
150758150782
console.timeEnd("gpt cost");

src/bot.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,7 @@ export const robot = (app: Probot) => {
358358

359359
// Fetch PR-wide file patches to compute accurate review comment positions
360360
let prFilePatchByPath = new Map<string, string>();
361+
let commentablePaths = new Set<string>();
361362
try {
362363
const prFiles = await context.octokit.pulls.listFiles({
363364
owner: repo.owner,
@@ -368,6 +369,7 @@ export const robot = (app: Probot) => {
368369
for (const f of prFiles.data as any[]) {
369370
if (f && typeof f.patch === "string") {
370371
prFilePatchByPath.set(f.filename, f.patch as string);
372+
commentablePaths.add(f.filename);
371373
}
372374
}
373375
} catch (e) {
@@ -414,6 +416,10 @@ export const robot = (app: Probot) => {
414416
}
415417

416418
if (!res.lgtm || (res.lgtm && REVIEW_ON_LGTM)) {
419+
if (!commentablePaths.has(file.filename)) {
420+
log.info(`PR 파일에 patch가 없어 ${file.filename}에 대한 코멘트 생략`);
421+
continue;
422+
}
417423
// Compute position against the PR-wide patch to avoid misalignment
418424
const prWidePatch = prFilePatchByPath.get(file.filename) || patch;
419425
const position = firstChangedPosition(prWidePatch);
@@ -423,8 +429,16 @@ export const robot = (app: Probot) => {
423429
position,
424430
});
425431
}
426-
} catch (e) {
427-
log.info(`review ${file.filename} failed`, e);
432+
} catch (e: any) {
433+
const status = e?.status || e?.response?.status;
434+
const data = e?.response?.data;
435+
log.error(`리뷰 실패: ${file.filename} (status=${status})`);
436+
if (data) {
437+
try {
438+
log.error(`GitHub API error payload: ${JSON.stringify(data, null, 2)}`);
439+
} catch {}
440+
}
441+
log.error("원시 오류:", e);
428442
}
429443
}
430444
}
@@ -450,7 +464,15 @@ export const robot = (app: Probot) => {
450464
commit_id: commits[commits.length - 1].sha,
451465
comments: ress,
452466
});
453-
} catch (e) {
467+
} catch (e: any) {
468+
const status = e?.status || e?.response?.status;
469+
const data = e?.response?.data;
470+
log.error(`리뷰 생성 실패 (status=${status})`);
471+
if (data) {
472+
try {
473+
log.error(`GitHub API error payload: ${JSON.stringify(data, null, 2)}`);
474+
} catch {}
475+
}
454476
log.info(`Failed to create review`, e);
455477
}
456478

0 commit comments

Comments
 (0)