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/add-environment-repo.ts

24 lines · 943 B · TypeScript
import { assertEnvironmentId, boxRequest, failure, type Result } from './client.ts'
import type { EnvironmentMutationOutput } from './set-environment-var.ts'

export type AddEnvironmentRepoInput = {
	environmentId: string
	/** The repository databaseId from listRepos. */
	repositoryId: string
	baseBranch?: string
}

/** Add a repository, or update its base branch. Mints a new immutable version. */
export default async function addEnvironmentRepo(
	input: AddEnvironmentRepoInput,
): Promise<Result<EnvironmentMutationOutput>> {
	const invalid = assertEnvironmentId(input?.environmentId)
	if (invalid) return failure<EnvironmentMutationOutput>(invalid)
	const body: Record<string, unknown> = { repositoryId: input.repositoryId }
	if (input.baseBranch !== undefined) body.baseBranch = input.baseBranch
	return boxRequest<EnvironmentMutationOutput>({
		path: '/environments/' + input.environmentId + '/repos',
		method: 'POST',
		body,
	})
}