Added more logging and validation. [review]

This commit is contained in:
Jimmy Royer 2024-09-19 17:08:31 -04:00
parent 4677946e97
commit 1565f8f40e
3 changed files with 27 additions and 7 deletions

15
dist/index.js vendored
View file

@ -468,11 +468,16 @@ ${chunk.changes
*/
function createReviewComment(owner, repo, pull_number, comments) {
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({
owner,
repo,
pull_number,
comments,
comments: validComments,
event: "COMMENT",
});
});
@ -535,8 +540,6 @@ ${chunk.changes
)
);
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);
if (!prDetails) {
console.log(
@ -582,6 +585,12 @@ ${chunk.changes
const filteredDiff = filterDiffs(parsedDiff);
const comments = yield analyzeCode(filteredDiff, prDetails);
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(
prDetails.owner,
prDetails.repo,

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -378,11 +378,17 @@ async function createReviewComment(
pull_number: number,
comments: Array<{ body: string; path: string; line: number }>
): 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({
owner,
repo,
pull_number,
comments,
comments: validComments,
event: "COMMENT",
});
}
@ -432,8 +438,6 @@ async function main() {
readFileSync(process.env.GITHUB_EVENT_PATH ?? "", "utf8")
);
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);
if (!prDetails) {
@ -482,6 +486,13 @@ async function main() {
const comments = await analyzeCode(filteredDiff, prDetails);
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(
prDetails.owner,
prDetails.repo,