Edits history of script submission #17528 for ' Unlink site repo (netlify)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Netlify = {
      token: string;
    };
    /**
     * Unlink site repo
     * [Beta] Unlinks the repo from the site.
    
    This action will also:
    - Delete associated deploy keys
    - Delete outgoing webhooks for the repo
    - Delete the site's build hooks
     */
    export async function main(auth: Netlify, site_id: string) {
      const url = new URL(
        `https://api.netlify.com/api/v1/sites/${site_id}/unlink_repo`,
      );
    
      const response = await fetch(url, {
        method: "PUT",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 235 days ago