0

Update branch metadata

by
Published Apr 8, 2025

Update the branch metadata

Script xata Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Xata = {
3
	apiKey: string
4
	workspaceUrl: string
5
}
6
/**
7
 * Update branch metadata
8
 * Update the branch metadata
9
 */
10
export async function main(
11
	auth: Xata,
12
	db_branch_name: string,
13
	body: {
14
		repository?: string
15
		branch?: string
16
		stage?: string
17
		labels?: string[]
18
	}
19
) {
20
	const url = new URL(`${auth.workspaceUrl}/db/${db_branch_name}/metadata`)
21

22
	const response = await fetch(url, {
23
		method: 'PUT',
24
		headers: {
25
			'Content-Type': 'application/json',
26
			Authorization: 'Bearer ' + auth.apiKey
27
		},
28
		body: JSON.stringify(body)
29
	})
30
	if (!response.ok) {
31
		const text = await response.text()
32
		throw new Error(`${response.status} ${text}`)
33
	}
34
	return await response.text()
35
}
36