refactor(vscode): remove unused GitHub comment context members

Drop the never-read `available` and `label` members from the GitHub
comment context introduced with inline PR comments, and cover the
retained resolve/send gating with a focused test.
This commit is contained in:
marius-kilocode
2026-09-14 10:51:05 +02:00
parent b666fb64ef
commit 531d2c1aaa
3 changed files with 34 additions and 11 deletions
@@ -1,5 +1,10 @@
import { describe, expect, it } from "bun:test"
import { postAllGithub, resolveGithubContext, type CommentsGithub } from "../../webview-ui/diff-viewer/comments-github"
import {
createCommentsGithub,
postAllGithub,
resolveGithubContext,
type CommentsGithub,
} from "../../webview-ui/diff-viewer/comments-github"
import type { PRDiffSnapshot, PRTarget } from "../../src/shared/pr-comment-actions"
import type { ReviewComment } from "../../webview-ui/diff-viewer/review-comments"
@@ -23,7 +28,6 @@ function comment(id: string, line: number): ReviewComment {
function fake(handler: (comment: ReviewComment) => { success: boolean; error?: string }): CommentsGithub {
return {
available: () => true,
resolve: () => undefined,
send: async (item) => handler(item),
}
@@ -44,7 +48,6 @@ describe("resolveGithubContext", () => {
prNumber: 7,
prUrl: target.prUrl,
snapshotId: "snap-1",
label: "GitHub #7",
closed: false,
})
})
@@ -84,6 +87,33 @@ describe("resolveGithubContext", () => {
})
})
describe("createCommentsGithub", () => {
function github(canPublish: boolean) {
return createCommentsGithub({
target: () => target,
snapshot: () => snapshot,
diffs: () => [],
post: () => {},
canPublish: () => canPublish,
})
}
it("resolves a context while publication is enabled", () => {
expect(github(true).resolve(comment("a", 2))).toEqual({
prNumber: 7,
prUrl: target.prUrl,
snapshotId: "snap-1",
closed: true,
})
})
it("refuses to resolve or send while publication is disabled", async () => {
const disabled = github(false)
expect(disabled.resolve(comment("a", 2))).toBeUndefined()
await expect(disabled.send(comment("a", 2))).resolves.toEqual({ success: false })
})
})
describe("postAllGithub", () => {
it("posts every comment in order when each request succeeds", async () => {
const sent: string[] = []
@@ -64,7 +64,6 @@ type Props = {
prNumber: number
prUrl: string
snapshotId: string
label: string
closed: boolean
}
initialBody?: string
@@ -11,13 +11,10 @@ export interface GithubContext {
prNumber: number
prUrl: string
snapshotId: string
label: string
closed: boolean
}
export interface CommentsGithub {
/** True when a PR with a loaded snapshot is available for publication. */
available: () => boolean
/** Resolve the GitHub target for a comment. `closed` means the line is not publishable. */
resolve: (comment: ReviewComment) => GithubContext | undefined
send: (comment: ReviewComment) => Promise<{ success: boolean; error?: string }>
@@ -53,7 +50,6 @@ export function resolveGithubContext(opts: {
prNumber: opts.target.prNumber,
prUrl: opts.target.prUrl,
snapshotId: opts.snapshot.id,
label: `GitHub #${opts.target.prNumber}`,
closed: !allowed,
}
}
@@ -82,8 +78,6 @@ export function createCommentsGithub(opts: Options): CommentsGithub {
})
}
const available = () => opts.canPublish?.() !== false && !!opts.target() && !!opts.snapshot()
const send = (comment: ReviewComment) => {
const { promise, resolve: settle } = Promise.withResolvers<{ success: boolean; error?: string }>()
const target = opts.target()
@@ -113,7 +107,7 @@ export function createCommentsGithub(opts: Options): CommentsGithub {
return promise
}
return { available, resolve, send }
return { resolve, send }
}
/**