diff --git a/src/Repository.js b/src/Repository.js index 9aa390c..80c82d5 100644 --- a/src/Repository.js +++ b/src/Repository.js @@ -31,12 +31,13 @@ class Repository { }); pullRequests.push({ + number: pullRequest.number, + baseBranchName: pullRequest.base.ref, baseBranchSha: pullRequest.base.sha, baseBranchShortSha: pullRequest.base.sha.slice(0, 7), - baseRef: pullRequest.base.ref, + headBranchName: this.branch, headBranchSha: pullRequest.head.sha, headBranchShortSha: pullRequest.head.sha.slice(0, 7), - number: pullRequest.number, }); } @@ -102,17 +103,17 @@ class Repository { const baseResult = JSON.parse(results[1].body); const commentBody = await BuildCommentBody({ - baseAvgPercentage: TotalPercentagesAverage(baseResult), - baseRef: pullRequest.baseRef, + baseBranchName: pullRequest.baseBranchName, baseShortHash: pullRequest.baseBranchShortSha, - baseTotals: baseResult.summary.total, - branchName: this.branch, - fullReportUrl, hasBaseResults: Boolean(baseResult), - headAvgPercentage: TotalPercentagesAverage(headResult), + baseTotals: baseResult.summary.total, + baseAvgPercentage: TotalPercentagesAverage(baseResult), + headBranchName: pullRequest.headBranchName, headShortHash: pullRequest.headBranchShortSha, - headTotals: headResult.summary.total, testResults: headResult.stats, + headAvgPercentage: TotalPercentagesAverage(headResult), + headTotals: headResult.summary.total, + fullReportUrl, }); await this.addPullRequestComment(pullRequest.number, commentBody); diff --git a/src/utils/buildComment.js b/src/utils/buildComment.js index 1153674..4b267d4 100644 --- a/src/utils/buildComment.js +++ b/src/utils/buildComment.js @@ -1,8 +1,8 @@ const markdownTable = require('../lib/markdownTable').markdownTable; async function BuildCommentBody({ - baseRef, - branchName, + baseBranchName, + headBranchName, headAvgPercentage, baseAvgPercentage, hasBaseResults, @@ -15,8 +15,8 @@ async function BuildCommentBody({ }) { const coverageMessage = BuildCommentHeadMessage({ baseAvgPercentage, - baseRef, - branchName, + baseBranchName, + headBranchName, headAvgPercentage, }); @@ -48,9 +48,7 @@ ${coverageSummaryTable} - Time: **${timeTaken}** -> Coverage data is based on head **${branchName}** (\`${ - (headShortHash, baseShortHash) -}\`) compared to base **${baseRef}** (\`${baseShortHash}\`). +> Coverage data is based on head branch **${headBranchName}** (\`${headShortHash}\`) compared to base branch **${baseBranchName}** (\`${baseShortHash}\`). [View full coverage report šŸ”—](${fullReportUrl})`; @@ -58,26 +56,26 @@ ${coverageSummaryTable} } function BuildCommentHeadMessage({ - baseRef, - branchName, + baseBranchName, + headBranchName, headAvgPercentage, baseAvgPercentage, }) { let coverageMessage; if (headAvgPercentage > baseAvgPercentage) { - coverageMessage = `> Wooo šŸŽ‰, the tests are passing and the coverage percentage **increased**, well done! šŸ‘\n> ${baseRef}: **${Math.round( + coverageMessage = `> Wooo šŸŽ‰, the tests are passing and the coverage percentage **increased**, well done! šŸ‘\n> ${baseBranchName}: **${Math.round( baseAvgPercentage, -1 - )}%** | ${branchName}: **${Math.round(headAvgPercentage, -1)}%**`; + )}%** | ${headBranchName}: **${Math.round(headAvgPercentage, -1)}%**`; } else if (headAvgPercentage === baseAvgPercentage) { coverageMessage = '> Good job šŸ‘Œ, the tests are passing and the coverage percentage remained intact.'; } else { - coverageMessage = `> Tests are passing but the coverage percentage **decreased** šŸ˜±, read coverage report below for more details.\n\nšŸ”» ${baseRef}: **${Math.round( + coverageMessage = `> Tests are passing but the coverage percentage **decreased** šŸ˜±, read coverage report below for more details.\n\nšŸ”» ${baseBranchName}: **${Math.round( baseAvgPercentage, -1 - )}%** | ${branchName}: **${Math.round(headAvgPercentage, -1)}%** šŸ”»`; + )}%** | ${headBranchName}: **${Math.round(headAvgPercentage, -1)}%** šŸ”»`; } return coverageMessage;