mirror of
https://github.com/stablyai/orca.git
synced 2026-11-19 04:23:57 +00:00
refactor(github): organize concrete feature owners (#41601)
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
import type { GitHubRepositoryIdentity } from '../repositories/repository-identity'
|
||||
|
||||
export type GitHubReactionContent =
|
||||
| '+1'
|
||||
| '-1'
|
||||
| 'laugh'
|
||||
| 'confused'
|
||||
| 'heart'
|
||||
| 'hooray'
|
||||
| 'rocket'
|
||||
| 'eyes'
|
||||
|
||||
export type GitHubReaction = {
|
||||
content: GitHubReactionContent
|
||||
count: number
|
||||
viewerHasReacted?: boolean
|
||||
}
|
||||
|
||||
export type PRComment = {
|
||||
id: number
|
||||
author: string
|
||||
authorAvatarUrl: string
|
||||
body: string
|
||||
/** Transient display sources from the same body fetch; never submit or persist these URLs. */
|
||||
bodyImageUrls?: Record<string, string>
|
||||
createdAt: string
|
||||
url: string
|
||||
reactions?: GitHubReaction[]
|
||||
/** GraphQL node ID for GitHub comments that support reaction mutations. */
|
||||
reactionSubjectId?: string
|
||||
/** File path for inline review comments (absent for top-level conversation comments). */
|
||||
path?: string
|
||||
/** Inline review thread’s GraphQL ID, used to resolve/unresolve it; absent for conversation comments. */
|
||||
threadId?: string
|
||||
/** Whether the review thread has been resolved. Only meaningful when threadId is set. */
|
||||
isResolved?: boolean
|
||||
/** True when GitHub no longer maps the thread to the current diff. */
|
||||
isOutdated?: boolean
|
||||
/** End line of the review annotation (1-based). */
|
||||
line?: number
|
||||
/** Start line of the review annotation range (1-based). Absent for single-line comments. */
|
||||
startLine?: number
|
||||
/** A thread root's last diff lines, ending on `line`; absent from older hosts and non-GitHub sources. */
|
||||
diffHunk?: string
|
||||
/** Provider-reported bot identity beats login heuristics (qodo/coderabbit use varied names). Absent when non-GitHub gh fallbacks cannot report it. */
|
||||
isBot?: boolean
|
||||
/** True only when the gh account that read the thread wrote it (GraphQL's flag, or its login on REST reads); absent from older hosts. */
|
||||
viewerDidAuthor?: boolean
|
||||
}
|
||||
|
||||
export type GitHubIssueTimelineTarget = {
|
||||
type: 'issue' | 'pr'
|
||||
number: number
|
||||
title: string
|
||||
url: string
|
||||
repository?: string
|
||||
}
|
||||
|
||||
export type GitHubIssueTimelineItem = {
|
||||
id: string
|
||||
event:
|
||||
| 'assigned'
|
||||
| 'unassigned'
|
||||
| 'mentioned'
|
||||
| 'cross-referenced'
|
||||
| 'closed'
|
||||
| 'reopened'
|
||||
| 'moved_columns_in_project'
|
||||
actor: string
|
||||
actorAvatarUrl: string
|
||||
createdAt: string
|
||||
assignee?: string
|
||||
source?: GitHubIssueTimelineTarget
|
||||
closer?: GitHubIssueTimelineTarget
|
||||
stateReason?: string | null
|
||||
previousColumnName?: string | null
|
||||
columnName?: string | null
|
||||
projectName?: string | null
|
||||
}
|
||||
|
||||
export type GitHubCommentResult = { ok: true; comment: PRComment } | { ok: false; error: string }
|
||||
|
||||
export type GitHubPRReviewCommentInput = {
|
||||
repoPath: string
|
||||
prRepo?: GitHubRepositoryIdentity | null
|
||||
prNumber: number
|
||||
commitId: string
|
||||
path: string
|
||||
line: number
|
||||
startLine?: number
|
||||
body: string
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
// GitHub ends a review comment's diff hunk on the line the thread is anchored to, so its tail is the code in question.
|
||||
|
||||
const HUNK_TAIL_LINES = 8
|
||||
|
||||
/** The hunk's last lines without its @@ header; what the host forwards so phones get the code, not the whole hunk. */
|
||||
export function tailDiffHunk(hunk: string | null | undefined): string | undefined {
|
||||
if (!hunk) {
|
||||
return undefined
|
||||
}
|
||||
const lines = hunk.split('\n').filter((line) => !line.startsWith('@@'))
|
||||
return lines.length > 0 ? lines.slice(-HUNK_TAIL_LINES).join('\n') : undefined
|
||||
}
|
||||
|
||||
export type DiffHunkLine = {
|
||||
/** Position in the hunk tail; stable and unique, for list keys. */
|
||||
index: number
|
||||
number: number | null
|
||||
sign: '+' | '-' | ' '
|
||||
text: string
|
||||
}
|
||||
|
||||
/**
|
||||
* The lines a thread is about (startLine..endLine, or just endLine), numbered back from endLine.
|
||||
* Removed lines inside the range show unnumbered; "\ No newline" markers are skipped.
|
||||
*/
|
||||
export function threadDiffLines(
|
||||
hunkTail: string,
|
||||
endLine: number,
|
||||
startLine?: number
|
||||
): DiffHunkLine[] {
|
||||
const first = Math.max(startLine ?? endLine, endLine - HUNK_TAIL_LINES + 1)
|
||||
const lines = hunkTail.split('\n')
|
||||
const out: DiffHunkLine[] = []
|
||||
let number = endLine
|
||||
for (let index = lines.length - 1; index >= 0 && number >= first; index--) {
|
||||
const raw = lines[index]
|
||||
if (raw.startsWith('\\')) {
|
||||
continue
|
||||
}
|
||||
const sign = raw.startsWith('+') ? '+' : raw.startsWith('-') ? '-' : ' '
|
||||
const text = sign === ' ' && !raw.startsWith(' ') ? raw : raw.slice(1)
|
||||
if (sign === '-') {
|
||||
out.unshift({ index, number: null, sign, text })
|
||||
continue
|
||||
}
|
||||
out.unshift({ index, number, sign, text })
|
||||
number -= 1
|
||||
}
|
||||
return out
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { PRComment } from './comment-types'
|
||||
|
||||
// Conversation comments only: review threads and review summaries edit through other APIs.
|
||||
export function isMutablePRConversationComment(
|
||||
comment: Pick<PRComment, 'id' | 'threadId' | 'path' | 'url'>
|
||||
): boolean {
|
||||
if (comment.threadId || comment.path) {
|
||||
return false
|
||||
}
|
||||
if (comment.url && comment.url.includes('pullrequestreview')) {
|
||||
return false
|
||||
}
|
||||
return Number.isSafeInteger(comment.id) && comment.id > 0
|
||||
}
|
||||
@@ -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