Edits history of script submission #1358 for ' List repository permissions for a user (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * List repository permissions for a user
     * Returns an object for each repository the caller has explicit access
    to and their effective permission — the highest level of permission 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/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 repository permissions for a user
     * Returns an object for each repository the caller has explicit access
    to and their effective permission — the highest level of permission 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/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 repository permissions for a user
     * Returns an object for each repository the caller has explicit access
    to and their effective permission — the highest level of permission the
    caller has. This does not return public repositories that the user was
    not granted any specific permission in, and does not distinguish between
    explicit and implicit privileges.
    
    Permissions can be:
    
    * `admin`
    * `write`
    * `read`
    
    Results may be further [filtered or sorted](/cloud/bitbucket/rest/intro/#filtering) by
    repository or permission by adding the following query string
    parameters:
    
    * `q=repository.name="geordi"` or `q=permission>"read"`
    * `sort=repository.name`
    
    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/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