@@ -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 ( / \* \* A c t i o n : \* \* ( .+ ) / ) ?. [ 1 ] ;
82+ const existingComment = comment . body . match ( / \* \* C o m m e n t : \* \* ( .+ ) / ) ?. [ 1 ] ;
83+ const existingUser = comment . body . match ( / \* \* U s e r : \* \* ( .+ ) / ) ?. [ 1 ] ;
84+ const existingDate = comment . body . match ( / \* \* D a t e : \* \* ( .+ ) / ) ?. [ 1 ] ;
85+
86+ const expectedAction = expectedComment . match ( / \* \* A c t i o n : \* \* ( .+ ) / ) ?. [ 1 ] ;
87+ const expectedCommentText = expectedComment . match ( / \* \* C o m m e n t : \* \* ( .+ ) / ) ?. [ 1 ] ;
88+ const expectedUser = expectedComment . match ( / \* \* U s e r : \* \* ( .+ ) / ) ?. [ 1 ] ;
89+ const expectedDate = expectedComment . match ( / \* \* D a t e : \* \* ( .+ ) / ) ?. [ 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