This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
feat: change to markdown and map html to markdown #688
Draft
whilefoo
wants to merge
7
commits into
ubiquity:development
Choose a base branch
from
ubiquity-whilefoo:incentives-fix
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
09485ef
feat: change to markdown and map html to markdown
whilefoo b5446a8
fix: use old version of mdast libraries that can be used with require
whilefoo d00af2c
fix: markdown types
whilefoo 0b5e149
feat: html tags enum
whilefoo 9e88f65
Merge remote-tracking branch 'upstream/development' into incentives-fix
whilefoo ed023ba
feat: add config
whilefoo 8e6ddaa
Merge remote-tracking branch 'upstream/development' into incentives-fix
whilefoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
declare module "mdast-util-gfm"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,13 @@ 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, MarkdownItem, MarkdownItems, Payload, UserType } from "../../types"; | ||
import { RewardsResponse, commentParser } from "../comment"; | ||
import Decimal from "decimal.js"; | ||
import { bountyInfo } from "../wildcard"; | ||
import { IncentivesCalculationResult } from "./action"; | ||
import { BigNumber } from "ethers"; | ||
import { HTMLItem } from "../../types/html"; | ||
|
||
export interface CreatorCommentResult { | ||
title: string; | ||
|
@@ -50,16 +51,16 @@ export const calculateIssueConversationReward = async (calculateIncentives: Ince | |
logger.info(`Skipping to parse the comment because it contains commands. comment: ${JSON.stringify(issueComment)}`); | ||
continue; | ||
} | ||
if (!issueComment.body_html) { | ||
logger.info(`Skipping to parse the comment because body_html is undefined. comment: ${JSON.stringify(issueComment)}`); | ||
if (!issueComment.body) { | ||
logger.info(`Skipping to parse the comment because body is undefined. comment: ${JSON.stringify(issueComment)}`); | ||
continue; | ||
} | ||
|
||
// Store the comment along with user's login and node_id | ||
if (!issueCommentsByUser[user.login]) { | ||
issueCommentsByUser[user.login] = { id: user.id, comments: [] }; | ||
} | ||
issueCommentsByUser[user.login].comments.push(issueComment.body_html); | ||
issueCommentsByUser[user.login].comments.push(issueComment.body); | ||
} | ||
logger.info(`Filtering by the user type done. commentsByUser: ${JSON.stringify(issueCommentsByUser)}`); | ||
|
||
|
@@ -298,45 +299,80 @@ const generatePermitForComments = async ( | |
* @returns - The reward value | ||
*/ | ||
const calculateRewardValue = ( | ||
comments: Record<string, string[]>, | ||
comments: Record<MarkdownItem, string[]>, | ||
incentives: Incentives | ||
): { sum: Decimal; sumByType: Record<string, { count: number; reward: Decimal }> } => { | ||
let sum = new Decimal(0); | ||
const sumByType: Record<string, { count: number; reward: Decimal }> = {}; | ||
|
||
for (const key of Object.keys(comments)) { | ||
const value = comments[key]; | ||
for (const item of MarkdownItems) { | ||
const value = comments[item]; | ||
|
||
// Initialize the sum for this key if it doesn't exist | ||
if (!sumByType[key]) { | ||
sumByType[key] = { | ||
if (!sumByType[item]) { | ||
sumByType[item] = { | ||
count: 0, | ||
reward: new Decimal(0), | ||
}; | ||
} | ||
|
||
// if it's a text node calculate word count and multiply with the reward value | ||
if (key == "#text") { | ||
if (item === MarkdownItem.Text) { | ||
if (!incentives.comment.totals.word) { | ||
continue; | ||
} | ||
const wordReward = new Decimal(incentives.comment.totals.word); | ||
const wordCount = value.map((str) => str.trim().split(" ").length).reduce((totalWords, wordCount) => totalWords + wordCount, 0); | ||
const reward = wordReward.mul(wordCount); | ||
sumByType[key].count += wordCount; | ||
sumByType[key].reward = wordReward; | ||
sumByType[item].count += wordCount; | ||
sumByType[item].reward = wordReward; | ||
sum = sum.add(reward); | ||
} else { | ||
if (!incentives.comment.elements[key]) { | ||
const htmlTag = MarkdownItemToHTMLTag[item]; | ||
if (!htmlTag || !incentives.comment.elements[htmlTag]) { | ||
continue; | ||
} | ||
const rewardValue = new Decimal(incentives.comment.elements[key]); | ||
const rewardValue = new Decimal(incentives.comment.elements[htmlTag]); | ||
const reward = rewardValue.mul(value.length); | ||
sumByType[key].count += value.length; | ||
sumByType[key].reward = rewardValue; | ||
sumByType[item].count += value.length; | ||
sumByType[item].reward = rewardValue; | ||
sum = sum.add(reward); | ||
} | ||
} | ||
|
||
return { sum, sumByType }; | ||
}; | ||
|
||
const MarkdownItemToHTMLTag: Record<MarkdownItem, HTMLItem> = { | ||
[MarkdownItem.Text]: HTMLItem.P, | ||
[MarkdownItem.Paragraph]: HTMLItem.P, | ||
[MarkdownItem.Heading]: HTMLItem.H1, | ||
[MarkdownItem.Heading1]: HTMLItem.H1, | ||
[MarkdownItem.Heading2]: HTMLItem.H2, | ||
[MarkdownItem.Heading3]: HTMLItem.H3, | ||
[MarkdownItem.Heading4]: HTMLItem.H4, | ||
[MarkdownItem.Heading5]: HTMLItem.H5, | ||
[MarkdownItem.Heading6]: HTMLItem.H6, | ||
[MarkdownItem.ListItem]: HTMLItem.LI, | ||
[MarkdownItem.List]: HTMLItem.UL, | ||
[MarkdownItem.Link]: HTMLItem.A, | ||
[MarkdownItem.Image]: HTMLItem.IMG, | ||
[MarkdownItem.BlockQuote]: HTMLItem.BLOCKQUOTE, | ||
[MarkdownItem.Code]: HTMLItem.PRE, | ||
[MarkdownItem.Emphasis]: HTMLItem.EM, | ||
[MarkdownItem.Strong]: HTMLItem.STRONG, | ||
[MarkdownItem.Delete]: HTMLItem.DEL, | ||
[MarkdownItem.HTML]: HTMLItem.HTML, | ||
[MarkdownItem.InlineCode]: HTMLItem.CODE, | ||
[MarkdownItem.LinkReference]: HTMLItem.A, | ||
[MarkdownItem.ImageReference]: HTMLItem.IMG, | ||
[MarkdownItem.FootnoteReference]: HTMLItem.SUP, | ||
[MarkdownItem.FootnoteDefinition]: HTMLItem.P, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure how can we represent footnote reference and definition by HTML? @pavlovcik Example of footnote1 Footnotes
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Very cool. I didn't know about this but I guess we can just file an issue and kick the can down the road? |
||
[MarkdownItem.Table]: HTMLItem.TABLE, | ||
[MarkdownItem.TableCell]: HTMLItem.TD, | ||
[MarkdownItem.TableRow]: HTMLItem.TR, | ||
[MarkdownItem.ThematicBreak]: HTMLItem.HR, | ||
[MarkdownItem.Break]: HTMLItem.BR, | ||
[MarkdownItem.Root]: HTMLItem.HTML, | ||
[MarkdownItem.Definition]: HTMLItem.DL, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
export enum HTMLItem { | ||
P = "p", | ||
H1 = "h1", | ||
H2 = "h2", | ||
H3 = "h3", | ||
H4 = "h4", | ||
H5 = "h5", | ||
H6 = "h6", | ||
UL = "ul", | ||
A = "a", | ||
IMG = "img", | ||
BLOCKQUOTE = "blockquote", | ||
CODE = "code", | ||
EM = "em", | ||
STRONG = "strong", | ||
DEL = "del", | ||
HTML = "html", | ||
SUP = "sup", | ||
LI = "li", | ||
TABLE = "table", | ||
TR = "tr", | ||
TD = "td", | ||
HR = "hr", | ||
BR = "br", | ||
DL = "dl", | ||
PRE = "pre", | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if it's gonna be clear to partners that
<pre>
refers toand
<code>
refers toinline code