Skip to content

Commit 56b4390

Browse files
committed
fix the correct comparison
1 parent 1af7cfb commit 56b4390

File tree

1 file changed

+45
-1
lines changed

1 file changed

+45
-1
lines changed

policy.js

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,55 @@ async function annotationCommentExists(options, issue_number, annotation) {
6868
console.log(expectedComment.substring(0, 200));
6969

7070
const exists = response.data.some(comment => {
71-
const matches = comment.body === expectedComment;
71+
// First try exact match
72+
let matches = comment.body === expectedComment;
73+
74+
if (!matches) {
75+
// If exact match fails, try comparing key fields for annotation comments
76+
const isAnnotationComment = comment.body.includes('**User:** Julian Totzek-Hallhuber') ||
77+
(comment.body.includes('**User:** ') && !comment.body.includes('**User:** Veracode Automation'));
78+
79+
if (isAnnotationComment) {
80+
// Extract key fields for comparison
81+
const existingAction = comment.body.match(/\*\*Action:\*\* (.+)/)?.[1];
82+
const existingComment = comment.body.match(/\*\*Comment:\*\* (.+)/)?.[1];
83+
const existingUser = comment.body.match(/\*\*User:\*\* (.+)/)?.[1];
84+
const existingDate = comment.body.match(/\*\*Date:\*\* (.+)/)?.[1];
85+
86+
const expectedAction = expectedComment.match(/\*\*Action:\*\* (.+)/)?.[1];
87+
const expectedCommentText = expectedComment.match(/\*\*Comment:\*\* (.+)/)?.[1];
88+
const expectedUser = expectedComment.match(/\*\*User:\*\* (.+)/)?.[1];
89+
const expectedDate = expectedComment.match(/\*\*Date:\*\* (.+)/)?.[1];
90+
91+
console.log(`Field comparison for ${expectedAction}:`);
92+
console.log(` Existing Action: "${existingAction}"`);
93+
console.log(` Expected Action: "${expectedAction}"`);
94+
console.log(` Existing Comment: "${existingComment}"`);
95+
console.log(` Expected Comment: "${expectedCommentText}"`);
96+
console.log(` Existing User: "${existingUser}"`);
97+
console.log(` Expected User: "${expectedUser}"`);
98+
console.log(` Existing Date: "${existingDate}"`);
99+
console.log(` Expected Date: "${expectedDate}"`);
100+
101+
// Compare key fields including annotation dates (not GitHub creation dates)
102+
matches = existingAction === expectedAction &&
103+
existingComment === expectedCommentText &&
104+
existingUser === expectedUser &&
105+
existingDate === expectedDate;
106+
107+
console.log(` Field comparison result: ${matches}`);
108+
109+
if (matches) {
110+
console.log(`Found duplicate by field comparison: ${comment.id} posted at ${comment.created_at}`);
111+
}
112+
}
113+
}
114+
72115
if (matches) {
73116
console.log(`Found duplicate comment: ${comment.id} posted at ${comment.created_at}`);
74117
console.log(`Duplicate comment body preview: ${comment.body.substring(0, 100)}...`);
75118
}
119+
76120
return matches;
77121
});
78122

0 commit comments

Comments
 (0)