Skip to content

Commit

Permalink
Update issue-template-parser.js
Browse files Browse the repository at this point in the history
  • Loading branch information
t-will-gillis authored Dec 4, 2023
1 parent 5c3725b commit 8aea8f6
Showing 1 changed file with 19 additions and 30 deletions.
49 changes: 19 additions & 30 deletions github-actions/utils/issue-template-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 8aea8f6

Please sign in to comment.