From 954bb4319e04d47990fb36936539d5c67ff54d70 Mon Sep 17 00:00:00 2001 From: Danielle Adams Date: Tue, 27 Feb 2024 16:41:06 -0700 Subject: [PATCH] ARCH-2011 - Small cleanup items --- dist/index.js | 17 +++++++++-------- src/github.js | 6 +++--- src/main.js | 10 +++++----- src/utils.js | 2 +- test/assert-pr-comment-matches-expectations.js | 17 ++++++++++------- 5 files changed, 28 insertions(+), 24 deletions(-) diff --git a/dist/index.js b/dist/index.js index cad9545..48e6696 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2389,7 +2389,8 @@ var require_utils2 = __commonJS({ } } function areThereAnyFailingTests2(json) { - core2.info(`Checking for failing tests..`); + core2.info(` +Checking for failing tests..`); if (json.numFailedTests > 0) { core2.warning(`At least one failing test was found.`); return true; @@ -16659,7 +16660,7 @@ Creating Status check for ${reportName2}...`); const status = 'completed'; const checkTime = new Date().toUTCString(); const summary = `This test run completed at \`${checkTime}\``; - let propMessage = ` Name: ${name} + const propMessage = ` Name: ${name} GitSha: ${git_sha} Event: ${github.context.eventName} Status: ${status} @@ -16692,7 +16693,7 @@ Creating Status check for ${reportName2}...`); }); return statusCheckId; } - async function lookForExistingComment(octokit, markupPrefix) { + async function lookForExistingComment(octokit, markdownPrefix) { let commentId = null; await octokit .paginate(octokit.rest.issues.listComments, { @@ -16704,7 +16705,7 @@ Creating Status check for ${reportName2}...`); if (comments.length === 0) { core2.info('There are no comments on the PR. A new comment will be created.'); } else { - const existingComment = comments.find(c => c.body.startsWith(markupPrefix)); + const existingComment = comments.find(c => c.body.startsWith(markdownPrefix)); if (existingComment) { core2.info(`An existing comment (${existingComment.id}) was found and will be updated.`); commentId = existingComment.id; @@ -19833,18 +19834,18 @@ async function run() { if (shouldCreatePRComment) { core.info(` Creating a PR comment with length ${markupData.length}...`); - const charLimit = 65535; + const characterLimit = 65535; let truncated = false; let mdForComment = markupData; - if (mdForComment.length > charLimit) { - const message = `Truncating markup data due to character limit exceeded for GitHub API. Markup data length: ${mdForComment.length}/${charLimit}`; + if (mdForComment.length > characterLimit) { + const message = `Truncating markup data due to character limit exceeded for GitHub API. Markup data length: ${mdForComment.length}/${characterLimit}`; core.info(message); truncated = true; const truncatedMessage = `> [!Important] > Test results truncated due to character limit. See full report in output. `; mdForComment = `${truncatedMessage} -${mdForComment.substring(0, charLimit - 100)}`; +${mdForComment.substring(0, characterLimit - 100)}`; } core.setOutput('test-results-truncated', truncated); const commentId = await createPrComment(token, mdForComment, updateCommentIfOneExists, commentIdentifier); diff --git a/src/github.js b/src/github.js index b1997f1..58a8437 100644 --- a/src/github.js +++ b/src/github.js @@ -12,7 +12,7 @@ async function createStatusCheck(repoToken, markupData, conclusion, reportName) const checkTime = new Date().toUTCString(); const summary = `This test run completed at \`${checkTime}\``; - let propMessage = ` Name: ${name} + const propMessage = ` Name: ${name} GitSha: ${git_sha} Event: ${github.context.eventName} Status: ${status} @@ -47,7 +47,7 @@ async function createStatusCheck(repoToken, markupData, conclusion, reportName) return statusCheckId; } -async function lookForExistingComment(octokit, markupPrefix) { +async function lookForExistingComment(octokit, markdownPrefix) { let commentId = null; await octokit @@ -60,7 +60,7 @@ async function lookForExistingComment(octokit, markupPrefix) { if (comments.length === 0) { core.info('There are no comments on the PR. A new comment will be created.'); } else { - const existingComment = comments.find(c => c.body.startsWith(markupPrefix)); + const existingComment = comments.find(c => c.body.startsWith(markdownPrefix)); if (existingComment) { core.info(`An existing comment (${existingComment.id}) was found and will be updated.`); commentId = existingComment.id; diff --git a/src/main.js b/src/main.js index 7f79c71..2bed891 100644 --- a/src/main.js +++ b/src/main.js @@ -10,7 +10,6 @@ const requiredArgOptions = { const token = core.getInput('github-token', requiredArgOptions); const resultsFile = core.getInput('results-file', requiredArgOptions); - const ignoreTestFailures = core.getBooleanInput('ignore-test-failures'); const shouldCreateStatusCheck = core.getBooleanInput('create-status-check'); const shouldCreatePRComment = core.getBooleanInput('create-pr-comment'); @@ -46,16 +45,17 @@ async function run() { core.info(`\nCreating a PR comment with length ${markupData.length}...`); // GitHub API has a limit of 65535 characters for a comment so truncate the markup if we need to - const charLimit = 65535; + const characterLimit = 65535; let truncated = false; let mdForComment = markupData; - if (mdForComment.length > charLimit) { - const message = `Truncating markup data due to character limit exceeded for GitHub API. Markup data length: ${mdForComment.length}/${charLimit}`; + + if (mdForComment.length > characterLimit) { + const message = `Truncating markup data due to character limit exceeded for GitHub API. Markup data length: ${mdForComment.length}/${characterLimit}`; core.info(message); truncated = true; const truncatedMessage = `> [!Important]\n> Test results truncated due to character limit. See full report in output.\n`; - mdForComment = `${truncatedMessage}\n${mdForComment.substring(0, charLimit - 100)}`; + mdForComment = `${truncatedMessage}\n${mdForComment.substring(0, characterLimit - 100)}`; } core.setOutput('test-results-truncated', truncated); diff --git a/src/utils.js b/src/utils.js index c0075f0..4ac7b35 100644 --- a/src/utils.js +++ b/src/utils.js @@ -20,7 +20,7 @@ async function readJsonResultsFromFile(resultsFile) { } function areThereAnyFailingTests(json) { - core.info(`Checking for failing tests..`); + core.info(`\nChecking for failing tests..`); if (json.numFailedTests > 0) { core.warning(`At least one failing test was found.`); diff --git a/test/assert-pr-comment-matches-expectations.js b/test/assert-pr-comment-matches-expectations.js index 8a479cd..e69436b 100644 --- a/test/assert-pr-comment-matches-expectations.js +++ b/test/assert-pr-comment-matches-expectations.js @@ -1,7 +1,7 @@ module.exports = async (core, actualComment, actualTestResults, expectedComment) => { function assertCreatedAndUpdatedMatch(created, updated) { core.info(`\n\tCreated: '${created}'`); - core.info(`\tUpdated: '${updated}'`); + core.info(`\tUpdated: '${updated}'`); if (created != updated) { core.setFailed(`\tThe created and updated dates do not match, which is NOT expected.`); @@ -12,7 +12,7 @@ module.exports = async (core, actualComment, actualTestResults, expectedComment) function assertUpdatedIsAfterCreated(created, updated) { core.info(`\n\tCreated: '${created}'`); - core.info(`\tUpdated: '${updated}'`); + core.info(`\tUpdated: '${updated}'`); if (created >= updated) { core.setFailed(`\tThe created date is on or after the updated date, which is NOT expected.`); @@ -24,13 +24,16 @@ module.exports = async (core, actualComment, actualTestResults, expectedComment) function assertValueContainsSubstring(valueName, value, substringName, substring) { if (value.includes(substring)) { core.info(`\n\tChecking ${valueName} contains the ${substringName} substring.`); - core.info(`\tThe ${valueName} string contains the substring.`); + core.info(`\tThe ${valueName} string contains the substring, which is expected.`); } else { core.info(`\n\tChecking ${valueName} contains the ${substringName} substring.`); - core.setFailed(`\tThe ${valueName} string does not contain the ${substringName} substring.`); - core.startGroup('\tString and substring Details'); - core.info(`\n\t${valueName}: '${value}'`); - core.info(`\t${substringName}: '${substring}'`); + core.setFailed(`\tThe ${valueName} string does not contain the ${substringName} substring, which is not expected.`); + core.startGroup(`\t${valueName} contents:`); + core.info(`'${value}'`); + core.endGroup(); + + core.startGroup(`\t${substringName} contents:`); + core.info(`'${substring}'`); core.endGroup(); } }