mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-04-20 17:46:47 +00:00
Added more logging and validation. [review]
This commit is contained in:
parent
4677946e97
commit
1565f8f40e
3 changed files with 27 additions and 7 deletions
15
dist/index.js
vendored
15
dist/index.js
vendored
|
@ -468,11 +468,16 @@ ${chunk.changes
|
||||||
*/
|
*/
|
||||||
function createReviewComment(owner, repo, pull_number, comments) {
|
function createReviewComment(owner, repo, pull_number, comments) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const validComments = comments.filter((comment) => comment.line > 0);
|
||||||
|
if (validComments.length === 0) {
|
||||||
|
console.log("No valid comments to post.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
yield octokit.pulls.createReview({
|
yield octokit.pulls.createReview({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
pull_number,
|
pull_number,
|
||||||
comments,
|
comments: validComments,
|
||||||
event: "COMMENT",
|
event: "COMMENT",
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -535,8 +540,6 @@ ${chunk.changes
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
const eventName = process.env.GITHUB_EVENT_NAME;
|
const eventName = process.env.GITHUB_EVENT_NAME;
|
||||||
console.log("GitHub event name:", eventName);
|
|
||||||
console.log("GitHub event data:", eventData);
|
|
||||||
const prDetails = yield getPrDetails(eventName, eventData);
|
const prDetails = yield getPrDetails(eventName, eventData);
|
||||||
if (!prDetails) {
|
if (!prDetails) {
|
||||||
console.log(
|
console.log(
|
||||||
|
@ -582,6 +585,12 @@ ${chunk.changes
|
||||||
const filteredDiff = filterDiffs(parsedDiff);
|
const filteredDiff = filterDiffs(parsedDiff);
|
||||||
const comments = yield analyzeCode(filteredDiff, prDetails);
|
const comments = yield analyzeCode(filteredDiff, prDetails);
|
||||||
if (comments.length > 0) {
|
if (comments.length > 0) {
|
||||||
|
// Additional logging and validation before creating the review
|
||||||
|
comments.forEach((comment) => {
|
||||||
|
console.log(
|
||||||
|
`Comment to be posted: ${comment.body} at ${comment.path}:${comment.line}`
|
||||||
|
);
|
||||||
|
});
|
||||||
yield createReviewComment(
|
yield createReviewComment(
|
||||||
prDetails.owner,
|
prDetails.owner,
|
||||||
prDetails.repo,
|
prDetails.repo,
|
||||||
|
|
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
17
src/main.ts
17
src/main.ts
|
@ -378,11 +378,17 @@ async function createReviewComment(
|
||||||
pull_number: number,
|
pull_number: number,
|
||||||
comments: Array<{ body: string; path: string; line: number }>
|
comments: Array<{ body: string; path: string; line: number }>
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const validComments = comments.filter((comment) => comment.line > 0);
|
||||||
|
if (validComments.length === 0) {
|
||||||
|
console.log("No valid comments to post.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await octokit.pulls.createReview({
|
await octokit.pulls.createReview({
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
pull_number,
|
pull_number,
|
||||||
comments,
|
comments: validComments,
|
||||||
event: "COMMENT",
|
event: "COMMENT",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -432,8 +438,6 @@ async function main() {
|
||||||
readFileSync(process.env.GITHUB_EVENT_PATH ?? "", "utf8")
|
readFileSync(process.env.GITHUB_EVENT_PATH ?? "", "utf8")
|
||||||
);
|
);
|
||||||
const eventName = process.env.GITHUB_EVENT_NAME as GitHubEvent;
|
const eventName = process.env.GITHUB_EVENT_NAME as GitHubEvent;
|
||||||
console.log("GitHub event name:", eventName);
|
|
||||||
console.log("GitHub event data:", eventData);
|
|
||||||
|
|
||||||
const prDetails = await getPrDetails(eventName, eventData);
|
const prDetails = await getPrDetails(eventName, eventData);
|
||||||
if (!prDetails) {
|
if (!prDetails) {
|
||||||
|
@ -482,6 +486,13 @@ async function main() {
|
||||||
|
|
||||||
const comments = await analyzeCode(filteredDiff, prDetails);
|
const comments = await analyzeCode(filteredDiff, prDetails);
|
||||||
if (comments.length > 0) {
|
if (comments.length > 0) {
|
||||||
|
// Additional logging and validation before creating the review
|
||||||
|
comments.forEach((comment) => {
|
||||||
|
console.log(
|
||||||
|
`Comment to be posted: ${comment.body} at ${comment.path}:${comment.line}`
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
await createReviewComment(
|
await createReviewComment(
|
||||||
prDetails.owner,
|
prDetails.owner,
|
||||||
prDetails.repo,
|
prDetails.repo,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue