@@ -86,23 +86,35 @@ function getBadgeColor(coverage) {
8686/**
8787 * Generate coverage report comment body
8888 * @param {object } metrics - Coverage metrics
89+ * @param {object } commitInfo - Optional commit information
8990 * @returns {string } Markdown formatted comment body
9091 */
91- function generateCoverageReport ( metrics ) {
92+ function generateCoverageReport ( metrics , commitInfo = { } ) {
9293 const lineCoverage = calculateCoverage ( metrics . coveredLines , metrics . totalLines ) ;
9394 const functionCoverage = calculateCoverage ( metrics . coveredFunctions , metrics . totalFunctions ) ;
9495 const branchCoverage = calculateCoverage ( metrics . coveredBranches , metrics . totalBranches ) ;
9596
9697 const badgeColor = getBadgeColor ( lineCoverage ) ;
9798 const badge = `` ;
99+
100+ // Generate timestamp
101+ const timestamp = new Date ( ) . toUTCString ( ) ;
102+
103+ // Build commit link if info is available
104+ let commitLink = '' ;
105+ if ( commitInfo . sha && commitInfo . owner && commitInfo . repo ) {
106+ const shortSha = commitInfo . sha . substring ( 0 , 7 ) ;
107+ commitLink = ` for commit [\`${ shortSha } \`](https://github.com/${ commitInfo . owner } /${ commitInfo . repo } /commit/${ commitInfo . sha } )` ;
108+ }
98109
99110 return `## Coverage Report\n` +
100111 `${ badge } \n\n` +
101112 `| Metric | Coverage | Details |\n` +
102113 `|--------|----------|----------|\n` +
103114 `| **Lines** | ${ lineCoverage } % | ${ metrics . coveredLines } /${ metrics . totalLines } lines |\n` +
104115 `| **Functions** | ${ functionCoverage } % | ${ metrics . coveredFunctions } /${ metrics . totalFunctions } functions |\n` +
105- `| **Branches** | ${ branchCoverage } % | ${ metrics . coveredBranches } /${ metrics . totalBranches } branches |\n\n` ;
116+ `| **Branches** | ${ branchCoverage } % | ${ metrics . coveredBranches } /${ metrics . totalBranches } branches |\n\n` +
117+ `*Last updated: ${ timestamp } *${ commitLink } \n` ;
106118}
107119
108120/**
@@ -157,7 +169,14 @@ function generateCoverageFile() {
157169 console . log ( '- Functions:' , metrics . coveredFunctions , '/' , metrics . totalFunctions ) ;
158170 console . log ( '- Branches:' , metrics . coveredBranches , '/' , metrics . totalBranches ) ;
159171
160- const body = generateCoverageReport ( metrics ) ;
172+ // Get commit info from environment variables
173+ const commitInfo = {
174+ sha : process . env . COMMIT_SHA ,
175+ owner : process . env . REPO_OWNER ,
176+ repo : process . env . REPO_NAME
177+ } ;
178+
179+ const body = generateCoverageReport ( metrics , commitInfo ) ;
161180 fs . writeFileSync ( 'coverage-report.md' , body ) ;
162181 console . log ( 'Coverage report saved to coverage-report.md' ) ;
163182}
0 commit comments