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
+8 -1
View File
@@ -17,6 +17,8 @@ type GitHubIssuesListResult = {
author?: { login: string; id?: number; avatarUrl?: string; name?: string; email?: string } | null;
labels?: Array<{ name: string; color?: string }>;
}>;
page?: number;
hasMore?: boolean;
};
type GitHubIssueGetResult = {
@@ -102,6 +104,7 @@ const mapLabels = (raw: unknown): Array<{ name: string; color?: string }> => {
export const listIssues = async (
accessToken: string,
directory: string,
page: number = 1,
): Promise<GitHubIssuesListResult> => {
const repo = await resolveRepoFromDirectory(directory);
if (!repo) {
@@ -111,12 +114,16 @@ export const listIssues = async (
const url = new URL(`${API_BASE}/repos/${repo.owner}/${repo.repo}/issues`);
url.searchParams.set('state', 'open');
url.searchParams.set('per_page', '50');
url.searchParams.set('page', String(page));
const resp = await githubFetch(url.toString(), accessToken);
if (resp.status === 401) {
return { connected: false };
}
const link = resp.headers.get('link') || '';
const hasMore = /rel="next"/.test(link);
const json = await jsonOrNull<unknown[]>(resp);
if (!resp.ok || !Array.isArray(json)) {
throw new Error('Failed to load issues');
@@ -140,7 +147,7 @@ export const listIssues = async (
})
.filter(Boolean) as GitHubIssuesListResult['issues'];
return { connected: true, repo, issues: issues || [] };
return { connected: true, repo, issues: issues || [], page, hasMore };
};
export const getIssue = async (