-
-
Notifications
You must be signed in to change notification settings - Fork 777
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add label key references * remove excess console.logs, match module names * full substitution of labelId values * adding omitted labels, fixing call to label dir, adjusting module * Update add-label.js changed note to `labelKeys` from `labelIds` * Update retrieve-label-directory.js Refactored non-variatic funct, renamed funct * Update retrieve-label-directory.js fix comments for singular use * Update retrieve-label-directory.js add comment first line, remove space
- Loading branch information
1 parent
1b94d5b
commit f425c4c
Showing
2 changed files
with
69 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,34 @@ | ||
// Import modules | ||
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 | ||
* Matches label reference name to the label display name from JSON | ||
* @param {Array} labelKey - Key reference to look up display name | ||
* @return {Array} labelName - Display name for each label | ||
*/ | ||
function labelRetrieveNames(...labelKeys) { | ||
function retrieveLabelName(labelKey) { | ||
|
||
// Retrieve label directory | ||
const rawData = fs.readFileSync(filepath, 'utf8'); | ||
const data = JSON.parse(rawData); | ||
// Retrieve label directory if not read already | ||
if (labelData === undefined) { | ||
console.log(`Reading label directory...`); | ||
const rawData = fs.readFileSync(filepath, 'utf8'); | ||
labelData = JSON.parse(rawData); | ||
} | ||
|
||
let labelName = ''; | ||
|
||
const displayNames = [ ]; | ||
for(let labelKey of labelKeys) { | ||
try { | ||
displayNames.push(data[labelKey][0]); | ||
console.log(`Success! From label key: '${labelKey}' found label display: '${data[labelKey][0]}'`); | ||
} catch (err) { | ||
console.error(`Failed to find label display for label key: '${labelKey}'`) | ||
} | ||
try { | ||
labelName = labelData[labelKey][0]; | ||
console.log(`Success! Found labelKey: '${labelKey}', returning labelName: '${labelName}'`); | ||
} catch (err) { | ||
console.error(`Failed to find labelKey: '${labelKey}'`); | ||
} | ||
|
||
return displayNames; | ||
return labelName; | ||
} | ||
|
||
module.exports = labelRetrieveNames; | ||
module.exports = retrieveLabelName; |