From 468ea798befd213a32f96dbee2091331cc7cbac0 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:38:25 +0000 Subject: [PATCH 1/2] fix: avoid built-ins --- src/handlers/issue/comment-scoring-rubric.ts | 13 ++++++++++--- src/utils/generate-configuration.ts | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/handlers/issue/comment-scoring-rubric.ts b/src/handlers/issue/comment-scoring-rubric.ts index a8ae9c8..bdac751 100644 --- a/src/handlers/issue/comment-scoring-rubric.ts +++ b/src/handlers/issue/comment-scoring-rubric.ts @@ -159,10 +159,17 @@ export class CommentScoring { ): (typeof CommentScoring.prototype.commentScores)[number]["details"][number]["wordScoreCommentDetails"] { const wordScoreCommentDetails: { [key: string]: Decimal } = {}; + const builtIns = new Set( + Object.getOwnPropertyNames(Object.prototype).filter((name) => typeof Object.prototype[name] === "function") + ); + for (const word of words) { - let counter = wordScoreCommentDetails[word] || ZERO; - counter = counter.plus(this.roleWordScore); - wordScoreCommentDetails[word] = counter; + if (!builtIns.has(word)) { + let counter = wordScoreCommentDetails[word] || ZERO; + counter = counter.plus(this.roleWordScore); + + wordScoreCommentDetails[word] = counter; + } } return wordScoreCommentDetails; diff --git a/src/utils/generate-configuration.ts b/src/utils/generate-configuration.ts index cf198c9..81e9a5c 100644 --- a/src/utils/generate-configuration.ts +++ b/src/utils/generate-configuration.ts @@ -16,7 +16,7 @@ export async function generateConfiguration( const orgConfig = parseYaml( await download({ repository: UBIQUIBOT_CONFIG_REPOSITORY, - owner: owner, + owner, authenticatedOctokit, }) ); From c8a10b63783ad2bebacdb9a60779f95f08ef4d9c Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Thu, 14 Mar 2024 22:08:26 +0000 Subject: [PATCH 2/2] chore: add jest test case --- .../tests/scoring-rubric-built-ins.test.ts | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/handlers/tests/scoring-rubric-built-ins.test.ts diff --git a/src/handlers/tests/scoring-rubric-built-ins.test.ts b/src/handlers/tests/scoring-rubric-built-ins.test.ts new file mode 100644 index 0000000..84126c8 --- /dev/null +++ b/src/handlers/tests/scoring-rubric-built-ins.test.ts @@ -0,0 +1,35 @@ +import Decimal from "decimal.js"; + +describe("Scoring Rubric Built-ins", () => { + let wordScoreCommentDetails: { [key: string]: Decimal }; + + beforeEach(() => { + wordScoreCommentDetails = {}; + }); + + it("should increment counter for non-built-in words", () => { + const words = ["hasOwnProperty", "valueOf", "was", "async", "but", "the", "constructor", "isn", "t", "I", "was"]; + const ZERO = new Decimal(0); + + const builtIns = new Set( + Object.getOwnPropertyNames(Object.prototype).filter((name) => typeof Object.prototype[name] === "function") + ); + + for (const word of words) { + if (!builtIns.has(word)) { + const counter = wordScoreCommentDetails[word] || ZERO; + wordScoreCommentDetails[word] = counter; + } + } + + expect(wordScoreCommentDetails).toEqual({ + was: new Decimal(0), + async: new Decimal(0), + but: new Decimal(0), + the: new Decimal(0), + isn: new Decimal(0), + t: new Decimal(0), + I: new Decimal(0), + }); + }); +});