-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import dotenv from "dotenv"; | ||
|
||
import { getYargs } from "./args"; | ||
import { logger } from "./common/utils/logger"; | ||
import { getOpenAIApiKey } from "./config"; | ||
|
||
dotenv.config(); | ||
|
||
const main = async () => { | ||
const argv = await getYargs(); | ||
const openAIApiKey = getOpenAIApiKey(); | ||
logger.settings.minLevel = argv.debug ? 2 : argv.ci ? 4 : 3; | ||
|
||
logger.debug(`Args: ${JSON.stringify(argv)}`); | ||
|
||
switch (argv._[0]) { | ||
case "configure": { | ||
const { configure } = await import("./configure"); | ||
await configure(argv); | ||
break; | ||
} | ||
case "review": { | ||
const { review } = await import("./review"); | ||
const { getReviewFiles } = await import("./common/utils/getReviewFiles"); | ||
const files = await getReviewFiles(argv.ci, argv.remote); | ||
await review(argv, files, openAIApiKey); | ||
break; | ||
} | ||
case "test": { | ||
const { test } = await import("./test"); | ||
await test(argv, openAIApiKey); | ||
break; | ||
} | ||
default: | ||
logger.error("Unknown command"); | ||
process.exit(1); | ||
} | ||
}; | ||
|
||
main().catch((error) => { | ||
const message = | ||
error instanceof Error ? error.message : "An unknown error occurred"; | ||
const stack = | ||
error instanceof Error ? error.stack : "No stack trace available"; | ||
|
||
logger.error(`Error: ${message}`); | ||
if (stack) { | ||
logger.debug(`Stack trace: ${stack}`); | ||
} | ||
process.exit(1); | ||
}); |