diff --git a/src/helpers.js b/src/helpers.js index d6b6540e..3fcbfbb2 100644 --- a/src/helpers.js +++ b/src/helpers.js @@ -250,13 +250,15 @@ const findPrInQueue = async ({ const getWatchers = (match) => { let watchers = ''; - if (match && Array.isArray(match.attachments)) { + const attachments = (match?.attachments ?? []).filter(Boolean); + + if (attachments.length) { const { fields } = - match.attachments.filter(Boolean).find((data = {}) => { + attachments.find((data = {}) => { return get(data, 'title').includes(WATCHERS_TITLE); }) || {}; if (fields) { - watchers = `\n${fields[0].value}`; + watchers = `\n${fields?.[0]?.value}`; } } diff --git a/src/modes/init.js b/src/modes/init.js index b48f5d24..7ffd9fbc 100644 --- a/src/modes/init.js +++ b/src/modes/init.js @@ -66,7 +66,7 @@ async function initRole({ }, }); - const attachments = + const builtAttachments = (await buildAttachment({ comments: commentArr, client, @@ -74,6 +74,8 @@ async function initRole({ usernames, })) || []; + const attachments = builtAttachments.filter(Boolean); + const eventAction = payload.action.toLowerCase(); const oldAttachments = get(match, 'attachments', []); const watchersChanged = getWatchers(match) !== getWatchers({ attachments }); @@ -105,6 +107,9 @@ async function initRole({ core.info(`Trigger found. adding PR to queue:\n`); const text = getMessage(payload); + + core.info(`Message:\n${text}`); + const result = await client.chat.postMessage({ ...chatOptions, channel: channel.id, @@ -112,6 +117,7 @@ async function initRole({ mrkdwn: true, attachments, }); + core.info(JSON.stringify(result, null, 2)); setActionStatus(STATUS.ADDED_TO_QUEUE);