Edits history of script submission #1558 for ' List repositories in a workspace (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * List repositories in a workspace
     * Returns a paginated list of all repositories owned by the specified
    workspace.
    
    The result can be narrowed down based on the authenticated user's role.
    
    E.g. with `?role=contributor`, only those repositories that the
    authenticated user has write access to are returned (this includes any
    repo the user is an admin on, as that implies write access).
    
    This endpoint also supports filtering and sorting of the results. See
    filtering and sorting for more details.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      role: "admin" | "contributor" | "member" | "owner" | undefined,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}`
      );
      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 repositories in a workspace
     * Returns a paginated list of all repositories owned by the specified
    workspace.
    
    The result can be narrowed down based on the authenticated user's role.
    
    E.g. with `?role=contributor`, only those repositories that the
    authenticated user has write access to are returned (this includes any
    repo the user is an admin on, as that implies write access).
    
    This endpoint also supports filtering and sorting of the results. See
    filtering and sorting for more details.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      role: "admin" | "contributor" | "member" | "owner" | undefined,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}`
      );
      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 repositories in a workspace
     * Returns a paginated list of all repositories owned by the specified
    workspace.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      role: "admin" | "contributor" | "member" | "owner" | undefined,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}`
      );
      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 repositories in a workspace
     * Returns a paginated list of all repositories owned by the specified
    workspace.
    
    The result can be narrowed down based on the authenticated user's role.
    
    E.g. with `?role=contributor`, only those repositories that the
    authenticated user has write access to are returned (this includes any
    repo the user is an admin on, as that implies write access).
    
    This endpoint also supports filtering and sorting of the results. See
    [filtering and sorting](/cloud/bitbucket/rest/intro/#filtering) for more details.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      role: "admin" | "contributor" | "member" | "owner" | undefined,
      q: string | undefined,
      sort: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}`
      );
      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