Skip to content

Commit

Permalink
fix: ensure values are safely read
Browse files Browse the repository at this point in the history
  • Loading branch information
lwhiteley committed Aug 1, 2024
1 parent 2622e9f commit 5c2ee42
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ const getHistory = async ({

hasMore = hasReachedThreshold ? false : has_more;
cursor = response_metadata.next_cursor;
const mergeQueueMessages = messages.filter(({ text }) =>
const mergeQueueMessages = (messages || []).filter(({ text }) =>
text.startsWith(SEARCH_PREFIX),
);
mergeQueueMessages.forEach(({ text }) => {
Expand Down Expand Up @@ -239,7 +239,7 @@ const findPrInQueue = async ({
});

return findLast(matches, (message, ...args) => {
const { text } = message;
const { text } = message || {};
const { issueNumber: num } = parseTag(text);
return (
num.trim() === issueNumber.toString() && filter(message, ...args, matches)
Expand Down
2 changes: 1 addition & 1 deletion src/modes/alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ async function alert({
core.info(`issues: ${JSON.stringify(filteredIssues, null, 2)}`);

const promises = messagesToAlert.map(async (match) => {
const { text } = match;
const { text } = match || {};
const { issueNumber: num } = parseTag(text);
const prTag = `PR${num}: `;

Expand Down
2 changes: 1 addition & 1 deletion src/modes/cancel.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ async function cancel({
return setActionStatus(STATUS.NOT_FOUND);
}

const tagSections = parseTag(match.text);
const tagSections = parseTag(match?.text);
const newTag = buildTagFromParse({
...tagSections,
mergeStatus: Q_STATUS.CANCELLED,
Expand Down
2 changes: 1 addition & 1 deletion src/modes/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function initRole({
const updatedMsg = await client.chat.update({
...chatOptions,
ts: match.ts,
text: match.text,
text: match?.text,
channel: channel.id,
attachments,
});
Expand Down
4 changes: 2 additions & 2 deletions src/modes/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ async function merge({
if (nextPr) {
core.info(`next PR: \n${JSON.stringify(nextPr, null, 2)}`);

const { issueNumber: nextPrNum } = parseTag(nextPr.text);
const { issueNumber: nextPrNum } = parseTag(nextPr?.text);
core.setOutput('next_pr', nextPrNum);
const watchers = getWatchers(nextPr);

Expand All @@ -106,7 +106,7 @@ async function merge({

if (isMerged) {
const promises = older.map(async (msg) => {
const { text } = msg;
const { text } = msg || {};
const tagSections = parseTag(text);
const newTag = buildTagFromParse({
...tagSections,
Expand Down

0 comments on commit 5c2ee42

Please sign in to comment.