Skip to content

Commit

Permalink
fix double json parse of lists
Browse files Browse the repository at this point in the history
  • Loading branch information
btkostner committed Sep 20, 2024
1 parent 75d788c commit 4b99581
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 36 deletions.
21 changes: 3 additions & 18 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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$/))
Expand Down Expand Up @@ -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?([^ ]+)/)
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
21 changes: 3 additions & 18 deletions src/setup-beam.js
Original file line number Diff line number Diff line change
Expand Up @@ -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$/))
Expand Down Expand Up @@ -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?([^ ]+)/)
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4b99581

Please sign in to comment.