Edits history of script submission #1484 for ' Compare two commits (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Compare two commits
     * Produces a raw git-style diff.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      spec: string,
      workspace: string,
      context: string | undefined,
      path: string | undefined,
      ignore_whitespace: string | undefined,
      binary: string | undefined,
      renames: string | undefined,
      merge: string | undefined,
      topic: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/diff/${spec}`
      );
      for (const [k, v] of [
        ["context", context],
        ["path", path],
        ["ignore_whitespace", ignore_whitespace],
        ["binary", binary],
        ["renames", renames],
        ["merge", merge],
        ["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.text();
    }
    

    Submitted by hugo697 386 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Compare two commits
     * Produces a raw git-style diff.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      spec: string,
      workspace: string,
      context: string | undefined,
      path: string | undefined,
      ignore_whitespace: string | undefined,
      binary: string | undefined,
      renames: string | undefined,
      merge: string | undefined,
      topic: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/diff/${spec}`
      );
      for (const [k, v] of [
        ["context", context],
        ["path", path],
        ["ignore_whitespace", ignore_whitespace],
        ["binary", binary],
        ["renames", renames],
        ["merge", merge],
        ["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.text();
    }
    

    Submitted by hugo697 947 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Compare two commits
     * Produces a raw git-style diff.
    
    #### 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`.
    
    #### Comparison to patches
    
    While similar to patches, diffs:
    
    * Don't have a commit header (username, commit message, etc)
    * Support the optional `path=foo/bar.py` query param to filter
      the diff to just that one file diff
    
    #### Response
    
    The raw diff is returned as-is, in whatever encoding the files in the
    repository use. It is not decoded into unicode. As such, the
    content-type is `text/plain`.
     */
    export async function main(
      auth: Bitbucket,
      repo_slug: string,
      spec: string,
      workspace: string,
      context: string | undefined,
      path: string | undefined,
      ignore_whitespace: string | undefined,
      binary: string | undefined,
      renames: string | undefined,
      merge: string | undefined,
      topic: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/diff/${spec}`
      );
      for (const [k, v] of [
        ["context", context],
        ["path", path],
        ["ignore_whitespace", ignore_whitespace],
        ["binary", binary],
        ["renames", renames],
        ["merge", merge],
        ["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.text();
    }
    

    Submitted by hugo697 947 days ago