Skip to content

Commit

Permalink
Merge pull request #188 from gentlementlegen/fix/link-credit
Browse files Browse the repository at this point in the history
fix: unique link credits
  • Loading branch information
gentlementlegen authored Nov 26, 2024
2 parents 9831cdf + 90a648b commit 74efe55
Show file tree
Hide file tree
Showing 13 changed files with 1,449 additions and 1,178 deletions.
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/configuration/formatting-evaluator-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const commentType = stringLiteralUnion(
);

export const wordRegex = /\b\w+\b/;
export const urlRegex = /https?:\/\/\S+/g;

const htmlEntity = Type.Object({
score: Type.Number(),
Expand Down
2 changes: 1 addition & 1 deletion src/parser/content-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export class ContentEvaluatorModule extends BaseModule {
);

if (Object.keys(relevancesByAi).length !== commentsToEvaluate.length + prCommentsToEvaluate.length) {
throw this.context.logger.fatal("Relevance / Comment length mismatch!", {
throw this.context.logger.error("Relevance / Comment length mismatch!", {
relevancesByAi,
commentsToEvaluate,
prCommentsToEvaluate,
Expand Down
2 changes: 2 additions & 0 deletions src/parser/data-purge-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export class DataPurgeModule extends BaseModule {
.replace(/^\/.+/g, "")
// Remove HTML comments
.replace(/<!--[\s\S]*?-->/g, "")
// Remove the footnotes
.replace(/^###### .*?\[\^\d+\^][\s\S]*$/gm, "")
// Keep only one new line needed by markdown-it package to convert to html
.replace(/\n\s*\n/g, "\n")
.trim();
Expand Down
23 changes: 21 additions & 2 deletions src/parser/formatting-evaluator-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { commentEnum, CommentType } from "../configuration/comment-types";
import {
FormattingEvaluatorConfiguration,
formattingEvaluatorConfigurationType,
urlRegex,
wordRegex,
} from "../configuration/formatting-evaluator-config";
import { IssueActivity } from "../issue-activity";
Expand Down Expand Up @@ -151,6 +152,7 @@ export class FormattingEvaluatorModule extends BaseModule {
_classifyTagsWithWordCount(htmlElement: HTMLElement, commentType: GithubCommentScore["type"]) {
const formatting: Record<string, { score: number; elementCount: number }> = {};
const elements = htmlElement.getElementsByTagName("*");
const urlSet = new Set<string>();

for (const element of elements) {
const tagName = element.tagName.toLowerCase();
Expand All @@ -168,9 +170,26 @@ export class FormattingEvaluatorModule extends BaseModule {
element.remove();
continue;
}
this._updateTagCount(formatting, tagName, score);
if (tagName === "a") {
const url = element.getAttribute("href");
if (url) {
urlSet.add(url.split(/[#?]/)[0]);
}
} else {
const bodyContent = element.textContent;
const matches = bodyContent?.match(urlRegex);
matches?.map((url) => url.split(/[#?]/)[0]).forEach((url) => urlSet.add(url));
this._updateTagCount(formatting, tagName, score);
}
}
const words = this._countWordsFromRegex(htmlElement.textContent ?? "", this._multipliers[commentType]?.wordValue);
urlSet.forEach(() => {
this._updateTagCount(formatting, "a", this._multipliers[commentType].html["a"].score ?? 0);
});
const words = this._countWordsFromRegex(
htmlElement.textContent?.replace(urlRegex, "") ?? "",
this._multipliers[commentType]?.wordValue
);

return { formatting, words };
}

Expand Down
Loading

0 comments on commit 74efe55

Please sign in to comment.