type Bitbucket = {
username: string;
password: string;
};
/**
* List a commit's comments
* Returns the commit's comments.
This includes both global and inline comments.
The default sorting is oldest to newest and can be overridden with
the `sort` query parameter.
*/
export async function main(
auth: Bitbucket,
commit: string,
repo_slug: string,
workspace: string,
q: string | undefined,
sort: string | undefined
) {
const url = new URL(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo_slug}/commit/${commit}/comments`
);
for (const [k, v] of [
["q", q],
["sort", sort],
]) {
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 456 days ago