Edits history of script submission #13940 for ' Unlink a git branch to a Xata branch (xata)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Xata = {
    	apiKey: string
    	workspaceUrl: string
    }
    /**
     * Unlink a git branch to a Xata branch
     * 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
    ```
    
     */
    export async function main(auth: Xata, db_name: string, gitBranch: string | undefined) {
    	const url = new URL(`${auth.workspaceUrl}/dbs/${db_name}/gitBranches`)
    	for (const [k, v] of [['gitBranch', gitBranch]]) {
    		if (v !== undefined && v !== '' && k !== undefined) {
    			url.searchParams.append(k, v)
    		}
    	}
    	const response = await fetch(url, {
    		method: 'DELETE',
    		headers: {
    			Authorization: 'Bearer ' + auth.apiKey
    		},
    		body: undefined
    	})
    	if (!response.ok) {
    		const text = await response.text()
    		throw new Error(`${response.status} ${text}`)
    	}
    	return await response.text()
    }
    

    Submitted by hugo697 428 days ago