Edits history of script submission #1538 for ' Search for code in a workspace (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Search for code in a workspace
     * Search for code in the repositories of the specified workspace.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      search_query: string | undefined,
      page: string | undefined,
      pagelen: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/search/code`
      );
      for (const [k, v] of [
        ["search_query", search_query],
        ["page", page],
        ["pagelen", pagelen],
      ]) {
        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;
    };
    /**
     * Search for code in a workspace
     * Search for code in the repositories of the specified workspace.
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      search_query: string | undefined,
      page: string | undefined,
      pagelen: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/search/code`
      );
      for (const [k, v] of [
        ["search_query", search_query],
        ["page", page],
        ["pagelen", pagelen],
      ]) {
        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;
    };
    /**
     * Search for code in a workspace
     * Search for code in the repositories of the specified workspace.
    
    Note that searches can match in the file's text (`content_matches`),
    the path (`path_matches`), or both.
    
    You can use the same syntax for the search query as in the UI.
    E.g. to search for "foo" only within the repository "demo",
    use the query parameter `search_query=foo+repo:demo`.
    
    Similar to other APIs, you can request more fields using a
    `fields` query parameter. E.g. to get some more information about
    the repository of matched files, use the query parameter
    `search_query=foo&fields=%2Bvalues.file.commit.repository`
    (the `%2B` is a URL-encoded `+`).
    
    Try `fields=%2Bvalues.*.*.*.*` to get an idea what's possible.
    
     */
    export async function main(
      auth: Bitbucket,
      workspace: string,
      search_query: string | undefined,
      page: string | undefined,
      pagelen: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/workspaces/${workspace}/search/code`
      );
      for (const [k, v] of [
        ["search_query", search_query],
        ["page", page],
        ["pagelen", pagelen],
      ]) {
        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