Edits history of script submission #1285 for ' Get a previous revision of a snippet (bitbucket)'

  • nativets
    One script reply has been approved by the moderators
    Ap­pro­ved
    type Bitbucket = {
      username: string;
      password: string;
    };
    /**
     * Get a previous revision of a snippet
     * Identical to `GET /snippets/encoded_id`, except that this endpoint
    can be used to retrieve the contents of the snippet as it was at an
    older revision, while `/snippets/encoded_id` always returns the
    snippet's current revision.
    
    Note that only the snippet's file contents are versioned, not its
    meta data properties like the title.
    
    Other than that, the two endpoints are identical in behavior.
     */
    export async function main(
      auth: Bitbucket,
      encoded_id: string,
      node_id: string,
      workspace: string
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/snippets/${workspace}/${encoded_id}/${node_id}`
      );
    
      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;
    };
    /**
     * Get a previous revision of a snippet
     * Identical to `GET /snippets/encoded_id`, except that this endpoint
    can be used to retrieve the contents of the snippet as it was at an
    older revision, while `/snippets/encoded_id` always returns the
    snippet's current revision.
    
    Note that only the snippet's file contents are versioned, not its
    meta data properties like the title.
    
    Other than that, the two endpoints are identical in behavior.
     */
    export async function main(
      auth: Bitbucket,
      encoded_id: string,
      node_id: string,
      workspace: string
    ) {
      const url = new URL(
        `https://api.bitbucket.org/2.0/snippets/${workspace}/${encoded_id}/${node_id}`
      );
    
      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