Repository navigation
Expand file tree
/
Copy pathpull-requests.ts
More file actions
56 lines (53 loc) · 1.74 KB
/
Copy pathpull-requests.ts
File metadata and controls
56 lines (53 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import type { ApiFetchOptions } from './client.js';
import { ghApiGet } from './gh.js';
import { gitDocumentKey, gitProjectQuery, type GitProjectTarget } from './git-client.js';
import type { PullRequestDetail as PullRequestDetailWire, PullRequestListResult } from '$shared/gh';
import type { GitReviewFileBody } from './git.js';
import { createIndexedGitReviewFileBody } from '$lib/git/review/git-review-body-index.js';
export type {
PullRequestState,
PullRequestChecksState,
PullRequestReviewDecision,
PullRequestMergeable,
PullRequestThreadSide,
PullRequestCheckState,
PullRequestSummary,
PullRequestListResult,
PullRequestReviewCommentItem,
PullRequestThread,
PullRequestCheck,
} from '$shared/gh';
export interface PullRequestDetail extends Omit<PullRequestDetailWire, 'fileBodies'> {
documentId: string;
fileBodies: Record<string, GitReviewFileBody>;
}
export async function getPullRequests(
target: GitProjectTarget,
options?: ApiFetchOptions,
): Promise<PullRequestListResult> {
return ghApiGet(target.executorId, `/api/v1/gh/pull-requests?${gitProjectQuery(target)}`, options);
}
export async function getPullRequest(
target: GitProjectTarget,
number: number,
options?: ApiFetchOptions,
): Promise<PullRequestDetail> {
const detail = await ghApiGet<PullRequestDetailWire>(
target.executorId,
`/api/v1/gh/pull-request?${gitProjectQuery(target)}&number=${encodeURIComponent(number)}`,
{ timeoutMs: 60_000, ...options },
);
return {
...detail,
documentId: gitDocumentKey({
...detail,
documentId: JSON.stringify([target.projectPath, detail.number, detail.updatedAt]),
}),
fileBodies: Object.fromEntries(
Object.entries(detail.fileBodies).map(([path, body]) => [
path,
createIndexedGitReviewFileBody(body),
]),
),
};
}