Skip to content

Commit

Permalink
EN-24491 - Truncating status check and github comment.
Browse files Browse the repository at this point in the history
  • Loading branch information
jsclifford committed Jan 28, 2025
1 parent 25f3784 commit 060f201
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 38 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ jobs:
- name: Process jest results with default
if: always()
# You may also reference just the major or major.minor version
uses: im-open/process-jest-test-results@v2.2.0
uses: im-open/process-jest-test-results@v2.2.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
results-file: 'src/ProjectWithJestTests/jest-results.json
Expand All @@ -137,7 +137,7 @@ jobs:

- name: Process jest results
id: process-jest
uses: im-open/process-jest-test-results@v2.2.0
uses: im-open/process-jest-test-results@v2.2.1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
results-file: 'jest.json'
Expand Down
34 changes: 17 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19823,32 +19823,32 @@ async function run() {
const failingTestsFound = areThereAnyFailingTests(resultsJson);
core.setOutput('test-outcome', failingTestsFound ? 'Failed' : 'Passed');
const markupData = getMarkupForJson(resultsJson, reportName);
const characterLimit = 65535;
let truncated = false;
let mdData = markupData;
if (mdData.length > characterLimit) {
const message = `Truncating markup data due to character limit exceeded for GitHub API. Markup data length: ${mdData.length}/${characterLimit}`;
core.info(message);
truncated = true;
const truncatedMessage = `> [!Important]
> Test results truncated due to character limit. See full report in output.
`;
mdData = `${truncatedMessage}
${mdForComment.substring(0, characterLimit - 100)}`;
}
core.setOutput('test-results-truncated', truncated);
if (shouldCreateStatusCheck) {
let conclusion = 'success';
if (!resultsJson.success) {
conclusion = ignoreTestFailures ? 'neutral' : 'failure';
}
const checkId = await createStatusCheck(token, markupData, conclusion, reportName);
const checkId = await createStatusCheck(token, mdData, conclusion, reportName);
core.setOutput('status-check-id', checkId);
}
if (shouldCreatePRComment) {
core.info(`
Creating a PR comment with length ${markupData.length}...`);
const characterLimit = 65535;
let truncated = false;
let mdForComment = markupData;
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, characterLimit - 100)}`;
}
core.setOutput('test-results-truncated', truncated);
const commentId = await createPrComment(token, mdForComment, updateCommentIfOneExists, commentIdentifier);
Creating a PR comment with length ${mdData.length}...`);
const commentId = await createPrComment(token, mdData, updateCommentIfOneExists, commentIdentifier);
core.setOutput('pr-comment-id', commentId);
}
const resultsFilePath = createResultsFile(markupData, jobAndStep);
Expand Down
37 changes: 18 additions & 19 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,33 @@ async function run() {

const markupData = getMarkupForJson(resultsJson, reportName);

// GitHub API has a limit of 65535 characters for a comment so truncate the markup if we need to
const characterLimit = 65535;
let truncated = false;
let mdData = markupData;

if (mdData.length > characterLimit) {
const message = `Truncating markup data due to character limit exceeded for GitHub API. Markup data length: ${mdData.length}/${characterLimit}`;
core.info(message);

truncated = true;
const truncatedMessage = `> [!Important]\n> Test results truncated due to character limit. See full report in output.\n`;
mdData = `${truncatedMessage}\n${mdForComment.substring(0, characterLimit - 100)}`;
}
core.setOutput('test-results-truncated', truncated);

if (shouldCreateStatusCheck) {
let conclusion = 'success';
if (!resultsJson.success) {
conclusion = ignoreTestFailures ? 'neutral' : 'failure';
}
const checkId = await createStatusCheck(token, markupData, conclusion, reportName);
const checkId = await createStatusCheck(token, mdData, conclusion, reportName);
core.setOutput('status-check-id', checkId); // This is mainly for testing purposes
}

if (shouldCreatePRComment) {
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 characterLimit = 65535;
let truncated = false;
let mdForComment = markupData;

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, characterLimit - 100)}`;
}
core.setOutput('test-results-truncated', truncated);

const commentId = await createPrComment(token, mdForComment, updateCommentIfOneExists, commentIdentifier);
core.info(`\nCreating a PR comment with length ${mdData.length}...`);
const commentId = await createPrComment(token, mdData, updateCommentIfOneExists, commentIdentifier);
core.setOutput('pr-comment-id', commentId); // This is mainly for testing purposes
}

Expand Down

0 comments on commit 060f201

Please sign in to comment.