mirror of
https://github.com/stablyai/orca.git
synced 2026-11-13 17:37:40 +00:00
refactor(github): move inline PR comment line placement to src/shared (#36904)
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import type { PRComment } from './comment-types'
|
||||
import { getPRInlineCommentPlacement } from './pr-inline-comment-placement'
|
||||
|
||||
const comment = (overrides: Partial<PRComment>): PRComment => ({
|
||||
id: 1,
|
||||
author: 'octocat',
|
||||
authorAvatarUrl: '',
|
||||
body: 'body',
|
||||
createdAt: '2026-11-01T00:00:00Z',
|
||||
url: 'https://github.com/o/r/pull/1#discussion_r1',
|
||||
...overrides
|
||||
})
|
||||
|
||||
describe('getPRInlineCommentPlacement', () => {
|
||||
it('places a current review comment on its range', () => {
|
||||
expect(
|
||||
getPRInlineCommentPlacement(comment({ path: 'src/a.ts', line: 12, startLine: 10 }))
|
||||
).toEqual({ path: 'src/a.ts', line: 12, startLine: 10 })
|
||||
})
|
||||
|
||||
it('keeps outdated threads and conversation comments out of the diff', () => {
|
||||
expect(
|
||||
getPRInlineCommentPlacement(comment({ path: 'src/a.ts', line: 12, isOutdated: true }))
|
||||
).toBeNull()
|
||||
expect(getPRInlineCommentPlacement(comment({ path: 'src/a.ts' }))).toBeNull()
|
||||
expect(getPRInlineCommentPlacement(comment({}))).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import type { PRComment } from './comment-types'
|
||||
|
||||
export type PRInlineCommentPlacement = {
|
||||
path: string
|
||||
line: number
|
||||
startLine: number | undefined
|
||||
}
|
||||
|
||||
/** Where a PR review comment sits in the current diff, or null when it should not render inline. */
|
||||
export function getPRInlineCommentPlacement(comment: PRComment): PRInlineCommentPlacement | null {
|
||||
// Why: outdated threads keep originalLine for the sidebar, but rendering it inline can attach the comment to unrelated current code.
|
||||
if (comment.isOutdated || !comment.path || typeof comment.line !== 'number') {
|
||||
return null
|
||||
}
|
||||
return { path: comment.path, line: comment.line, startLine: comment.startLine }
|
||||
}
|
||||
Reference in New Issue
Block a user