Edits history of script submission #1316 for ' Get the root directory of the main branch (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get the root directory of the main branch
     * This endpoint redirects the client to the directory listing of the
    root directory on the main branch.
    
    This is equivalent to directly hitting
    [/2.0/repositories/{username}/{repo_slug}/src/{commit}/{path}](src/%7Bcommit%7D/%7Bpath%7D)
    without having to know the name or SHA1 of the repo's main branch.
    
    To create new commits, [POST to this endpoint](#post)
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      workspace: string,
      format: "meta" | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/src`
      );
      for (const [k, v] of [["format", format]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 375 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get the root directory of the main branch
     * This endpoint redirects the client to the directory listing of the
    root directory on the main branch.
    
    This is equivalent to directly hitting
    [/2.0/repositories/{username}/{repo_slug}/src/{commit}/{path}](src/%7Bcommit%7D/%7Bpath%7D)
    without having to know the name or SHA1 of the repo's main branch.
    
    To create new commits, [POST to this endpoint](#post)
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      workspace: string,
      format: "meta" | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/src`
      );
      for (const [k, v] of [["format", format]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 802 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get the root directory of the main branch
     * This endpoint redirects the client to the directory listing of the
    root directory on the main branch.
    
    This is equivalent to directly hitting
    [/2.0/repositories/{username}/{repo_slug}/src/{commit}/{path}](src/%7Bcommit%7D/%7Bpath%7D)
    without having to know the name or SHA1 of the repo's main branch.
    
    To create new commits, POST to this endpoint
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      workspace: string,
      format: "meta" | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/src`
      );
      for (const [k, v] of [["format", format]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 880 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get the root directory of the main branch
     * This endpoint redirects the client to the directory listing of the
    root directory on the main branch.
    
    This is equivalent to directly hitting
    [/2.0/repositories/{username}/{repo_slug}/src/{commit}/{path}](src/%7Bcommit%7D/%7Bpath%7D)
    without having to know the name or SHA1 of the repo's main branch.
    
    To create new commits, [POST to this endpoint](#post)
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      workspace: string,
      format: "meta" | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/src`
      );
      for (const [k, v] of [["format", format]]) {
        if (v !== undefined && v !== "") {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "GET",
        headers: {
          Authorization: "Basic " + btoa(`${auth.username}:${auth.password}`),
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 935 days ago