import { getState, setState } from "windmill-client@1";
type Bitbucket = {
username: string;
password: string;
};
export async function main(
bitbucket: Bitbucket,
workspace: string,
repo: string
) {
const state: string[] = (await getState()) || [];
const response = await fetch(
`https://api.bitbucket.org/2.0/repositories/${workspace}/${repo}/refs/branches?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 branches = data.values;
const newBranches = branches.filter(
(branch: any) => !state.includes(branch.name)
);
await setState([...state, ...newBranches.map((branch: any) => branch.name)]);
return newBranches;
}
Submitted by hugo697 437 days ago