type Bitbucket = {
username: string;
password: string;
};
/**
* Update a previous revision of a snippet
* Identical to `UPDATE /snippets/encoded_id`, except that this endpoint
takes an explicit commit revision.
*/
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: "PUT",
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 319 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* Update a previous revision of a snippet
* Identical to `UPDATE /snippets/encoded_id`, except that this endpoint
takes an explicit commit revision. Only the snippet's "HEAD"/"tip"
(most recent) version can be updated and requests on all other,
older revisions fail by returning a 405 status.
Usage of this endpoint over the unrestricted `/snippets/encoded_id`
could be desired if the caller wants to be sure no concurrent
modifications have taken place between the moment of the UPDATE
request and the original GET.
This can be considered a so-called "Compare And Swap", or CAS
operation.
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: "PUT",
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 320 days ago