Improve legacy matching and comment dedupe

This commit is contained in:
Arunavo Ray
2026-02-24 10:48:40 +05:30
parent 85b1867490
commit cb7510f79d

View File

@@ -1915,6 +1915,17 @@ export const mirrorGitRepoIssuesToGitea = async ({
console.log( console.log(
`[Issues] Matched legacy issue by title for #${issue.number}; converting to marker-based title` `[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; commentsPage += 1;
} }
const mirroredCommentIds = new Set<number>(); const mirroredCommentIds = new Set<number>();
const existingCommentBodies = new Set<string>();
for (const existingComment of existingComments) { for (const existingComment of existingComments) {
const body = String(existingComment.body || "");
if (body) existingCommentBodies.add(body);
const marker = String(existingComment.body || "").match( const marker = String(existingComment.body || "").match(
/<!--\s*gh-comment-id:(\d+)\s*-->/i /<!--\s*gh-comment-id:(\d+)\s*-->/i
); );
@@ -2025,11 +2039,16 @@ export const mirrorGitRepoIssuesToGitea = async ({
const commentHeader = `@${commenter} commented on GitHub${ const commentHeader = `@${commenter} commented on GitHub${
commentDate ? ` (${commentDate})` : "" commentDate ? ` (${commentDate})` : ""
}:`; }:`;
const legacyBody = `${commentHeader}\n\n${comment.body ?? ""}`;
const markedBody = `<!-- gh-comment-id:${comment.id} -->\n${legacyBody}`;
if (existingCommentBodies.has(legacyBody) || existingCommentBodies.has(markedBody)) {
return comment;
}
await httpPost( await httpPost(
`${config.giteaConfig!.url}/api/v1/repos/${giteaOwner}/${repoName}/issues/${targetIssueNumber}/comments`, `${config.giteaConfig!.url}/api/v1/repos/${giteaOwner}/${repoName}/issues/${targetIssueNumber}/comments`,
{ {
body: `<!-- gh-comment-id:${comment.id} -->\n${commentHeader}\n\n${comment.body ?? ""}`, body: markedBody,
}, },
{ {
Authorization: `token ${decryptedConfig.giteaConfig!.token}`, Authorization: `token ${decryptedConfig.giteaConfig!.token}`,