Edits history of script submission #1404 for ' List workspaces for user (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * List workspaces for user
     * Returns a list of workspaces accessible by the authenticated user.
    
    Results may be further filtered or sorted by
    workspace or permission by adding the following query string parameters:
    
    * `q=slug="bbworkspace1"` or `q=is_private=true`
    * `sort=created_on`
    
    Note that the query parameter values need to be URL escaped so that `=`
    would become `%3D`.
    
    **The `collaborator` role is being removed from the Bitbucket Cloud API. For more information,
    see the deprecation announcement.**
     */
    export async function main(
      auth: Bitbucket,
      role: "owner" | "collaborator" | "member" | undefined,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(`https://api.bitbucket.org/2.0/workspaces`);
      for (const [k, v] of [
        ["role", role],
        ["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 workspaces for user
     * Returns a list of workspaces accessible by the authenticated user.
    
    Results may be further filtered or sorted by
    workspace or permission by adding the following query string parameters:
    
    * `q=slug="bbworkspace1"` or `q=is_private=true`
    * `sort=created_on`
    
    Note that the query parameter values need to be URL escaped so that `=`
    would become `%3D`.
    
    **The `collaborator` role is being removed from the Bitbucket Cloud API. For more information,
    see the deprecation announcement.**
     */
    export async function main(
      auth: Bitbucket,
      role: "owner" | "collaborator" | "member" | undefined,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(`https://api.bitbucket.org/2.0/workspaces`);
      for (const [k, v] of [
        ["role", role],
        ["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 880 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * List workspaces for user
     * Returns a list of workspaces accessible by the authenticated user.
     */
    export async function main(
      auth: Bitbucket,
      role: "owner" | "collaborator" | "member" | undefined,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(`https://api.bitbucket.org/2.0/workspaces`);
      for (const [k, v] of [
        ["role", role],
        ["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 workspaces for user
     * Returns a list of workspaces accessible by the authenticated user.
    
    Example:
    
    ```
    $ curl https://api.bitbucket.org/2.0/workspaces
    
    {
      "pagelen": 10,
      "page": 1,
      "size": 1,
      "values": [
        {
            "uuid": "{a15fb181-db1f-48f7-b41f-e1eff06929d6}",
            "links": {
                "owners": {
                    "href": "https://api.bitbucket.org/2.0/workspaces/bbworkspace1/members?q=permission%3D%22owner%22"
                },
                "self": {
                    "href": "https://api.bitbucket.org/2.0/workspaces/bbworkspace1"
                },
                "repositories": {
                    "href": "https://api.bitbucket.org/2.0/repositories/bbworkspace1"
                },
                "snippets": {
                    "href": "https://api.bitbucket.org/2.0/snippets/bbworkspace1"
                },
                "html": {
                    "href": "https://bitbucket.org/bbworkspace1/"
                },
                "avatar": {
                    "href": "https://bitbucket.org/workspaces/bbworkspace1/avatar/?ts=1543465801"
                },
                "members": {
                    "href": "https://api.bitbucket.org/2.0/workspaces/bbworkspace1/members"
                },
                "projects": {
                    "href": "https://api.bitbucket.org/2.0/workspaces/bbworkspace1/projects"
                }
            },
            "created_on": "2018-11-14T19:15:05.058566+00:00",
            "type": "workspace",
            "slug": "bbworkspace1",
            "is_private": true,
            "name": "Atlassian Bitbucket"
        }
      ]
    }
    ```
    
    Results may be further [filtered or sorted](/cloud/bitbucket/rest/intro/#filtering) by
    workspace or permission by adding the following query string parameters:
    
    * `q=slug="bbworkspace1"` or `q=is_private=true`
    * `sort=created_on`
    
    Note that the query parameter values need to be URL escaped so that `=`
    would become `%3D`.
    
    **The `collaborator` role is being removed from the Bitbucket Cloud API. For more information,
    see the [deprecation announcement](/cloud/bitbucket/deprecation-notice-collaborator-role/).**
     */
    export async function main(
      auth: Bitbucket,
      role: "owner" | "collaborator" | "member" | undefined,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(`https://api.bitbucket.org/2.0/workspaces`);
      for (const [k, v] of [
        ["role", role],
        ["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