Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/Aquaticat/Monochromatic. TypeScript and Rust monorepo: Claude Code and Pi coding-agent plugins, a m
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229/** Deterministic GitHub Issue body and request rendering. @module */
import type { RenderedIssue, SourceLink,} from './issue-model.ts';import { renderIssueTitle, } from './issue-title.ts';import { escapeMarkdownInline, indentCode,} from './markdown.ts';import type { NormalizedFinding, } from './model.ts';
/** Encodes source path segments for GitHub blob URL and Markdown destination. @param path - Untrusted repository-relative source path. @returns Slash-preserving URL path with Markdown parentheses encoded. @example ```ts encodeSourcePath('src/a b.ts'); // 'src/a%20b.ts' ``` */function encodeSourcePath(path: string,): string { return path.split('/',) .map(function encodeSegment(segment,): string { return encodeURIComponent(segment,) .replaceAll( '(', '%28', ) .replaceAll( ')', '%29', ); },) .join('/',);}
/** Builds plain or commit-pinned source location line. @param finding - Validated finding carrying source range. @param sourceLink - Verified repository and commit coordinates. @returns Markdown source location item. @example ```ts renderSourceLocation({ finding }); ``` */
function renderSourceLocation({ finding, sourceLink,}: { readonly finding: NormalizedFinding; readonly sourceLink?: SourceLink;},): string { /** Escaped source location text displayed in either branch. */ const location = `${escapeMarkdownInline(finding.path,)}:${String(finding.startLine,)}-${String(finding.endLine,)}`; if (sourceLink === undefined) { return `- Location: ${location}`; } /** Commit-pinned URL whose path is encoded at final interpolation. */ const url = `https://github.com/${sourceLink.repository}/blob/${sourceLink.commit}/${encodeSourcePath(finding.path,)}#L${String(finding.startLine,)}-L${String(finding.endLine,)}`; return `- Location: [${location}](${url})`;}
/** Renders optional indented code section. @param heading - Stable Markdown section heading. @param code - OCR source field. @returns Complete section lines or empty list when field is absent. @example ```ts renderCodeSection({ heading: 'Existing code', code: 'x' }); ``` */function renderCodeSection({ heading, code,}: { readonly heading: string; readonly code: string;},): readonly string[] { return code === '' ? [] : [ `## ${heading}`, '', indentCode(code,), '', ];}
/** Renders complete body while retaining OCR content as active Markdown. @param finding - Validated normalized finding. @param sourceLink - Verified repository and commit coordinates. @returns Deterministic GitHub Flavored Markdown body. @example ```ts renderIssueBody(finding); ``` */export function renderIssueBody({ finding, sourceLink,}: { readonly finding: NormalizedFinding; readonly sourceLink?: SourceLink;},): string { /** Category metadata with explicit missing value. */ const category = finding.category ?? 'uncategorized'; /** Severity metadata with explicit missing value. */ const severity = finding.severity ?? 'unspecified'; return [ '## Finding', '', finding.content, '', '## Source', '', renderSourceLocation({ finding, ...(sourceLink === undefined ? {} : { sourceLink, }), },), `- Category: \`${category}\``, `- Severity: \`${severity}\``, '', ...renderCodeSection({ heading: 'Existing code', code: finding.existingCode, },), ...renderCodeSection({ heading: 'Suggested code', code: finding.suggestionCode, },), '## OpenCodeReview', '', 'Generated from OpenCodeReview structured output.', ].join('\n',);}
/** Selects explicit marker for ordinary exceptional category states. @param finding - Validated finding classification. @returns Optional OTHER or UNCATEGORIZED marker property. */function classificationMarkerMetadata( finding: NormalizedFinding,): Pick<RenderedIssue, 'classificationMarker'> { if (finding.category === 'other') { return { classificationMarker: 'OTHER', }; } if (finding.category === undefined) { return { classificationMarker: 'UNCATEGORIZED', }; } return {};}
/** Renders one complete create-only Issue request. @param finding - Validated normalized finding. @param needsTriageLabel - Whether destination label exists. @param sourceLink - Verified repository and commit coordinates. @returns Deterministic title, body, labels, position, and security marker. @example ```ts renderIssue({ finding, needsTriageLabel: true }); ``` */export function renderIssue({ finding, needsTriageLabel, sourceLink,}: { readonly finding: NormalizedFinding; readonly needsTriageLabel: boolean; readonly sourceLink?: SourceLink;},): RenderedIssue { return { position: finding.position, security: finding.category === 'security', ...classificationMarkerMetadata(finding,), title: renderIssueTitle({ finding, needsTriageLabel, }), body: renderIssueBody({ finding, ...(sourceLink === undefined ? {} : { sourceLink, }), },), labels: needsTriageLabel ? ['needs-triage',] : [], };}