CodeIssuesDiscussionsWikiPull RequestsProjectsCommitsActionsReleasesContributorsPulse● GatesSecuritySettingsDeploymentsPipelineInsightsAgents✨ Explain✨ Ask AI✨ Workspace✨ Spec✨ Tests▓ Debt Map✨ NL Search🏛 Archaeology
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | import { fetchJSON, postJSON } from './client';
export interface PullRequest {
id: number;
number: number;
title: string;
body: string | null;
state: 'open' | 'closed' | 'merged';
authorUsername: string;
authorAvatarUrl: string | null;
baseBranch: string;
headBranch: string;
baseRepo: string;
headRepo: string;
isDraft: boolean;
commentCount: number;
commitCount: number;
additions: number;
deletions: number;
changedFiles: number;
mergedAt: string | null;
closedAt: string | null;
createdAt: string;
updatedAt: string;
mergedByUsername: string | null;
gateStatus: 'pending' | 'passed' | 'failed' | 'none';
}
export interface PrComment {
id: number;
body: string;
authorUsername: string;
authorAvatarUrl: string | null;
isAiReview: boolean;
filePath: string | null;
lineNumber: number | null;
diffHunk: string | null;
createdAt: string;
updatedAt: string;
}
export interface AiReviewSummary {
summary: string;
comments: PrComment[];
severity: 'info' | 'warning' | 'error';
createdAt: string;
}
export interface PrDiffFile {
path: string;
additions: number;
deletions: number;
patch: string;
}
export interface CreatePrInput {
title: string;
body?: string;
baseBranch: string;
headBranch: string;
isDraft?: boolean;
}
export interface CreatePrCommentInput {
body: string;
filePath?: string;
lineNumber?: number;
diffHunk?: string;
}
/** List pull requests for a repository. */
export async function listPullRequests(
owner: string,
repo: string,
state: 'open' | 'closed' | 'merged' | 'all' = 'open',
page = 1,
): Promise<PullRequest[]> {
return fetchJSON<PullRequest[]>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls?state=${state}&page=${page}&json=1`,
);
}
/** Get a single pull request. */
export async function getPullRequest(
owner: string,
repo: string,
number: number,
): Promise<PullRequest> {
return fetchJSON<PullRequest>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${number}?json=1`,
);
}
/** Get comments on a pull request (including AI review comments). */
export async function getPrComments(
owner: string,
repo: string,
number: number,
): Promise<PrComment[]> {
return fetchJSON<PrComment[]>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${number}/comments?json=1`,
);
}
/** Get the AI review summary for a pull request. */
export async function getAiReview(
owner: string,
repo: string,
number: number,
): Promise<AiReviewSummary | null> {
try {
return await fetchJSON<AiReviewSummary>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${number}/ai-review?json=1`,
);
} catch {
return null;
}
}
/** Get diff files for a pull request. */
export async function getPrDiff(
owner: string,
repo: string,
number: number,
): Promise<PrDiffFile[]> {
return fetchJSON<PrDiffFile[]>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${number}/diff?json=1`,
);
}
/** Create a new pull request. */
export async function createPullRequest(
owner: string,
repo: string,
input: CreatePrInput,
): Promise<PullRequest> {
return postJSON<PullRequest>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls`,
input,
);
}
/** Post a comment on a pull request. */
export async function createPrComment(
owner: string,
repo: string,
number: number,
input: CreatePrCommentInput,
): Promise<PrComment> {
return postJSON<PrComment>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${number}/comments`,
input,
);
}
/** Merge a pull request. */
export async function mergePullRequest(
owner: string,
repo: string,
number: number,
mergeMethod: 'merge' | 'squash' | 'rebase' = 'merge',
): Promise<{ merged: boolean; sha: string }> {
return postJSON<{ merged: boolean; sha: string }>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${number}/merge`,
{ mergeMethod },
);
}
/** Close a pull request without merging. */
export async function closePullRequest(
owner: string,
repo: string,
number: number,
): Promise<PullRequest> {
return postJSON<PullRequest>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${number}/close`,
{},
);
}
/** Trigger AI review on a pull request. */
export async function requestAiReview(
owner: string,
repo: string,
number: number,
): Promise<{ queued: boolean }> {
return postJSON<{ queued: boolean }>(
`/${encodeURIComponent(owner)}/${encodeURIComponent(repo)}/pulls/${number}/request-ai-review`,
{},
);
}
|