Skip to content

Commit

Permalink
fix: make string split safer
Browse files Browse the repository at this point in the history
  • Loading branch information
lwhiteley committed Sep 1, 2024
1 parent 601ffcf commit ea6648b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ const buildTagFromParse = ({ searchPrefix, issueNumber, mergeStatus, url }) => {
};

const parseTag = (str) => {
const [searchPrefix, issueNumber, status, url] = str.split(DELIM.trim());
const [searchPrefix = '', issueNumber = '', status = '', url = ''] = (
str || ''
).split(DELIM.trim());
return {
searchPrefix: searchPrefix.trim(),
issueNumber: issueNumber.trim(),
Expand Down Expand Up @@ -146,13 +148,13 @@ const getUserFromName = ({ name: providedName, members }) => {
const possibleNames = [
id,
name,
get(profile, 'email', '').split('@')[0],
(profile?.email ?? '').split('@')[0],
get(profile, 'display_name'),
get(profile, 'display_name_normalized'),
real_name,
get(profile, 'real_name'),
get(profile, 'real_name_normalized'),
];
].filter(Boolean);
return possibleNames.some((x) => x === pn);
});

Expand Down Expand Up @@ -242,7 +244,8 @@ const findPrInQueue = async ({
const { text } = message || {};
const { issueNumber: num } = parseTag(text);
return (
num.trim() === issueNumber.toString() && filter(message, ...args, matches)
num?.trim() === issueNumber.toString() &&
filter(message, ...args, matches)
);
});
};
Expand Down Expand Up @@ -344,7 +347,7 @@ const buildAttachment = async ({
const getFormattedComment = ({ payload }) => {
const commentMsg =
get(payload, 'comment.body', '') || get(payload, 'review.body');
return commentMsg.split('\n').filter(Boolean);
return (commentMsg ?? '').split('\n').filter(Boolean);
};

const mergingFilter = ({ text }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ async function resolveChannel(channelId, channelName, channelTypes, teamId) {
} catch (error) {
setActionStatus(STATUS.FAILED);
core.error(error.message);
core.debug(error);
core.error(error);
}
})();

0 comments on commit ea6648b

Please sign in to comment.