@@ -131,6 +131,36 @@ export async function run() {
131131 core . setFailed (
132132 `There ${ allInvalidWorkItems . length === 1 ? 'is' : 'are' } ${ allInvalidWorkItems . length } work item${ allInvalidWorkItems . length === 1 ? '' : 's' } that ${ allInvalidWorkItems . length === 1 ? 'does' : 'do' } not exist in Azure DevOps`
133133 ) ;
134+ } else if ( commentOnFailure && validateWorkItemExistsFlag ) {
135+ // All work items are valid - check if there's an existing invalid work item comment to update to success
136+ const { owner, repo } = context . repo ;
137+ const comments = await octokit . paginate ( octokit . rest . issues . listComments , {
138+ owner,
139+ repo,
140+ issue_number : pullNumber
141+ } ) ;
142+
143+ const existingInvalidWorkItemComment = comments . find ( comment =>
144+ comment . body ?. includes ( COMMENT_MARKERS . INVALID_WORK_ITEMS )
145+ ) ;
146+
147+ if ( existingInvalidWorkItemComment ) {
148+ console . log ( `Found existing invalid work item comment: ${ existingInvalidWorkItemComment . id } ` ) ;
149+ const currentDateTime = new Date ( ) . toISOString ( ) . replace ( 'T' , ' ' ) . substring ( 0 , 19 ) ;
150+ const commentExtra = `\n\n<details>\n<summary>Workflow run details</summary>\n\n[View workflow run](${ context . payload . repository ?. html_url } /actions/runs/${ context . runId } ) - _Last ran: ${ currentDateTime } UTC_</details>` ;
151+ const successCommentCombined =
152+ `${ COMMENT_MARKERS . INVALID_WORK_ITEMS } \n:white_check_mark: All work items referenced in this pull request now exist in Azure DevOps.` +
153+ commentExtra ;
154+
155+ console . log ( '... attempting to update the invalid work item comment to success' ) ;
156+ await octokit . rest . issues . updateComment ( {
157+ owner,
158+ repo,
159+ comment_id : existingInvalidWorkItemComment . id ,
160+ body : successCommentCombined
161+ } ) ;
162+ console . log ( '... invalid work item comment updated to success' ) ;
163+ }
134164 }
135165 } catch ( error ) {
136166 core . setFailed ( `Action failed with error: ${ error } ` ) ;
@@ -306,36 +336,8 @@ async function checkCommitsForWorkItems(
306336 return { workItemToCommitMap, invalidWorkItems, hasCommitFailures : false } ;
307337 }
308338
309- // All work items are valid - check if there's an existing invalid work item comment to update
310- if ( commentOnFailure ) {
311- const comments = await octokit . paginate ( octokit . rest . issues . listComments , {
312- owner,
313- repo,
314- issue_number : pullNumber
315- } ) ;
316-
317- const existingInvalidWorkItemComment = comments . find ( comment =>
318- comment . body ?. includes ( COMMENT_MARKERS . INVALID_WORK_ITEMS )
319- ) ;
320-
321- if ( existingInvalidWorkItemComment ) {
322- console . log ( `Found existing invalid work item comment: ${ existingInvalidWorkItemComment . id } ` ) ;
323- const currentDateTime = new Date ( ) . toISOString ( ) . replace ( 'T' , ' ' ) . substring ( 0 , 19 ) ;
324- const commentExtra = `\n\n<details>\n<summary>Workflow run details</summary>\n\n[View workflow run](${ context . payload . repository ?. html_url } /actions/runs/${ context . runId } ) - _Last ran: ${ currentDateTime } UTC_</details>` ;
325- const successCommentCombined =
326- `${ COMMENT_MARKERS . INVALID_WORK_ITEMS } \n:white_check_mark: All work items referenced in this pull request now exist in Azure DevOps.` +
327- commentExtra ;
328-
329- console . log ( '... attempting to update the invalid work item comment to success' ) ;
330- await octokit . rest . issues . updateComment ( {
331- owner,
332- repo,
333- comment_id : existingInvalidWorkItemComment . id ,
334- body : successCommentCombined
335- } ) ;
336- console . log ( '... invalid work item comment updated to success' ) ;
337- }
338- }
339+ // All commit work items are valid - return empty array
340+ // (Don't update success comment here - let caller handle it after checking PR too)
339341 }
340342
341343 // Link work items to PR if enabled (after deduplication)
0 commit comments