Edits history of script submission #13928 for ' List git branches mapping (xata)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xata = {
    	apiKey: string
    	workspaceUrl: string
    }
    /**
     * List git branches mapping
     * 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"
          }
      ]
    }
    ```
    
     */
    export async function main(auth: Xata, db_name: string) {
    	const url = new URL(`${auth.workspaceUrl}/dbs/${db_name}/gitBranches`)
    
    	const response = await fetch(url, {
    		method: 'GET',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.json()
    }
    

    Submitted by hugo697 428 days ago