Files
orca/src/shared/diff-comments-format.ts
T
7f770ae559 Add mobile review note actions (#3518)
* Add mobile review note actions

* fix: align mobile diff note gutter lines

Co-authored-by: Orca <help@stably.ai>

---------

Co-authored-by: Jinwoo-H <jinwoo0825@gmail.com>
Co-authored-by: Orca <help@stably.ai>
2026-05-30 13:43:33 -07:00

30 lines
1.0 KiB
TypeScript

import type { DiffComment } from './types'
function isMarkdownComment(comment: Pick<DiffComment, 'source'>): boolean {
return comment.source === 'markdown'
}
// Why: the pasted format is the contract between review notes and whichever
// agent consumes them. Keep it deterministic and quote-safe across clients.
export function formatDiffComment(c: DiffComment): string {
const escaped = c.body
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\r/g, '\\r')
.replace(/\n/g, '\\n')
const lineLabel =
c.startLine !== undefined && c.startLine !== c.lineNumber
? `Lines: ${c.startLine}-${c.lineNumber}`
: `Line: ${c.lineNumber}`
if (!isMarkdownComment(c)) {
return [`File: ${c.filePath}`, lineLabel, `User comment: "${escaped}"`].join('\n')
}
return [`File: ${c.filePath}`, 'Source: markdown', lineLabel, `User comment: "${escaped}"`].join(
'\n'
)
}
export function formatDiffComments(comments: readonly DiffComment[]): string {
return comments.map(formatDiffComment).join('\n\n')
}