diff --git a/github-actions/utils/issue-template-parser.js b/github-actions/utils/issue-template-parser.js index 7c8228dfbe..604d782a41 100644 --- a/github-actions/utils/issue-template-parser.js +++ b/github-actions/utils/issue-template-parser.js @@ -10,39 +10,28 @@ const fs = require('fs'); function issueTemplateParser(filepath) { - // Read contents of issue template - let templateData = fs.readFileSync(filepath, 'utf8'); - let data = templateData.split('---'); - - // Parse "frontMatter" i.e. between '---' delimiters and "body" after - const frontMatterKeys = ['name','title','labels','milestone','assignees']; - let frontMatter = data[1].trim().split('\r\n'); - let body = data[2].trim(); - console.log('body is next'); - console.log(body); - // Extract values only from "frontMatter", remove colons, quote marks, whitespace - function removeWords(words, strings) { - for (let i = 0; i < words.length; i ++) { - for (let j = 0; j < strings.length; j ++) { - if (strings[j].includes(words[i])) { - strings[j] = strings[j].replace(words[i] + ':','').replaceAll(/["']/g, '').trim(); - } - } - } - return strings; - } + const templateData = fs.readFileSync(filepath, 'utf8'); + const data = templateData.split('---'); - // Package and return template values in array - let issueValues = removeWords(frontMatterKeys, frontMatter); - issueValues = issueValues[0].split('\n'); - issueValues[3] = issueValues[3].split(', '); - issueValues[4] = parseInt(issueValues[4]); - console.log(issueValues); - issueValues.push(body); + // Parse front matter i.e. between '---' delimiters + const frontMatter = data[1].trim().split('\r\n'); + const issueObject = frontMatter.reduce((acc, item) => { + const colonIndex = item.indexOf(':'); + const key = item.slice(0, colonIndex).trim(); + const value = item.slice(colonIndex + 1).trim(); + if (value.startsWith('[') && value.endsWith(']')) { + acc[key] = value.slice(1, -1).split(',').map(str => str.trim()); + } else { + acc[key] = value; + } + return acc; + }, {}); - console.log(issueValues); - return issueValues + issueObject['body'] = data[2].trim(); + console.log('inside issue-template-parser'); + console.log(issueObject); + return issueObject } module.exports = issueTemplateParser;