diff --git a/dist/index.js b/dist/index.js index 0ca8516e..06de242b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6058,7 +6058,18 @@ class Bot { } try { // Attempt to parse the JSON content - const parsedContent = JSON.parse(responseText); + let parsedContent; + if (responseText.startsWith('{')) { + parsedContent = JSON.parse(responseText); + } + else { + // If it doesn't start with '{', it might be a nested JSON string + parsedContent = JSON.parse(JSON.parse(responseText)); + } + // Ensure the structure is correct + if (!parsedContent.reviews) { + parsedContent = { reviews: parsedContent.reviews || [{ comment: responseText }], lgtm: false }; + } responseText = JSON.stringify(parsedContent, null, 2); // Pretty print the JSON } catch (parseError) { diff --git a/src/bot.ts b/src/bot.ts index 4c2d47df..b3d72bfa 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -106,7 +106,19 @@ export class Bot { try { // Attempt to parse the JSON content - const parsedContent = JSON.parse(responseText); + let parsedContent; + if (responseText.startsWith('{')) { + parsedContent = JSON.parse(responseText); + } else { + // If it doesn't start with '{', it might be a nested JSON string + parsedContent = JSON.parse(JSON.parse(responseText)); + } + + // Ensure the structure is correct + if (!parsedContent.reviews) { + parsedContent = { reviews: parsedContent.reviews || [{ comment: responseText }], lgtm: false }; + } + responseText = JSON.stringify(parsedContent, null, 2); // Pretty print the JSON } catch (parseError) { warning(`Response is not in JSON format: ${parseError}`);