import { getGithubStarsForRepo } from "https://esm.town/v/joey/getGithubStarsForRepo";
import { PUBLIC_STATE } from "https://esm.town/v/joey/PUBLIC_STATE";
import { email } from "https://esm.town/v/std/email?v=9";
import { runVal } from "https://esm.town/v/std/runVal";
export const emailOnGithubStar = async (username: string, project: string, toEmail: string) => {
const count = await getGithubStarsForRepo(username, project);
const prevCount = PUBLIC_STATE.STAR_COUNTS[project] || 0;
if (count && count > prevCount) {
console.log(`New star on ${project}: ${count}`);
email(
{
to: toEmail,
subject: `New star on your project! ${project}`,
text: `You now have ${count} stars, they were wrong about you. You're a major success!`,
},
);
}
if (count || count === 0) {
await runVal("joey.setPublicState", `STAR_COUNTS/${project}`, count);
}
};