import { getState, setState } from "windmill-client@1";
type Bitbucket = {
username: string;
password: string;
};
export async function main(
bitbucket: Bitbucket,
workspace: string,
repo: string
) {
const lastChecked: number = (await getState()) || 0;
const response = await fetch(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo}/pipelines?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 newPipelines = [];
for (const pipeline of data?.values || []) {
if (new Date(pipeline.created_on).getTime() > lastChecked) {
newPipelines.push(pipeline);
} else {
break;
}
}
if (newPipelines.length > 0) {
await setState(new Date(newPipelines[0].created_on).getTime());
}
return newPipelines;
}
Submitted by hugo697 425 days ago