Skip to content

Commit

Permalink
ARCH-2011 - Small cleanup items
Browse files Browse the repository at this point in the history
  • Loading branch information
danielle-casella-adams committed Feb 27, 2024
1 parent 61d3cd6 commit 954bb43
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 24 deletions.
17 changes: 9 additions & 8 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}
Expand Down Expand Up @@ -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, {
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions src/github.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down
10 changes: 5 additions & 5 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.`);
Expand Down
17 changes: 10 additions & 7 deletions test/assert-pr-comment-matches-expectations.js
Original file line number Diff line number Diff line change
@@ -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.`);
Expand All @@ -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.`);
Expand All @@ -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();
}
}
Expand Down

0 comments on commit 954bb43

Please sign in to comment.