Edits history of script submission #1331 for ' List all repository permissions for a workspace (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * List all repository permissions for a workspace
     * Returns an object for each repository permission for all of a
    workspace's repositories.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/permissions/repositories`
      );
      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 all repository permissions for a workspace
     * Returns an object for each repository permission for all of a
    workspace's repositories.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/permissions/repositories`
      );
      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 all repository permissions for a workspace
     * Returns an object for each repository permission for all of a
    workspace's repositories.
    
    Permissions returned are effective permissions: the highest level of
    permission the user has. This does not distinguish between direct and
    indirect (group) privileges.
    
    Only users with admin permission for the team may access this resource.
    
    Permissions can be:
    
    * `admin`
    * `write`
    * `read`
    
    Results may be further [filtered or sorted](/cloud/bitbucket/rest/intro/#filtering)
    by repository, user, or permission by adding the following query string
    parameters:
    
    * `q=repository.name="geordi"` or `q=permission>"read"`
    * `sort=user.display_name`
    
    Note that the query parameter values need to be URL escaped so that `=`
    would become `%3D`.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/permissions/repositories`
      );
      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