feat: add GitHub PR list and context APIs

Add PRs list API with pagination
Provide PR context API with optional diff
Integrate PR picker in session UI
This commit is contained in:
Bohdan Triapitsyn
2026-01-24 01:57:35 +02:00
parent 57f00be773
commit f370ea5d8c
14 changed files with 2507 additions and 79 deletions
+56 -1
View File
@@ -35,6 +35,11 @@ import {
listIssues,
} from './githubIssues';
import {
getPullRequestContext,
listPullRequests,
} from './githubPulls';
export interface BridgeRequest {
id: string;
type: string;
@@ -1185,11 +1190,12 @@ export async function handleBridgeMessage(message: BridgeRequest, ctx?: BridgeCo
return { id, type, success: true, data: { connected: false } };
}
const directory = readStringField(payload, 'directory');
const page = readNumberField(payload, 'page') ?? 1;
if (!directory) {
return { id, type, success: false, error: 'directory is required' };
}
try {
const result = await listIssues(stored.accessToken, directory);
const result = await listIssues(stored.accessToken, directory, page);
if (result.connected === false) {
await clearGitHubAuth(context);
}
@@ -1248,6 +1254,55 @@ export async function handleBridgeMessage(message: BridgeRequest, ctx?: BridgeCo
}
}
case 'api:github/pulls:list': {
const context = ctx?.context;
if (!context) return { id, type, success: false, error: 'Missing VS Code context' };
const stored = await readGitHubAuth(context);
if (!stored?.accessToken) {
return { id, type, success: true, data: { connected: false } };
}
const directory = readStringField(payload, 'directory');
const page = readNumberField(payload, 'page') ?? 1;
if (!directory) {
return { id, type, success: false, error: 'directory is required' };
}
try {
const result = await listPullRequests(stored.accessToken, directory, page);
if (result.connected === false) {
await clearGitHubAuth(context);
}
return { id, type, success: true, data: result };
} catch (error: unknown) {
const message = error instanceof Error ? error.message : String(error);
return { id, type, success: false, error: message };
}
}
case 'api:github/pulls:context': {
const context = ctx?.context;
if (!context) return { id, type, success: false, error: 'Missing VS Code context' };
const stored = await readGitHubAuth(context);
if (!stored?.accessToken) {
return { id, type, success: true, data: { connected: false } };
}
const directory = readStringField(payload, 'directory');
const number = readNumberField(payload, 'number') ?? 0;
const includeDiff = readBooleanField(payload, 'includeDiff') ?? false;
if (!directory || !number) {
return { id, type, success: false, error: 'directory and number are required' };
}
try {
const result = await getPullRequestContext(stored.accessToken, directory, number, includeDiff);
if (result.connected === false) {
await clearGitHubAuth(context);
}
return { id, type, success: true, data: result };
} catch (error: unknown) {
const message = error instanceof Error ? error.message : String(error);
return { id, type, success: false, error: message };
}
}
case 'api:config/reload': {
await ctx?.manager?.restart();
return { id, type, success: true, data: { restarted: true } };