Skip to content

Commit

Permalink
fix: filter attachments array
Browse files Browse the repository at this point in the history
  • Loading branch information
lwhiteley committed Aug 9, 2024
1 parent f55afc0 commit 1e1b465
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
}

Expand Down
8 changes: 7 additions & 1 deletion src/modes/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,16 @@ async function initRole({
},
});

const attachments =
const builtAttachments =
(await buildAttachment({
comments: commentArr,
client,
channel,
usernames,
})) || [];

const attachments = builtAttachments.filter(Boolean);

const eventAction = payload.action.toLowerCase();
const oldAttachments = get(match, 'attachments', []);
const watchersChanged = getWatchers(match) !== getWatchers({ attachments });
Expand Down Expand Up @@ -105,13 +107,17 @@ 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,
text,
mrkdwn: true,
attachments,
});

core.info(JSON.stringify(result, null, 2));

setActionStatus(STATUS.ADDED_TO_QUEUE);
Expand Down

0 comments on commit 1e1b465

Please sign in to comment.