type Bitbucket = {
username: string;
password: string;
};
/**
* List snippets in a workspace
* Identical to `/snippets`, except that the result is further filtered
by the snippet owner and only those that are owned by `{workspace}` are
returned.
*/
export async function main(
auth: Bitbucket,
workspace: string,
role: "owner" | "contributor" | "member" | undefined
) {
const url = new URL(`https://api.bitbucket.org/2.0/snippets/${workspace}`);
for (const [k, v] of [["role", role]]) {
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 352 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* List snippets in a workspace
* Identical to [`/snippets`](/cloud/bitbucket/rest/api-group-snippets/#api-snippets-get), except that the result is further filtered
by the snippet owner and only those that are owned by `{workspace}` are
returned.
*/
export async function main(
auth: Bitbucket,
workspace: string,
role: "owner" | "contributor" | "member" | undefined
) {
const url = new URL(`https://api.bitbucket.org/2.0/snippets/${workspace}`);
for (const [k, v] of [["role", role]]) {
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 407 days ago