Edits history of script submission #1521 for ' List a 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 a repository permissions for a workspace
     * Returns an object for the repository permission of each user in the
    requested 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/workspaces/${workspace}/permissions/repositories/${repo_slug}`
      );
      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 a repository permissions for a workspace
     * Returns an object for the repository permission of each user in the
    requested 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/workspaces/${workspace}/permissions/repositories/${repo_slug}`
      );
      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 a repository permissions for a workspace
     * Returns an object for the repository permission of each user in the
    requested repository.
    
    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 repository may access this resource.
    
    Permissions can be:
    
    * `admin`
    * `write`
    * `read`
    
    Results may be further [filtered or sorted](/cloud/bitbucket/rest/intro/#filtering)
    by user, or permission by adding the following query string parameters:
    
    * `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,
      repo_slug: string,
      workspace: string,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/permissions/repositories/${repo_slug}`
      );
      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