0

List git branches mapping

by
Published Apr 8, 2025

Lists all the git branches in the mapping, and their associated Xata branches. Example response: ```json { "mappings": [ { "gitBranch": "main", "xataBranch": "main" }, { "gitBranch": "gitBranch1", "xataBranch": "xataBranch1" } { "gitBranch": "xataBranch2", "xataBranch": "xataBranch2" } ] } ```

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
 * List git branches mapping
8
 * Lists all the git branches in the mapping, and their associated Xata branches.
9

10
Example response:
11

12
```json
13
{
14
  "mappings": [
15
      {
16
        "gitBranch": "main",
17
        "xataBranch": "main"
18
      },
19
      {
20
        "gitBranch": "gitBranch1",
21
        "xataBranch": "xataBranch1"
22
      }
23
      {
24
        "gitBranch": "xataBranch2",
25
        "xataBranch": "xataBranch2"
26
      }
27
  ]
28
}
29
```
30

31
 */
32
export async function main(auth: Xata, db_name: string) {
33
	const url = new URL(`${auth.workspaceUrl}/dbs/${db_name}/gitBranches`)
34

35
	const response = await fetch(url, {
36
		method: 'GET',
37
		headers: {
38
			Authorization: 'Bearer ' + auth.apiKey
39
		},
40
		body: undefined
41
	})
42
	if (!response.ok) {
43
		const text = await response.text()
44
		throw new Error(`${response.status} ${text}`)
45
	}
46
	return await response.json()
47
}
48