From b52c4ed5cb0d6ef9c26e467c1d4a65c57937826e Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Thu, 12 Nov 2020 12:01:58 -0700 Subject: [PATCH 1/2] Show differences from the required form --- src/pr-info.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/pr-info.ts b/src/pr-info.ts index 2006d83a0..b3e7e158c 100644 --- a/src/pr-info.ts +++ b/src/pr-info.ts @@ -419,11 +419,18 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[]) { const newDiff = diffFromReq(contents); if (typeof newDiff === "string") return newDiff; if (newDiff.length === 0) return undefined; - if (!oldText) return "not the required form"; + if (!oldText) return `not the required form +\`\`\`JSON +${JSON.stringify(newDiff)} +\`\`\``; const oldDiff = diffFromReq(oldText); if (typeof oldDiff === "string") return oldDiff; - if (jsonDiff.compare(oldDiff, newDiff).every(({ op }) => op === "remove")) return undefined; - return "not the required form and not moving towards it"; + const notRemove = jsonDiff.compare(oldDiff, newDiff).filter(({ op }) => op !== "remove"); + if (notRemove.length === 0) return undefined; + return `not the required form and not moving towards it +\`\`\`JSON +${JSON.stringify(notRemove.map(({ path }) => newDiff[Number(path.slice(1))]))} +\`\`\``; }; } From e672b8a3c8a74a417a7c365556adda43f799a143 Mon Sep 17 00:00:00 2001 From: Jack Bates Date: Fri, 13 Nov 2020 11:10:27 -0700 Subject: [PATCH 2/2] Apply suggestions from code review --- src/pr-info.ts | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/pr-info.ts b/src/pr-info.ts index b3e7e158c..439b34909 100644 --- a/src/pr-info.ts +++ b/src/pr-info.ts @@ -419,18 +419,12 @@ function makeJsonCheckerFromCore(requiredForm: any, ignoredKeys: string[]) { const newDiff = diffFromReq(contents); if (typeof newDiff === "string") return newDiff; if (newDiff.length === 0) return undefined; - if (!oldText) return `not the required form -\`\`\`JSON -${JSON.stringify(newDiff)} -\`\`\``; + if (!oldText) return `not the required form \`${JSON.stringify(newDiff)}\``; const oldDiff = diffFromReq(oldText); if (typeof oldDiff === "string") return oldDiff; const notRemove = jsonDiff.compare(oldDiff, newDiff).filter(({ op }) => op !== "remove"); if (notRemove.length === 0) return undefined; - return `not the required form and not moving towards it -\`\`\`JSON -${JSON.stringify(notRemove.map(({ path }) => newDiff[Number(path.slice(1))]))} -\`\`\``; + return `not the required form and not moving towards it \`${JSON.stringify(notRemove.map(({ path }) => newDiff[Number(path.slice(1))]))}\``; }; }