type Bitbucket = {
username: string;
password: string;
};
/**
* List snippets
* Returns all snippets.
*/
export async function main(
auth: Bitbucket,
role: "owner" | "contributor" | "member" | undefined
) {
const url = new URL(`https://api.bitbucket.org/2.0/snippets`);
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 508 days ago
type Bitbucket = {
username: string;
password: string;
};
/**
* List snippets
* Returns all snippets. Like pull requests, repositories and workspaces, the
full set of snippets is defined by what the current user has access to.
This includes all snippets owned by any of the workspaces the user is a member of,
or snippets by other users that the current user is either watching or has collaborated
on (for instance by commenting on it).
To limit the set of returned snippets, apply the
`?role=[owner|contributor|member]` query parameter where the roles are
defined as follows:
* `owner`: all snippets owned by the current user
* `contributor`: all snippets owned by, or watched by the current user
* `member`: created in a workspaces or watched by the current user
When no role is specified, all public snippets are returned, as well as all
privately owned snippets watched or commented on.
The returned response is a normal paginated JSON list. This endpoint
only supports `application/json` responses and no
`multipart/form-data` or `multipart/related`. As a result, it is not
possible to include the file contents.
*/
export async function main(
auth: Bitbucket,
role: "owner" | "contributor" | "member" | undefined
) {
const url = new URL(`https://api.bitbucket.org/2.0/snippets`);
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 508 days ago