import type { ApiContext } from "./context.js"; import type { Paginated } from "./http/pagination.js"; import type { PullRequest as BasePullRequest, PullRequestActivity } from "../generated/types.js"; export type PullRequest = BasePullRequest & { version: number; author?: { user?: { name?: string; slug?: string; displayName?: string; }; }; fromRef: { id: string; displayId: string; latestCommit: string; repository: { slug: string; project: { key: string; }; }; }; toRef: { id: string; displayId: string; repository: { slug: string; project: { key: string; }; }; }; }; export type Activity = PullRequestActivity & { comment?: { author?: { name: string; }; }; }; export interface ReviewerEntry { user: { name: string; }; } export type PullRequestState = "OPEN" | "MERGED" | "DECLINED" | "ALL"; export type ActivityFilter = "all" | "reviews" | "comments"; export interface PullRequestTarget { project?: string; repository: string; prId: number; } export interface CreatePullRequestParams { project?: string; repository: string; title: string; description?: string; sourceBranch: string; targetBranch: string; sourceProject?: string; sourceRepository?: string; reviewers?: string[]; includeDefaultReviewers?: boolean; draft?: boolean; } export type GetPullRequestParams = PullRequestTarget; export interface UpdatePullRequestParams extends PullRequestTarget { title?: string; description?: string; targetBranch?: string; reviewers?: string[]; } export interface MergePullRequestParams extends PullRequestTarget { message?: string; strategy?: string; } export interface DeclinePullRequestParams extends PullRequestTarget { message?: string; } export interface ListPullRequestsParams { project?: string; repository: string; state?: PullRequestState; author?: string; direction?: "INCOMING" | "OUTGOING"; order?: "OLDEST" | "NEWEST"; limit?: number; start?: number; } export interface ListDashboardParams { state?: PullRequestState; role?: "AUTHOR" | "REVIEWER" | "PARTICIPANT"; participantStatus?: "APPROVED" | "UNAPPROVED" | "NEEDS_WORK"; order?: "OLDEST" | "NEWEST"; closedSince?: number; limit?: number; start?: number; } export interface GetActivityParams extends PullRequestTarget { filter?: ActivityFilter; excludeUsers?: string[]; limit?: number; start?: number; } export type GetDiffStatParams = PullRequestTarget; export interface DiffStat { files: Array<{ path: string; type: string; }>; totalFiles: number; summary?: Record; } export interface GetDiffParams extends PullRequestTarget { filePath?: string; contextLines?: number; } export interface ListPullRequestPageParams extends PullRequestTarget { limit?: number; start?: number; } export interface ListForCommitParams { project?: string; repository: string; commitId: string; limit?: number; start?: number; } export interface PublishReviewParams extends PullRequestTarget { commentText?: string; participantStatus?: "APPROVED" | "NEEDS_WORK"; } interface DefaultReviewerParams { ctx: ApiContext; targetProject: string; repository: string; sourceProject: string; sourceRepository: string; sourceBranch: string; targetBranch: string; existingReviewers: ReviewerEntry[]; } /** * Add the repository's configured default reviewers to an explicit list, * skipping anyone already present. Bitbucket resolves them from the * source/target repository ids, so both have to be looked up first. A failure * anywhere here is not fatal: the pull request is still created with the * explicit reviewers. */ export declare function mergeDefaultReviewers({ ctx, targetProject, repository, sourceProject, sourceRepository, sourceBranch, targetBranch, existingReviewers, }: DefaultReviewerParams): Promise; export declare function pullRequestsApi(ctx: ApiContext): { create({ project, repository, title, description, sourceBranch, targetBranch, sourceProject, sourceRepository, reviewers, includeDefaultReviewers, draft, }: CreatePullRequestParams): Promise>; get(target: GetPullRequestParams): Promise; /** Merge vetoes and conflict state. Null when the endpoint refuses. */ getMergeStatus(target: PullRequestTarget): Promise | null>; /** * Aggregated CI status per commit, from the UI-layer endpoint. Null on * deployments that do not expose it. */ getBuildSummaries(target: PullRequestTarget): Promise | null>; /** * Sends only the fields the PUT endpoint accepts: echoing the whole pull * request back causes a 400 because the API rejects fields like `author`. */ update({ title, description, targetBranch, reviewers, ...target }: UpdatePullRequestParams): Promise>; merge({ message, strategy, ...target }: MergePullRequestParams): Promise>; decline({ message, ...target }: DeclinePullRequestParams): Promise>; /** * `author` filters the fetched page in memory because Bitbucket has no * author query on this endpoint, so `size` reports the matches on that * page rather than the server-side total. */ list({ project, repository, state, author, direction, order, limit, start, }: ListPullRequestsParams): Promise>; listDashboard({ state, role, participantStatus, order, closedSince, limit, start, }: ListDashboardParams): Promise>>; getActivity({ filter, excludeUsers, limit, start, ...target }: GetActivityParams): Promise>; /** * The line-count summary needs Bitbucket DC 9.1+, so it is omitted rather * than failing the whole call on older servers. */ getDiffStat(target: GetDiffStatParams): Promise; /** * The unified diff as Bitbucket returns it. Trimming it to fit a context * budget is the caller's decision, so `truncateDiff` is exported * separately rather than applied here. */ getDiff({ filePath, contextLines, ...target }: GetDiffParams): Promise; listCommits({ limit, start, ...target }: ListPullRequestPageParams): Promise>>; listForCommit({ project, repository, commitId, limit, start, }: ListForCommitParams): Promise>>; approve(target: PullRequestTarget): Promise; unapprove(target: PullRequestTarget): Promise<{ unapproved: true; prId: number; }>; publishReview({ commentText, participantStatus, ...target }: PublishReviewParams): Promise; }; export type PullRequestsApi = ReturnType; export {};