Edits history of script submission #1377 for ' List open branches (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * List open branches
     * Returns a list of all open branches within the specified repository.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      workspace: string,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/refs/branches`
      );
      for (const [k, v] of [
        ["q", q],
        ["sort", sort],
      ]) {
        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;
    };
    /**
     * List open branches
     * Returns a list of all open branches within the specified repository.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      workspace: string,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/refs/branches`
      );
      for (const [k, v] of [
        ["q", q],
        ["sort", sort],
      ]) {
        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

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * List open branches
     * Returns a list of all open branches within the specified repository.
    Results will be in the order the source control manager returns them.
    
    Branches support [filtering and sorting](/cloud/bitbucket/rest/intro/#filtering)
    that can be used to search for specific branches. For instance, to find
    all branches that have "stab" in their name:
    
    ```
    curl -s https://api.bitbucket.org/2.0/repositories/atlassian/aui/refs/branches -G --data-urlencode 'q=name ~ "stab"'
    ```
    
    By default, results will be in the order the underlying source control system returns them and identical to
    the ordering one sees when running "$ git branch --list". Note that this follows simple
    lexical ordering of the ref names.
    
    This can be undesirable as it does apply any natural sorting semantics, meaning for instance that tags are
    sorted ["v10", "v11", "v9"] instead of ["v9", "v10", "v11"].
    
    Sorting can be changed using the ?q= query parameter. When using ?q=name to explicitly sort on ref name,
    Bitbucket will apply natural sorting and interpret numerical values as numbers instead of strings.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      workspace: string,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/refs/branches`
      );
      for (const [k, v] of [
        ["q", q],
        ["sort", sort],
      ]) {
        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