Skip to content
← Public packages

@cameronpak/box

Full Box Public API v1 client: lifecycle, prompts, files, commands, snapshots, environments, webhooks, desktop, hosting, and account.

src/select-repo.ts

25 lines · 904 B · TypeScript
import { boxRequest, type Result } from './client.ts'
import type { SelectedRepository } from './types.ts'

export type SelectRepoInput = {
	/** Internal repository databaseId returned by listRepos. */
	repositoryId: string
	baseBranch?: string
}

export type SelectRepoOutput = {
	success: boolean
	environmentId?: string
	selectedRepositories?: Array<SelectedRepository>
}

/**
 * Idempotently select one repository for the default Box environment.
 * Use databaseId from listRepos as repositoryId. Selecting an already-selected
 * repository updates its baseBranch.
 */
export default async function selectRepo(input: SelectRepoInput): Promise<Result<SelectRepoOutput>> {
	const body: Record<string, unknown> = { repositoryId: input.repositoryId }
	if (input.baseBranch !== undefined) body.baseBranch = input.baseBranch
	return boxRequest<SelectRepoOutput>({ path: '/repos', method: 'POST', body })
}