diff --git a/github-actions/utils/retrieve-label-directory.js b/github-actions/utils/retrieve-label-directory.js index e027063d5d..ad3cf31471 100644 --- a/github-actions/utils/retrieve-label-directory.js +++ b/github-actions/utils/retrieve-label-directory.js @@ -2,7 +2,7 @@ const fs = require('fs'); // Global variables var filepath = 'github-actions/utils/_data/label-directory.json'; -var labelData; + /* * Matches label reference name(s) to the label display name(s) from JSON * @param {string } filepath - Path to `label_directory.json` @@ -12,39 +12,74 @@ var labelData; function labelRetrieveNames(...labelKeys) { // Retrieve label directory - if (labelData === undefined) { - console.log(`creating Label Data`); - const rawData = fs.readFileSync(filepath, 'utf8'); - labelData = JSON.parse(rawData); - } else { - console.log(`data exists`); - } - - let displayNames = ''; - for(let labelKey of labelKeys) { - console.log(labelKey); - try { - displayNames.push(labelData[labelKey][0]); - console.log(`Success! Found labelKey: '${labelKey}', returning labelName: '${labelData[labelKey][0]}'`); - } catch (err) { - console.error(`Failed to find labelKey: '${labelKey}'`) - } - } -/* - console.log(labelKeys); - let displayNames = ''; + const rawData = fs.readFileSync(filepath, 'utf8'); + const data = JSON.parse(rawData); + + const displayNames = [ ]; for(let labelKey of labelKeys) { - console.log(labelKey); try { - displayNames.push(labelData[labelKeys][0]); - console.log(`Success! Found labelKey: '${labelKey}', returning labelName: '${labelData[labelKeys][0]}'`); + displayNames.push(data[labelKey][0]); + console.log(`Success! Found labelKey: '${labelKey}', returning labelName: '${data[labelKey][0]}'`); } catch (err) { console.error(`Failed to find labelKey: '${labelKey}'`) } } - */ + return displayNames; } - module.exports = labelRetrieveNames; + + + + +// const fs = require('fs'); + +// // Global variables +// var filepath = 'github-actions/utils/_data/label-directory.json'; +// var labelData; +// /* +// * Matches label reference name(s) to the label display name(s) from JSON +// * @param {string } filepath - Path to `label_directory.json` +// * @param {Array} labelKeys - List of reference names to look up display names +// * @return {Array} displayNames - List of display names +// */ +// function labelRetrieveNames(...labelKeys) { + +// // Retrieve label directory +// if (labelData === undefined) { +// console.log(`creating Label Data`); +// const rawData = fs.readFileSync(filepath, 'utf8'); +// labelData = JSON.parse(rawData); +// } else { +// console.log(`data exists`); +// } + +// let displayNames = ''; +// for(let labelKey of labelKeys) { +// console.log(labelKey); +// try { +// displayNames.push(labelData[labelKey][0]); +// console.log(`Success! Found labelKey: '${labelKey}', returning labelName: '${labelData[labelKey][0]}'`); +// } catch (err) { +// console.error(`Failed to find labelKey: '${labelKey}'`) +// } +// } +// /* +// console.log(labelKeys); +// let displayNames = ''; +// for(let labelKey of labelKeys) { +// console.log(labelKey); +// try { +// displayNames.push(labelData[labelKeys][0]); +// console.log(`Success! Found labelKey: '${labelKey}', returning labelName: '${labelData[labelKeys][0]}'`); +// } catch (err) { +// console.error(`Failed to find labelKey: '${labelKey}'`) +// } +// } +// */ +// return displayNames; +// } + + +// module.exports = labelRetrieveNames;