Skip to content

Commit

Permalink
Merge pull request #1 from gentlementlegen/fork/test
Browse files Browse the repository at this point in the history
fix: fixing display and collection errors
  • Loading branch information
EresDev authored Aug 5, 2024
2 parents 135105d + 0917a07 commit 50a4380
Show file tree
Hide file tree
Showing 7 changed files with 562 additions and 365 deletions.
4 changes: 3 additions & 1 deletion src/data-collection/collect-linked-pulls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export async function collectLinkedMergedPulls(issue: IssueParams) {
// Works on multiple linked issues, and matches #<number> or URL patterns
const linkedIssueRegex =
/\b(?:Close(?:s|d)?|Fix(?:es|ed)?|Resolve(?:s|d)?):?\s+(?:#(\d+)|https?:\/\/(?:www\.)?github\.com\/(?:[^/\s]+\/[^/\s]+\/(?:issues|pull)\/(\d+)))\b/gi;
const linkedPrUrls = event.source.issue.body.match(linkedIssueRegex);
// We remove the comments as they should not be part of the linked pull requests
const linkedPrUrls = event.source.issue.body.replace(/<!--[\s\S]+-->/, "").match(linkedIssueRegex);
if (!linkedPrUrls) {
return false;
}
Expand All @@ -33,6 +34,7 @@ export async function collectLinkedMergedPulls(issue: IssueParams) {
linkedRepo.owner === issue.owner;
}
}
if (isClosingPr) break;
}
return isGitHubLinkEvent(event) && event.source.issue.pull_request?.merged_at && isClosingPr;
});
Expand Down
19 changes: 15 additions & 4 deletions src/parser/github-comment-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { getERC20TokenSymbol } from "../helpers/web3";
import { IssueActivity } from "../issue-activity";
import program from "./command-line";
import { GithubCommentScore, Module, Result } from "./processor";
import { JSDOM } from "jsdom";

interface SortedTasks {
issues: { specification: GithubCommentScore | null; comments: GithubCommentScore[] };
Expand All @@ -31,6 +32,16 @@ export class GithubCommentModule implements Module {
*/
private _lastCommentId: number | null = process.env.COMMENT_ID ? Number(process.env.COMMENT_ID) : null;

/**
* Ensures that a string containing special characters get HTML encoded.
*/
_encodeHTML(str: string) {
const dom = new JSDOM();
const div = dom.window.document.createElement("div");
div.appendChild(dom.window.document.createTextNode(str));
return div.innerHTML;
}

async transform(data: Readonly<IssueActivity>, result: Result): Promise<Result> {
const bodyArray: (string | undefined)[] = [];

Expand All @@ -40,8 +51,7 @@ export class GithubCommentModule implements Module {
}
// Add the workflow run url and the metadata in the GitHub's comment
bodyArray.push("\n<!--");
bodyArray.push(`\n${getGithubWorkflowRunUrl()}\n`);
bodyArray.push(JSON.stringify(result, typeReplacer, 2));
bodyArray.push(this._encodeHTML(`\n${getGithubWorkflowRunUrl()}\n${JSON.stringify(result, typeReplacer, 2)}`));
bodyArray.push("\n-->");
const body = bodyArray.join("");
if (this._configuration?.debug) {
Expand Down Expand Up @@ -153,12 +163,13 @@ export class GithubCommentModule implements Module {
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll("`", "&#96;");
.replaceAll("`", "&#96;")
.replace(/([\s\S]{64}).[\s\S]+/, "$1&hellip;");
return `
<tr>
<td>
<h6>
<a href="${commentScore.url}" target="_blank" rel="noopener">${sanitizedContent.replace(/(.{64})..+/, "$1&hellip;")}</a>
<a href="${commentScore.url}" target="_blank" rel="noopener">${sanitizedContent}</a>
</h6>
</td>
<td>
Expand Down
4 changes: 2 additions & 2 deletions src/parser/user-extractor-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ export class UserExtractorModule implements Module {
}

/**
* Checks if the comment is made by a human user, and not empty.
* Checks if the comment is made by a human user, not empty, and not a command.
*/
_checkEntryValidity(comment: (typeof IssueActivity.prototype.allComments)[0]) {
return comment.body && comment.user?.type === "User";
return comment.body && comment.user?.type === "User" && comment.body.trim()[0] !== "/";
}

/**
Expand Down
Loading

0 comments on commit 50a4380

Please sign in to comment.