From 81097f1f0b64618a3c51f90ec54d37178fdc8213 Mon Sep 17 00:00:00 2001 From: Manon Faour Date: Mon, 7 Aug 2023 12:48:47 +0100 Subject: [PATCH 1/2] fix: exit when there is no file to review --- src/common/git/getFilesWithChanges.ts | 7 +++++-- src/review/index.ts | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/common/git/getFilesWithChanges.ts b/src/common/git/getFilesWithChanges.ts index b58adb21..0a5a8c68 100644 --- a/src/common/git/getFilesWithChanges.ts +++ b/src/common/git/getFilesWithChanges.ts @@ -1,5 +1,7 @@ import { readFile } from "fs/promises"; +import { exit } from "process"; import { ReviewFile } from "../types"; +import { logger } from "../utils/logger"; import { getChangedFileLines } from "./getChangedFileLines"; import { getChangedFilesNames } from "./getChangedFilesNames"; @@ -10,9 +12,10 @@ export const getFilesWithChanges = async ( const fileNames = await getChangedFilesNames(isCi); if (fileNames.length === 0) { - throw new Error( - "No files with changes found, please stage your changes." + logger.warn( + "No files with changes found, you might need to stage your changes." ); + exit(); } const files = await Promise.all( diff --git a/src/review/index.ts b/src/review/index.ts index 6067f975..b0e845d2 100644 --- a/src/review/index.ts +++ b/src/review/index.ts @@ -1,3 +1,4 @@ +import { exit } from "process"; import { commentOnPR as commentOnPRGithub } from "../common/ci/github/commentOnPR"; import { commentPerFile } from "../common/ci/github/commentPerFile"; import { commentOnPR as commentOnPRGitlab } from "../common/ci/gitlab/commentOnPR"; @@ -22,6 +23,12 @@ export const review = async (yargs: ReviewArgs, files: ReviewFile[]) => { const reviewType = yargs.reviewType; const filteredFiles = filterFiles(files); + + if (filteredFiles.length == 0) { + logger.info("No file to review, exiting now."); + exit(); + } + logger.debug( `Files to review after filtering: ${filteredFiles.map( (file) => file.fileName From 9bb81400132a8c7c06057c559bdab3e1b354bf81 Mon Sep 17 00:00:00 2001 From: Manon Faour Date: Mon, 7 Aug 2023 12:54:14 +0100 Subject: [PATCH 2/2] fix: explicit exit code and return in review index --- src/common/git/getFilesWithChanges.ts | 2 +- src/review/index.ts | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/common/git/getFilesWithChanges.ts b/src/common/git/getFilesWithChanges.ts index 0a5a8c68..e70812e2 100644 --- a/src/common/git/getFilesWithChanges.ts +++ b/src/common/git/getFilesWithChanges.ts @@ -15,7 +15,7 @@ export const getFilesWithChanges = async ( logger.warn( "No files with changes found, you might need to stage your changes." ); - exit(); + exit(0); } const files = await Promise.all( diff --git a/src/review/index.ts b/src/review/index.ts index b0e845d2..45c74bff 100644 --- a/src/review/index.ts +++ b/src/review/index.ts @@ -10,7 +10,10 @@ import { askAI } from "./llm/askAI"; import { constructPromptsArray } from "./prompt/constructPrompt/constructPrompt"; import { filterFiles } from "./prompt/filterFiles"; -export const review = async (yargs: ReviewArgs, files: ReviewFile[]) => { +export const review = async ( + yargs: ReviewArgs, + files: ReviewFile[] +): Promise => { logger.debug(`Review started.`); logger.debug(`Model used: ${yargs.model}`); logger.debug(`Ci enabled: ${yargs.ci}`); @@ -25,8 +28,8 @@ export const review = async (yargs: ReviewArgs, files: ReviewFile[]) => { const filteredFiles = filterFiles(files); if (filteredFiles.length == 0) { - logger.info("No file to review, exiting now."); - exit(); + logger.info("No file to review, finishing review now."); + return; } logger.debug(