From cb7510f79ddc8422cc1a2375180adb7a8655934b Mon Sep 17 00:00:00 2001 From: Arunavo Ray Date: Tue, 24 Feb 2026 10:48:40 +0530 Subject: [PATCH] Improve legacy matching and comment dedupe --- src/lib/gitea.ts | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/lib/gitea.ts b/src/lib/gitea.ts index a581408..d05c8cf 100644 --- a/src/lib/gitea.ts +++ b/src/lib/gitea.ts @@ -1915,6 +1915,17 @@ export const mirrorGitRepoIssuesToGitea = async ({ console.log( `[Issues] Matched legacy issue by title for #${issue.number}; converting to marker-based title` ); + } else if (titleFallbackCandidates.length > 1) { + const filtered = titleFallbackCandidates.filter((candidate) => + String(candidate.body || "").startsWith(issueOriginHeader) + ); + if (filtered.length === 1) { + existingIssue = filtered[0]; + giteaIssueByGitHubNumber.set(issue.number, existingIssue); + console.log( + `[Issues] Matched legacy issue by body prefix for #${issue.number}; converting to marker-based title` + ); + } } } @@ -2004,7 +2015,10 @@ export const mirrorGitRepoIssuesToGitea = async ({ commentsPage += 1; } const mirroredCommentIds = new Set(); + const existingCommentBodies = new Set(); for (const existingComment of existingComments) { + const body = String(existingComment.body || ""); + if (body) existingCommentBodies.add(body); const marker = String(existingComment.body || "").match( //i ); @@ -2025,11 +2039,16 @@ export const mirrorGitRepoIssuesToGitea = async ({ const commentHeader = `@${commenter} commented on GitHub${ commentDate ? ` (${commentDate})` : "" }:`; + const legacyBody = `${commentHeader}\n\n${comment.body ?? ""}`; + const markedBody = `\n${legacyBody}`; + if (existingCommentBodies.has(legacyBody) || existingCommentBodies.has(markedBody)) { + return comment; + } await httpPost( `${config.giteaConfig!.url}/api/v1/repos/${giteaOwner}/${repoName}/issues/${targetIssueNumber}/comments`, { - body: `\n${commentHeader}\n\n${comment.body ?? ""}`, + body: markedBody, }, { Authorization: `token ${decryptedConfig.giteaConfig!.token}`,