Edits history of script submission #1508 for ' List workspaces for the current user (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * List workspaces for the current user
     * Returns an object for each workspace the caller is a member of, and
    their effective role - the highest level of privilege the caller has.
     */
    export async function main(
      auth: Bitbucket,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/user/permissions/workspaces`
      );
      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 workspaces for the current user
     * Returns an object for each workspace the caller is a member of, and
    their effective role - the highest level of privilege the caller has.
     */
    export async function main(
      auth: Bitbucket,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/user/permissions/workspaces`
      );
      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 workspaces for the current user
     * Returns an object for each workspace the caller is a member of, and
    their effective role - the highest level of privilege the caller has.
    If a user is a member of multiple groups with distinct roles, only the
    highest level is returned.
    
    Permissions can be:
    
    * `owner`
    * `collaborator`
    * `member`
    
    **The `collaborator` role is being removed from the Bitbucket Cloud API. For more information,
    see the [deprecation announcement](/cloud/bitbucket/deprecation-notice-collaborator-role/).**
    
    **When you move your administration from Bitbucket Cloud to admin.atlassian.com, the following fields on
    `workspace_membership` will no longer be present: `last_accessed` and `added_on`. See the
    [deprecation announcement](/cloud/bitbucket/announcement-breaking-change-workspace-membership/).**
    
    Example:
    
    ```
    $ curl https://api.bitbucket.org/2.0/user/permissions/workspaces
    
    {
      "pagelen": 10,
      "page": 1,
      "size": 1,
      "values": [
        {
          "type": "workspace_membership",
          "permission": "owner",
          "last_accessed": "2019-03-07T12:35:02.900024+00:00",
          "added_on": "2018-10-11T17:42:02.961424+00:00",
          "user": {
            "type": "user",
            "uuid": "{470c176d-3574-44ea-bb41-89e8638bcca4}",
            "nickname": "evzijst",
            "display_name": "Erik van Zijst",
          },
          "workspace": {
            "type": "workspace",
            "uuid": "{a15fb181-db1f-48f7-b41f-e1eff06929d6}",
            "slug": "bbworkspace1",
            "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=workspace.slug="bbworkspace1"` or `q=permission="owner"`
    * `sort=workspace.slug`
    
    Note that the query parameter values need to be URL escaped so that `=`
    would become `%3D`.
     */
    export async function main(
      auth: Bitbucket,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/user/permissions/workspaces`
      );
      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