From 649def769bd860512e5fce86e30aa05c8119259f Mon Sep 17 00:00:00 2001 From: Affaan Mustafa Date: Sun, 9 Aug 2026 16:44:18 -0400 Subject: [PATCH] fix: complete Discord delivery receipts reliably (#2738) * test: reproduce Actions receipt completion mismatch * fix: complete Discord receipts with Actions identity --- scripts/discord/announcement-core.mjs | 7 ++++--- scripts/discord/release-announce.mjs | 12 ++++-------- tests/scripts/release-announce.test.js | 3 ++- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/scripts/discord/announcement-core.mjs b/scripts/discord/announcement-core.mjs index d3c9e391..891f432a 100644 --- a/scripts/discord/announcement-core.mjs +++ b/scripts/discord/announcement-core.mjs @@ -72,11 +72,12 @@ export function discussionReceiptMarker(key) { } export function findDiscussionReceipt(comments, marker) { - return comments.find(comment => ( - comment?.author?.login === 'github-actions[bot]' + const trusted = comments.filter(comment => ( + ['github-actions', 'github-actions[bot]'].includes(comment?.author?.login) && typeof comment.body === 'string' && comment.body.includes(marker) - )) || null; + )); + return trusted.find(comment => discussionReceiptStatus(comment) === 'complete') || trusted[0] || null; } export function discussionReceiptStatus(comment) { diff --git a/scripts/discord/release-announce.mjs b/scripts/discord/release-announce.mjs index f03f4b58..6ac1e2f5 100644 --- a/scripts/discord/release-announce.mjs +++ b/scripts/discord/release-announce.mjs @@ -127,13 +127,6 @@ async function addReceiptComment(discussionId, body) { return data.addDiscussionComment.comment.id; } -async function updateReceiptComment(commentId, body) { - await githubGraphql( - `mutation($id:ID!,$body:String!){updateDiscussionComment(input:{commentId:$id,body:$body}){comment{id}}}`, - { id: commentId, body }, - ); -} - async function deleteReceiptComment(commentId) { await githubGraphql( `mutation($id:ID!){deleteDiscussionComment(input:{id:$id}){clientMutationId}}`, @@ -179,7 +172,10 @@ async function deliver(discussion) { throw new Error(`Discord webhook request failed (${response.status})`); } const message = await response.json(); - await updateReceiptComment(claimId, `${marker}\n\nDiscord delivery: complete (message ${message.id}).`); + await addReceiptComment(discussion.id, `${marker}\n\nDiscord delivery: complete (message ${message.id}).`); + await deleteReceiptComment(claimId).catch(() => { + console.warn('announcement delivered; pending receipt cleanup requires attention'); + }); console.log('announcement delivered by channel webhook'); return; } diff --git a/tests/scripts/release-announce.test.js b/tests/scripts/release-announce.test.js index 4e2a6fcc..a111dfef 100644 --- a/tests/scripts/release-announce.test.js +++ b/tests/scripts/release-announce.test.js @@ -52,7 +52,8 @@ const receiptMarker = discussionReceiptMarker('affaan-m/ECC:discussion:D_kw123') assert.match(receiptMarker, /^$/); assert.equal(findDiscussionReceipt([ { id: 'forged', body: `Discord delivery: complete\n${receiptMarker}`, author: { login: 'attacker' } }, - { id: 'comment-1', body: `Discord delivery: complete\n${receiptMarker}`, author: { login: 'github-actions[bot]' } }, + { id: 'pending', body: `Discord delivery: pending.\n${receiptMarker}`, author: { login: 'github-actions' } }, + { id: 'comment-1', body: `Discord delivery: complete\n${receiptMarker}`, author: { login: 'github-actions' } }, ], receiptMarker).id, 'comment-1'); assert.equal(findDiscussionReceipt([{ id: 'comment-2', body: 'unrelated' }], receiptMarker), null); assert.equal(discussionReceiptStatus({ body: `Discord delivery: pending.\n${receiptMarker}` }), 'pending');