From 21f8b0b42d95e737e60fefe8e4e83eb0cf32c136 Mon Sep 17 00:00:00 2001 From: DIBSTER <76603072+DEV-DIBSTER@users.noreply.github.com> Date: Sun, 8 Sep 2024 00:31:36 -0400 Subject: [PATCH] feat: additional check --- utils/getJSON.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/utils/getJSON.js b/utils/getJSON.js index 3829e67..e76b1c1 100644 --- a/utils/getJSON.js +++ b/utils/getJSON.js @@ -1,5 +1,5 @@ const fs = require('fs'); -const { getFileExtension } = require('./utils.js'); +const { getFileExtension, stripExt } = require('./utils.js'); const core = require('@actions/core'); function getJSON(file, filename) { @@ -14,7 +14,18 @@ function getJSON(file, filename) { // It exists const rawdata = fs.readFileSync(path); // Read the file const data = JSON.parse(rawdata); // Parse it - return data; // Return true or false, depending if tests pass or fail. + + // Extract the file name without extension + const fileNameWithoutExt = stripExt(file); + + // Validate if the file name matches any of the target.RECORD_TYPE values + const recordTypes = Object.keys(data.target); + if (!recordTypes.includes(fileNameWithoutExt.toUpperCase())) { + core.setOutput('infoMessage', `File name ${fileNameWithoutExt} does not match any target.RECORD_TYPE`); + return false; + } + + return data; // Return the parsed data if validation passes } return 3; // It doesn't exist } catch(err) { @@ -28,4 +39,4 @@ function getJSON(file, filename) { return 3; } -module.exports = getJSON; +module.exports = getJSON; \ No newline at end of file