Skip to content

Commit

Permalink
fix: separate flags for review and configure
Browse files Browse the repository at this point in the history
  • Loading branch information
lizacullis committed Aug 3, 2023
1 parent c149613 commit 5cb8b69
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,11 @@ Run `code-review-gpt` in the root directory of a git repository.

### Options

- `--ci` - Runs the application in CI mode. This will use the BASE_SHA and GITHUB_SHA environment variables to determine which files to review. It will also use the GITHUB_TOKEN environment variable to create a comment on the pull request with the review results.
- `--ci` - Used with the `review` command. Options are --ci=("github" | "gitlab"). Defaults to "github" if no option is specified. Runs the application in CI mode. This will use the BASE_SHA and GITHUB_SHA environment variables to determine which files to review. It will also use the GITHUB_TOKEN environment variable to create a comment on the pull request with the review results. Can run the review command locally, without setting the `--ci` flag, to get the bot to comment on any staged changes.

- `--commentPerFile` - Used when the `--ci` flag is set. It enables the bot to comment the feedback on a file-by-file basis. Defaults to false.
- `--commentPerFile` - Used when the `--ci` flag is set. Defaults to false. It enables the bot to comment the feedback on a file-by-file basis.

- `--setupTarget` - Used with the `configure` command. Options are --setupTarget=("github" | "gitlab"). Defaults to "github" if no option is specified. Specifies for which platform ('github' or 'gitlab') the project should be configured for.

- `--model` - The model to use for the review. Defaults to `gpt-4`. You can use any openai model you have access to.

Expand Down
10 changes: 9 additions & 1 deletion src/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ export const getYargs = async (): Promise<ReviewArgs> => {
const argv = yargs
.option("ci", {
description:
"Indicates that the script is running on a CI environment. Specify which platform the scrip is running on, 'github' or 'gitlab'.",
"Indicates that the script is running on a CI environment. Specifies which platform the script is running on, 'github' or 'gitlab'. Defaults to 'github'.",
choices: ["github", "gitlab"],
type: "string",
coerce: (arg) => {
return arg || "github";
},
})
.option("setupTarget", {
description: "Specifies for which platform ('github' or 'gitlab') the project should be configured for. Defaults to 'github'.",
choices: ["github", "gitlab"],
type: "string",
default: "github",
Expand Down
1 change: 1 addition & 0 deletions src/common/types/ReviewArgs.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export interface ReviewArgs {
[x: string]: unknown;
ci: string;
setupTarget: string,
commentPerFile: boolean;
model: string;
_: (string | number)[];
Expand Down
8 changes: 4 additions & 4 deletions src/configure/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import { GITHUB, GITLAB } from "../common/constants";
import { ReviewArgs } from "../common/types";

export const configure = async (yargs: ReviewArgs) => {
if (yargs.ci === GITHUB) {
if (yargs.setupTarget === GITHUB) {
configureGitHub();
}
if (yargs.ci === GITLAB) {
if (yargs.setupTarget === GITLAB) {
configureGitLab();
}
};
Expand Down Expand Up @@ -92,11 +92,11 @@ const configureGitLab = async () => {
execSync(`glab auth login`, { stdio: "inherit" });
execSync(`glab variable set OPENAI_API_KEY ${apiKey}`);
logger.info(
"Successfully added the OPENAI_API_KEY secret to your GitHub repository."
"Successfully added the OPENAI_API_KEY secret to your GitLab repository."
);
} catch (error) {
logger.error(
"It seems that the GitLab CLI is not installed or there was an error during authentication. Don't forget to add the OPENAI_API_KEY to the repo settings/Environment/Actions/Repository Secrets manually."
"It seems that the GitLab CLI is not installed or there was an error during authentication. Don't forget to add the OPENAI_API_KEY to the repo's CI/CD Variables manually."
);
}
};
6 changes: 1 addition & 5 deletions src/review/llm/askAI.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { openAIApiKey } from "../../config";
import AIModel from "../../common/model/AIModel";
import {
createSummary,
processFeedbacks,
} from "./feedbackProcessor";
import { createSummary, processFeedbacks } from "./feedbackProcessor";
import { generateMarkdownReport } from "./generateMarkdownReport";
import { logger } from "../../common/utils/logger";
import { AskAIResponse } from "../../common/types";
Expand All @@ -28,7 +25,6 @@ export const askAI = async (
`Filename: ${feedback.fileName}, logafScore: ${feedback.logafScore}, details: ${feedback.details}\n`
)}`
);

const summary = await createSummary(model, feedbacks);

logger.debug(`Summary of feedbacks: ${summary}`);
Expand Down

0 comments on commit 5cb8b69

Please sign in to comment.