Skip to content
This repository has been archived by the owner on Sep 19, 2024. It is now read-only.

build: making ignoring of children dynamic #825

Open
wants to merge 11 commits into
base: development
Choose a base branch
from
1 change: 1 addition & 0 deletions src/configs/ubiquibot-config-default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export const DefaultConfig: MergedConfig = {
totals: {
word: 0,
},
ignore_children: ["code", "i", "em", "blockquote", "pre"],
},
},
enableAccessControl: {
Expand Down
10 changes: 5 additions & 5 deletions src/handlers/payout/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getWalletAddress } from "../../adapters/supabase";
import { getBotContext, getLogger } from "../../bindings";
import { getAllIssueComments, getAllPullRequestReviews, getIssueDescription, parseComments } from "../../helpers";
import { getLatestPullRequest, gitLinkedPrParser } from "../../helpers/parser";
import { Incentives, MarkdownItem, Payload, UserType } from "../../types";
import { Incentives, Payload, UserType } from "../../types";
import { RewardsResponse, commentParser } from "../comment";
import Decimal from "decimal.js";
import { bountyInfo } from "../wildcard";
Expand All @@ -19,7 +19,6 @@ export interface CreatorCommentResult {
user?: string | undefined;
}

const ItemsToExclude: string[] = [MarkdownItem.BlockQuote];
/**
* Incentivize the contributors based on their contribution.
* The default formula has been defined in https://github.com/ubiquity/ubiquibot/issues/272
Expand Down Expand Up @@ -79,7 +78,7 @@ export const calculateIssueConversationReward = async (calculateIncentives: Ince

for (const user of Object.keys(issueCommentsByUser)) {
const commentsByUser = issueCommentsByUser[user];
const commentsByNode = await parseComments(commentsByUser.comments, ItemsToExclude);
const commentsByNode = await parseComments(commentsByUser.comments, calculateIncentives.incentives.comment.ignore_children);
const rewardValue = calculateRewardValue(commentsByNode, calculateIncentives.incentives);
if (rewardValue.equals(0)) {
logger.info(`Skipping to generate a permit url because the reward value is 0. user: ${user}`);
Expand Down Expand Up @@ -245,8 +244,9 @@ export const calculatePullRequestReviewsReward = async (incentivesCalculation: I

for (const user of Object.keys(prReviewsByUser)) {
const commentByUser = prReviewsByUser[user];
const commentsByNode = await parseComments(commentByUser.comments, ItemsToExclude);
const commentsByNode = await parseComments(commentByUser.comments, incentivesCalculation.incentives.comment.ignore_children);
const rewardValue = calculateRewardValue(commentsByNode, incentivesCalculation.incentives);

if (rewardValue.equals(0)) {
logger.info(`calculatePullRequestReviewsReward: Skipping to generate a permit url because the reward value is 0. user: ${user}`);
continue;
Expand Down Expand Up @@ -280,7 +280,7 @@ const generatePermitForComments = async (
paymentPermitMaxPrice: number
): Promise<undefined | { account: string; amountInETH: Decimal }> => {
const logger = getLogger();
const commentsByNode = await parseComments(comments, ItemsToExclude);
const commentsByNode = await parseComments(comments, incentives.comment.ignore_children);
const rewardValue = calculateRewardValue(commentsByNode, incentives);
if (rewardValue.equals(0)) {
logger.info(`No reward for the user: ${user}. comments: ${JSON.stringify(commentsByNode)}, sum: ${rewardValue}`);
Expand Down
6 changes: 2 additions & 4 deletions src/helpers/comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@ type Node = {
};

const traverse = (result: Record<string, string[]>, node: Node, itemsToExclude: string[]): Record<string, string[]> => {
if (itemsToExclude.includes(node.nodeName)) {
return result;
}
result[node.nodeName].push(node.nodeName);
GaryThisSidee marked this conversation as resolved.
Show resolved Hide resolved

if (!result[node.nodeName]) {
result[node.nodeName] = [];
}

result[node.nodeName].push(node.value?.trim() ?? "");

if (node.childNodes && node.childNodes.length > 0) {
if (node.childNodes && node.childNodes.length > 0 && !itemsToExclude.includes(node.nodeName)) {
node.childNodes.forEach((child) => traverse(result, child, itemsToExclude));
}

Expand Down
1 change: 1 addition & 0 deletions src/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const CommentIncentivesSchema = Type.Object(
},
{ additionalProperties: false }
),
ignore_children: Type.Array(Type.String()),
GaryThisSidee marked this conversation as resolved.
Show resolved Hide resolved
},
{ additionalProperties: false }
);
Expand Down
Loading