From 4b99581f17bfa6d193a8f87b9bb930b802498584 Mon Sep 17 00:00:00 2001 From: Blake Kostner Date: Fri, 20 Sep 2024 15:13:13 -0700 Subject: [PATCH] fix double json parse of lists --- dist/index.js | 21 +++------------------ src/setup-beam.js | 21 +++------------------ 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/dist/index.js b/dist/index.js index a8f8fea6..dc7a9ec2 100644 --- a/dist/index.js +++ b/dist/index.js @@ -9389,7 +9389,7 @@ async function getOTPVersions(osVersion) { }) } else if (process.platform === 'win32') { otpVersionsListings.forEach((otpVersionsListing) => { - jsonParseAsList(otpVersionsListing) + otpVersionsListing .map((x) => x.assets) .flat() .filter((x) => x.name.match(/^otp_win64_.*.exe$/)) @@ -9446,7 +9446,7 @@ async function getGleamVersions() { ) const gleamVersionsListing = {} resultJSONs.forEach((resultJSON) => { - jsonParseAsList(resultJSON) + resultJSON .map((x) => x.tag_name) .forEach((ver) => { const gleamMatch = ver.match(/^v?([^ ]+)/) @@ -9465,7 +9465,7 @@ async function getRebar3Versions() { ) const rebar3VersionsListing = {} resultJSONs.forEach((resultJSON) => { - jsonParseAsList(resultJSON) + resultJSON .map((x) => x.tag_name) .forEach((ver) => { rebar3VersionsListing[ver] = ver @@ -9797,21 +9797,6 @@ function parseVersionFile(versionFilePath0) { return appVersions } -function jsonParseAsList(maybeJson) { - try { - const obj = JSON.parse(maybeJson) - if (!Array.isArray(obj)) { - throw new Error('expected a list!') - } - - return obj - } catch (exc) { - throw new Error( - `Got an exception when trying to parse non-JSON list ${maybeJson}: ${exc}`, - ) - } -} - function debugLog(groupName, message) { const group = `Debugging for ${groupName}` core.debug( diff --git a/src/setup-beam.js b/src/setup-beam.js index 3c72da7c..879a75b6 100644 --- a/src/setup-beam.js +++ b/src/setup-beam.js @@ -289,7 +289,7 @@ async function getOTPVersions(osVersion) { }) } else if (process.platform === 'win32') { otpVersionsListings.forEach((otpVersionsListing) => { - jsonParseAsList(otpVersionsListing) + otpVersionsListing .map((x) => x.assets) .flat() .filter((x) => x.name.match(/^otp_win64_.*.exe$/)) @@ -346,7 +346,7 @@ async function getGleamVersions() { ) const gleamVersionsListing = {} resultJSONs.forEach((resultJSON) => { - jsonParseAsList(resultJSON) + resultJSON .map((x) => x.tag_name) .forEach((ver) => { const gleamMatch = ver.match(/^v?([^ ]+)/) @@ -365,7 +365,7 @@ async function getRebar3Versions() { ) const rebar3VersionsListing = {} resultJSONs.forEach((resultJSON) => { - jsonParseAsList(resultJSON) + resultJSON .map((x) => x.tag_name) .forEach((ver) => { rebar3VersionsListing[ver] = ver @@ -697,21 +697,6 @@ function parseVersionFile(versionFilePath0) { return appVersions } -function jsonParseAsList(maybeJson) { - try { - const obj = JSON.parse(maybeJson) - if (!Array.isArray(obj)) { - throw new Error('expected a list!') - } - - return obj - } catch (exc) { - throw new Error( - `Got an exception when trying to parse non-JSON list ${maybeJson}: ${exc}`, - ) - } -} - function debugLog(groupName, message) { const group = `Debugging for ${groupName}` core.debug(