feat: merge codeblock
This commit is contained in:
+13
-1
@@ -33,7 +33,10 @@ export function webhookMerger(app: App) {
|
||||
existing.data = merge(existing.data, body);
|
||||
existing.count++;
|
||||
|
||||
log.debug`collected ${existing}`;
|
||||
|
||||
existing.timer = setTimeout(async () => {
|
||||
log.debug`running ${existing}`;
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
@@ -58,7 +61,10 @@ export function webhookMerger(app: App) {
|
||||
timer: undefined as never,
|
||||
};
|
||||
|
||||
log.debug`collected ${state}`;
|
||||
|
||||
state.timer = setTimeout(async () => {
|
||||
log.debug`running ${state}`;
|
||||
try {
|
||||
const res = await fetch(url, {
|
||||
method: "POST",
|
||||
@@ -103,7 +109,13 @@ function merge(a: unknown, b: unknown, key?: string): unknown {
|
||||
typeof a === "string" &&
|
||||
typeof b === "string"
|
||||
) {
|
||||
return `${a}\n${b}`;
|
||||
const CODEBLOCK_MATCHER = /^([^`]+)```(?:([a-z]*)\n)?([^`]+)```\n?/m;
|
||||
const [ma, mb] = [a.match(CODEBLOCK_MATCHER), b.match(CODEBLOCK_MATCHER)];
|
||||
log.debug`${ma} ${mb}`;
|
||||
if (ma && mb && ma[1] === mb[1]) {
|
||||
return `${ma[1]}\`\`\`${ma[2] ? `${ma[2]}\n` : ""}${ma[3]}${mb[3]}\`\`\``;
|
||||
}
|
||||
return `${a}${a.endsWith("\n") || (a.endsWith("```") && !b.startsWith("`") && !b.startsWith("-# ")) ? "" : "\n"}${b}`;
|
||||
}
|
||||
|
||||
if (Array.isArray(a) && Array.isArray(b)) {
|
||||
|
||||
Reference in New Issue
Block a user