Edits history of script submission #1488 for ' Compare two commit diff stats (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Compare two commit diff stats
     * Produces a response in JSON format with a record for every path
    modified, including information on the type of the change and the
    number of lines added and removed.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      spec: string,
      workspace: string,
      ignore_whitespace: string | undefined,
      merge: string | undefined,
      path: string | undefined,
      renames: string | undefined,
      topic: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/diffstat/${spec}`
      );
      for (const [k, v] of [
        ["ignore_whitespace", ignore_whitespace],
        ["merge", merge],
        ["path", path],
        ["renames", renames],
        ["topic", topic],
      ]) {
        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;
    };
    /**
     * Compare two commit diff stats
     * Produces a response in JSON format with a record for every path
    modified, including information on the type of the change and the
    number of lines added and removed.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      spec: string,
      workspace: string,
      ignore_whitespace: string | undefined,
      merge: string | undefined,
      path: string | undefined,
      renames: string | undefined,
      topic: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/diffstat/${spec}`
      );
      for (const [k, v] of [
        ["ignore_whitespace", ignore_whitespace],
        ["merge", merge],
        ["path", path],
        ["renames", renames],
        ["topic", topic],
      ]) {
        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;
    };
    /**
     * Compare two commit diff stats
     * Produces a response in JSON format with a record for every path
    modified, including information on the type of the change and the
    number of lines added and removed.
    
    #### Single commit spec
    
    If the `spec` argument to this API is a single commit, the diff is
    produced against the first parent of the specified commit.
    
    #### Two commit spec
    
    Two commits separated by `..` may be provided as the `spec`, e.g.,
    `3a8b42..9ff173`. When two commits are provided and the `topic` query
    parameter is true, this API produces a 2-way three dot diff.
    This is the diff between source commit and the merge base of the source
    commit and the destination commit. When the `topic` query param is false,
    a simple git-style diff is produced.
    
    The two commits are interpreted as follows:
    
    * First commit: the commit containing the changes we wish to preview
    * Second commit: the commit representing the state to which we want to
      compare the first commit
    * **Note**: This is the opposite of the order used in `git diff`.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      spec: string,
      workspace: string,
      ignore_whitespace: string | undefined,
      merge: string | undefined,
      path: string | undefined,
      renames: string | undefined,
      topic: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/diffstat/${spec}`
      );
      for (const [k, v] of [
        ["ignore_whitespace", ignore_whitespace],
        ["merge", merge],
        ["path", path],
        ["renames", renames],
        ["topic", topic],
      ]) {
        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