Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions github-actions/utils/find-linked-issue.js
Original file line number Diff line number Diff line change
@@ -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'];
Expand All @@ -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];
Expand Down