UNPKG

donobu

Version:

Create browser automations with an LLM agent and replay them as Playwright scripts.

89 lines 3.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.renderPullRequestBody = renderPullRequestBody; /** * @fileoverview Donobu auto-heal pull request body renderer. * * Turns the merged auto-heal `DonobuReport` into the markdown body of the * PR/MR opened by the surrounding CI job. Pure: callers pass the env subset * the footer needs as a plain object, defaulting to the central `env.pick` * view of the relevant CI vars when running in production. * * Returns an empty string when nothing was healed — the CLI uses that to * decide whether to write the file at all. */ const envVars_1 = require("../envVars"); function parseHealedKey(rawKey) { // Composite key shape from buildTestKey(): `file::projectName::title`. // Titles can themselves contain `::`, so we only split off the first two // segments and treat the remainder as the title. const firstSep = rawKey.indexOf('::'); if (firstSep < 0) { return { file: 'unknown-file', projectName: 'default', title: rawKey }; } const file = rawKey.slice(0, firstSep); const rest = rawKey.slice(firstSep + 2); const secondSep = rest.indexOf('::'); if (secondSep < 0) { return { file, projectName: 'default', title: rest }; } return { file, projectName: rest.slice(0, secondSep), title: rest.slice(secondSep + 2), }; } function renderPullRequestBody(report, envData = envVars_1.env.pick('GITHUB_RUN_ID', 'GITHUB_RUN_NUMBER', 'GITHUB_SERVER_URL', 'GITHUB_REPOSITORY', 'GITHUB_ACTOR', 'GITHUB_REF_NAME', 'CI_PIPELINE_URL', 'CI_PIPELINE_IID', 'GITLAB_USER_LOGIN', 'CI_COMMIT_REF_NAME').data) { const healedKeys = report.metadata?.donobuHealedTests ?? []; if (healedKeys.length === 0) { return ''; } const parsed = healedKeys.map(parseHealedKey); const noun = parsed.length === 1 ? 'test' : 'tests'; let body = `🩹 **Donobu auto-heal applied fixes to ${parsed.length} failing ${noun}** in this branch.\n\n`; body += `The auto-heal rerun applied a treatment plan to the failing ${noun}.\n\n`; body += `## Healed ${noun}\n\n`; for (const entry of parsed) { const projectSuffix = entry.projectName && entry.projectName !== 'default' ? ` _(project: \`${entry.projectName}\`)_` : ''; body += `- ❤️‍🩹 \`${entry.file}\` — ${entry.title}${projectSuffix}\n`; } const footer = buildCiFooter(envData); if (footer) { body += `\n---\n\n${footer}\n`; } return body; } function buildCiFooter(e) { if (e.GITHUB_RUN_ID && e.GITHUB_SERVER_URL && e.GITHUB_REPOSITORY) { const url = `${e.GITHUB_SERVER_URL}/${e.GITHUB_REPOSITORY}/actions/runs/${e.GITHUB_RUN_ID}`; const label = e.GITHUB_RUN_NUMBER ? `workflow run #${e.GITHUB_RUN_NUMBER}` : 'workflow run'; return assembleFooter(label, url, e.GITHUB_ACTOR, e.GITHUB_REF_NAME); } else if (e.CI_PIPELINE_URL) { // `CI_PIPELINE_IID` is the per-project pipeline number GitLab shows in // its UI ("#42") — far more useful in a footer than the global numeric // `CI_PIPELINE_ID` reviewers don't recognize. const label = e.CI_PIPELINE_IID ? `pipeline #${e.CI_PIPELINE_IID}` : 'pipeline'; return assembleFooter(label, e.CI_PIPELINE_URL, e.GITLAB_USER_LOGIN, e.CI_COMMIT_REF_NAME); } else { return undefined; } } function assembleFooter(label, url, actor, refName) { let footer = `🤖 Generated by Donobu auto-heal · [${label}](${url})`; if (actor) { footer += ` · triggered by @${actor}`; } if (refName) { footer += ` · on \`${refName}\``; } return footer; } //# sourceMappingURL=renderPullRequestBody.js.map