diff --git a/github-actions/utils/find-linked-issue.js b/github-actions/utils/find-linked-issue.js index b44e54d56f..3700ce2e6f 100644 --- a/github-actions/utils/find-linked-issue.js +++ b/github-actions/utils/find-linked-issue.js @@ -1,3 +1,8 @@ +/** + * Function that returns the number of a linked issue (if exists) + * @param {String} text - the text to search for keywords + * @returns - issueNumber, or false + */ function findLinkedIssue(text) { // Create RegEx for capturing KEYWORD #ISSUE-NUMBER syntax (i.e. resolves #1234) const KEYWORDS = ['close', 'closes', 'closed', 'fix', 'fixes', 'fixed', 'resolve', 'resolves', 'resolved']; @@ -8,10 +13,17 @@ function findLinkedIssue(text) { // Receive and unpack matches into an Array of Array objs let re = new RegExp(reArr.join('|'), 'gi'); - let matches = text.matchAll(re); - matches = [...matches]; - - // If only one match is found, return the issue number. Else return false. Also console.log results. + let matches = []; + + // Find matches or throw error + try { + matches = text.matchAll(re); + matches = [...matches]; + } catch (err) { + console.error(err); + } + + // If only one match is found, return the issue number if (matches.length == 1) { const issueNumber = matches[0][0].match(/\d+/); return issueNumber[0];