Skip to content

Commit

Permalink
Update retrieve-label-directory.js
Browse files Browse the repository at this point in the history
  • Loading branch information
t-will-gillis authored Oct 3, 2024
1 parent 72f7f1b commit 42f58e8
Showing 1 changed file with 62 additions and 27 deletions.
89 changes: 62 additions & 27 deletions github-actions/utils/retrieve-label-directory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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;

0 comments on commit 42f58e8

Please sign in to comment.