1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
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";
// Notifies you when you get a new star on your repo
// Usage:
// Pass username and project name from url: github.com/joeroddy/bridg =>
// const githubCron = async() => @joey.checkGithubStars('joeroddy','bridg')
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);
}
};