mirror of
https://github.com/affaan-m/ECC.git
synced 2026-09-13 13:17:55 +02:00
fix: complete Discord delivery receipts reliably (#2738)
* test: reproduce Actions receipt completion mismatch * fix: complete Discord receipts with Actions identity
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ const receiptMarker = discussionReceiptMarker('affaan-m/ECC:discussion:D_kw123')
|
||||
assert.match(receiptMarker, /^<!-- ecc-discord-receipt:[a-f0-9]{32} -->$/);
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user