Skip to content

Commit

Permalink
chore: added type check for module configurations
Browse files Browse the repository at this point in the history
  • Loading branch information
gentlementlegen committed Mar 25, 2024
1 parent 60a96b1 commit ba43476
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/parser/content-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { encodingForModel } from "js-tiktoken";
import OpenAI from "openai";
import configuration from "../configuration/config-reader";
import { OPENAI_API_KEY } from "../configuration/constants";
import { ContentEvaluatorConfiguration } from "../configuration/content-evaluator-config";
import contentEvaluatorConfig, { ContentEvaluatorConfiguration } from "../configuration/content-evaluator-config";
import { IssueActivity } from "../issue-activity";
import { GithubCommentScore, Module, Result } from "./processor";
import { Value } from "@sinclair/typebox/value";

/**
* Evaluates and rates comments.
Expand All @@ -15,6 +16,10 @@ export class ContentEvaluatorModule implements Module {
readonly _configuration: ContentEvaluatorConfiguration = configuration.contentEvaluator;

get enabled(): boolean {
if (!Value.Check(contentEvaluatorConfig, this._configuration)) {
console.warn("Invalid configuration detected for ContentEvaluatorModule, disabling.");
return false;
}
return this._configuration.enabled;
}

Expand Down
9 changes: 8 additions & 1 deletion src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { Value } from "@sinclair/typebox/value";
import Decimal from "decimal.js";
import { JSDOM } from "jsdom";
import MarkdownIt from "markdown-it";
import configuration from "../configuration/config-reader";
import { FormattingEvaluatorConfiguration } from "../configuration/formatting-evaluator-config";
import formattingEvaluatorConfig, {
FormattingEvaluatorConfiguration,
} from "../configuration/formatting-evaluator-config";
import { CommentType, IssueActivity } from "../issue-activity";
import { GithubCommentScore, Module, Result } from "./processor";

Expand Down Expand Up @@ -65,6 +68,10 @@ export class FormattingEvaluatorModule implements Module {
}

get enabled(): boolean {
if (!Value.Check(formattingEvaluatorConfig, this._configuration)) {
console.warn("Invalid configuration detected for FormattingEvaluatorModule, disabling.");
return false;
}
return this._configuration?.enabled;
}

Expand Down
9 changes: 7 additions & 2 deletions src/parser/user-extractor-module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Value } from "@sinclair/typebox/value";
import configuration from "../configuration/config-reader";
import { UserExtractorConfiguration } from "../configuration/user-extractor-config";
import { IssueActivity } from "../issue-activity";
import userExtractorConfig, { UserExtractorConfiguration } from "../configuration/user-extractor-config";
import { GitHubIssue } from "../github-types";
import { IssueActivity } from "../issue-activity";
import { Module, Result } from "./processor";

/**
Expand All @@ -11,6 +12,10 @@ export class UserExtractorModule implements Module {
private readonly _configuration: UserExtractorConfiguration = configuration.userExtractor;

get enabled(): boolean {
if (!Value.Check(userExtractorConfig, this._configuration)) {
console.warn("Invalid configuration detected for UserExtractorModule, disabling.");
return false;
}
return true;
}

Expand Down

0 comments on commit ba43476

Please sign in to comment.