Edits history of script submission #1527 for ' Get snippet changes between versions (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get snippet changes between versions
     * Returns the diff of the specified commit against its first parent.
     */
    export async function main(
      auth: Bitbucket,
      encoded_id: string,
      revision: string,
      workspace: string,
      path: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/snippets/${workspace}/${encoded_id}/${revision}/diff`
      );
      for (const [k, v] of [["path", path]]) {
        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 375 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get snippet changes between versions
     * Returns the diff of the specified commit against its first parent.
     */
    export async function main(
      auth: Bitbucket,
      encoded_id: string,
      revision: string,
      workspace: string,
      path: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/snippets/${workspace}/${encoded_id}/${revision}/diff`
      );
      for (const [k, v] of [["path", path]]) {
        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 935 days ago

  • nativets
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get snippet changes between versions
     * Returns the diff of the specified commit against its first parent.
    
    Note that this resource is different in functionality from the `patch`
    resource.
    
    The differences between a diff and a patch are:
    
    * patches have a commit header with the username, message, etc
    * diffs support the optional `path=foo/bar.py` query param to filter the
      diff to just that one file diff (not supported for patches)
    * for a merge, the diff will show the diff between the merge commit and
      its first parent (identical to how PRs work), while patch returns a
      response containing separate patches for each commit on the second
      parent's ancestry, up to the oldest common ancestor (identical to
      its reachability).
    
    Note that the character encoding of the contents of the diff is
    unspecified as Git does not track this, making it hard for
    Bitbucket to reliably determine this.
     */
    export async function main(
      auth: Bitbucket,
      encoded_id: string,
      revision: string,
      workspace: string,
      path: string | undefined
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/snippets/${workspace}/${encoded_id}/${revision}/diff`
      );
      for (const [k, v] of [["path", path]]) {
        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 935 days ago