import "@johnlindquist/kit";
const Heroku = await npm("heroku-client");
let token = await env("HEROKU_API_TOKEN");
const heroku = new Heroku({ token });
const preview = ({ name, stack, web_url, git_url, updated_at, status }) =>
md(`
## ${name}
- Updated: ${updated_at}
- Status: ${status}
- Stack: ${stack}
### Links
${git_url ? `- [git](${git_url})` : ""}
${web_url ? `- [web](${web_url})` : ""}
`);
const byDateDesc = (a, b) => {
if (a.created_at < b.created_at) {
return 1;
}
if (a.created_at > b.created_at) {
return -1;
}
return 0;
};
const apps = await heroku.get("/apps").then((apps) =>
apps.map(({ id, name, web_url, git_url, updated_at }) => ({
name,
description: web_url,
value: `https://dashboard.heroku.com/apps/${name}`,
preview: async () => {
const setups = await heroku
.get(`/apps/${id}/builds`)
.then((builds) => builds.sort(byDateDesc));
if (!setups || !setups.length) return md(`No builds found`);
return preview({ ...setups[0], name, web_url, git_url });
},
}))
);
let url = await arg("Select Heroku App:", apps);
await $`open ${url}`;