0

Unlink a git branch to a Xata branch

by
Published Apr 8, 2025

Removes an entry from the mapping of git branches to Xata branches. The name of the git branch must be passed as a query parameter. If the git branch is not found, the endpoint returns a 404 status code. Example request: ```json // DELETE https://tutorial-ng7s8c.xata.sh/dbs/demo/gitBranches?gitBranch=fix%2Fbug123 ```

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
 * Unlink a git branch to a Xata branch
8
 * Removes an entry from the mapping of git branches to Xata branches. The name of the git branch must be passed as a query parameter. If the git branch is not found, the endpoint returns a 404 status code.
9

10
Example request:
11

12
```json
13
// DELETE https://tutorial-ng7s8c.xata.sh/dbs/demo/gitBranches?gitBranch=fix%2Fbug123
14
```
15

16
 */
17
export async function main(auth: Xata, db_name: string, gitBranch: string | undefined) {
18
	const url = new URL(`${auth.workspaceUrl}/dbs/${db_name}/gitBranches`)
19
	for (const [k, v] of [['gitBranch', gitBranch]]) {
20
		if (v !== undefined && v !== '' && k !== undefined) {
21
			url.searchParams.append(k, v)
22
		}
23
	}
24
	const response = await fetch(url, {
25
		method: 'DELETE',
26
		headers: {
27
			Authorization: 'Bearer ' + auth.apiKey
28
		},
29
		body: undefined
30
	})
31
	if (!response.ok) {
32
		const text = await response.text()
33
		throw new Error(`${response.status} ${text}`)
34
	}
35
	return await response.text()
36
}
37