|
| 1 | +const { compareTests } = require('./utils/test'); |
| 2 | +const { generateTestChangesSummary } = require('./utils/format'); |
| 3 | +const { generateBundleSizeSection, getBundleInfo } = require('./utils/bundle'); |
| 4 | +const { readTestResults, getTestStatus } = require('./utils/results'); |
| 5 | + |
| 6 | +/** |
| 7 | + * Main function to update PR description with test results and bundle size information |
| 8 | + * @param {Object} github - GitHub API object |
| 9 | + * @param {Object} context - GitHub Actions context |
| 10 | + */ |
| 11 | +async function updatePRDescription(github, context) { |
| 12 | + // Read test results |
| 13 | + const currentResults = readTestResults('playwright-artifacts/test-results.json'); |
| 14 | + const mainResults = readTestResults('gh-pages/main/test-results.json'); |
| 15 | + |
| 16 | + // Compare tests |
| 17 | + const testComparison = compareTests(currentResults.tests, mainResults.tests); |
| 18 | + |
| 19 | + // Get test status and report URL |
| 20 | + const { status, statusColor } = getTestStatus(currentResults); |
| 21 | + const reportUrl = `https://${context.repo.owner}.github.io/${context.repo.repo}/${context.issue.number}/`; |
| 22 | + |
| 23 | + // Get bundle size information |
| 24 | + const bundleInfo = getBundleInfo(); |
| 25 | + |
| 26 | + // Generate the CI section content |
| 27 | + const ciSection = `## CI Results |
| 28 | +
|
| 29 | + ### Test Status: <span style="color: ${statusColor};">${status}</span> |
| 30 | + 📊 [Full Report](${reportUrl}) |
| 31 | +
|
| 32 | + | Total | Passed | Failed | Flaky | Skipped | |
| 33 | + |:-----:|:------:|:------:|:-----:|:-------:| |
| 34 | + | ${currentResults.total} | ${currentResults.passed} | ${currentResults.failed} | ${currentResults.flaky} | ${currentResults.skipped} | |
| 35 | +
|
| 36 | + ${generateTestChangesSummary(testComparison)} |
| 37 | +
|
| 38 | + ${generateBundleSizeSection(bundleInfo)} |
| 39 | +
|
| 40 | + <details> |
| 41 | + <summary>ℹ️ CI Information</summary> |
| 42 | +
|
| 43 | + - Test recordings for failed tests are available in the full report. |
| 44 | + - Bundle size is measured for the entire 'dist' directory. |
| 45 | + - 📊 indicates links to detailed reports. |
| 46 | + - 🔺 indicates increase, 🔽 decrease, and ✅ no change in bundle size. |
| 47 | + </details>`; |
| 48 | + |
| 49 | + // Update PR description |
| 50 | + const { data: pullRequest } = await github.rest.pulls.get({ |
| 51 | + owner: context.repo.owner, |
| 52 | + repo: context.repo.repo, |
| 53 | + pull_number: context.issue.number, |
| 54 | + }); |
| 55 | + |
| 56 | + const currentBody = pullRequest.body || ''; |
| 57 | + const ciSectionRegex = /## CI Results[\s\S]*?(?=\n## (?!CI Results)|$)/; |
| 58 | + |
| 59 | + const newBody = ciSectionRegex.test(currentBody) |
| 60 | + ? currentBody.replace(ciSectionRegex, ciSection) |
| 61 | + : currentBody + '\n\n' + ciSection; |
| 62 | + |
| 63 | + await github.rest.pulls.update({ |
| 64 | + owner: context.repo.owner, |
| 65 | + repo: context.repo.repo, |
| 66 | + pull_number: context.issue.number, |
| 67 | + body: newBody, |
| 68 | + }); |
| 69 | +} |
| 70 | + |
| 71 | +module.exports = updatePRDescription; |
0 commit comments