UNPKG

@sleavely/bitbucket

Version:

Client and utils for Bitbucket Cloud REST APIs

88 lines (87 loc) 5.12 kB
import { type ExtendOptions, type Got } from 'got'; import { type IAccount, type ICommitStatus, type IDefaultReviewerAndType, type IPipeline, type IPullRequest, type ICodeSearchResult, type IProject, type IRepository, type IWorkspace, type IPipelineVariable, type IDefaultReviewer } from './types/api'; interface BitbucketClientOptions { auth: { username: string; password: string; }; } /** * A workspace ID (slug) or its UUID surrounded by curly-braces, for example: {workspace UUID} */ type WorkspaceIdentifier = string; /** * A username or a UUID surrounded by curly-braces, for example: {account UUID}. */ type UserIdentifier = string; export declare class BitbucketClient { client: Got; constructor(opts: BitbucketClientOptions); extend(gotOpts: ExtendOptions): void; getCurrentUser(): Promise<IAccount>; listWorkspaces(): Promise<Array<IWorkspace & { permission: string; }>>; getWorkspace(workspace: WorkspaceIdentifier): Promise<IWorkspace>; getProject(workspace: WorkspaceIdentifier, projectKey: string): Promise<IProject>; getRepositoriesByProject(workspace: WorkspaceIdentifier, projectKey: string, requestPage?: number): Promise<IRepository[]>; getRepository(workspace: WorkspaceIdentifier, repoSlug: string): Promise<IRepository>; /** * @deprecated This only returns repo-level defaults, not inherited ones. Use getEffectiveDefaultReviewers instead. * @see getEffectiveDefaultReviewers */ getDefaultReviewers(workspace: WorkspaceIdentifier, repoSlug: string): Promise<IAccount[]>; /** * Adds the specified user to the repository's list of default reviewers. This method is idempotent. Adding a user a second time has no effect. */ addDefaultReviewer(workspace: WorkspaceIdentifier, repoSlug: string, targetUser: UserIdentifier): Promise<IAccount>; removeDefaultReviewer(workspace: WorkspaceIdentifier, repoSlug: string, targetUser: UserIdentifier): Promise<void>; /** * Includes both default reviewers defined at the repository level as well as those inherited from its project. */ getEffectiveDefaultReviewers(workspace: WorkspaceIdentifier, repoSlug: string): Promise<Array<IDefaultReviewer & { reviewer_type: IDefaultReviewerAndType['reviewer_type']; }>>; /** * Gets 10 most recent pipelines that were created */ getPipelines(workspace: WorkspaceIdentifier, repoSlug: string): Promise<IPipeline[]>; getPipeline(workspace: WorkspaceIdentifier, repoSlug: string, pipelineUuid: string): Promise<IPipeline>; getCommitStatuses(workspace: WorkspaceIdentifier, repoSlug: string, commit: string): Promise<ICommitStatus[]>; /** * Returns repository level variables */ getRepoVariables(workspace: WorkspaceIdentifier, repoSlug: string): Promise<IPipelineVariable[]>; /** * Regardless of whether it exists or not */ setRepoVariable(workspace: string, repoSlug: string, varName: string, varValue: string): Promise<IPipelineVariable>; createRepoVariable(workspace: WorkspaceIdentifier, repoSlug: string, varName: string, varValue: string): Promise<IPipelineVariable>; updateRepoVariable(workspace: WorkspaceIdentifier, repoSlug: string, varUuid: string, varName: string, varValue: string): Promise<IPipelineVariable>; deleteRepoVariable(workspace: string, repoSlug: string, varName: string): Promise<unknown>; createPullRequest(workspace: WorkspaceIdentifier, repoSlug: string, title: string, sourceBranch: string, destinationBranch?: string): Promise<IPullRequest>; getFile(workspace: WorkspaceIdentifier, repoSlug: string, commitOrRef: string, filePath: string): Promise<string | null>; /** * @param workspace * @param repoSlug * @param filePath A file path in the repository * @param contents * @param message The commit message * @param author Should be in format of `Joakim Hedlund <contact@joakimhedlund.com>`. Defaults to the current user. * @param branch The name of the branch that the new commit should be created on. When omitted, the commit will be created on top of the main branch * @returns Full commit hash */ commitFile(workspace: WorkspaceIdentifier, repoSlug: string, filePath: string, contents: string, message?: string, author?: string, branch?: string): Promise<string>; /** * @param workspace * @param repoSlug * @param filePath A file path in the repository * @param message The commit message * @param author Should be in format of `Joakim Hedlund <contact@joakimhedlund.com>`. Defaults to the current user. * @param branch The name of the branch that the new commit should be created on. When omitted, the commit will be created on top of the main branch * @returns Full commit hash */ removeFile(workspace: WorkspaceIdentifier, repoSlug: string, filePath: string, message?: string, author?: string, branch?: string): Promise<string>; codeSearch(workspace: WorkspaceIdentifier, query: string, requestPage?: number): Promise<ICodeSearchResult[]>; } export {};