import { getState, setState } from "windmill-client@1";
type Bitbucket = {
username: string;
password: string;
};
export async function main(
bitbucket: Bitbucket,
workspace: string,
repo: string,
commit: string
) {
const lastChecked: number = (await getState()) || 0;
const response = await fetch(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo}/commit/${commit}/comments?pagelen=100`,
{
headers: {
Authorization:
"Basic " +
Buffer.from(bitbucket.username + ":" + bitbucket.password).toString(
"base64"
),
},
}
);
const data = await response.json();
if (!response.ok) {
throw new Error(data.error.message);
}
const newComments = [];
for (const comment of data?.values || []) {
if (new Date(comment.created_on).getTime() > lastChecked) {
newComments.push(comment);
} else {
break;
}
}
if (newComments.length > 0) {
await setState(new Date(newComments[0].created_on).getTime());
}
return newComments;
}
Submitted by hugo697 456 days ago