
It's an open secret that you can find the email address from most GitHub users:
it's in the git commit history! In the past, I would close repos and use
git log
to pull it out, but recently I learned that you can do it fairly
easily via the GitHub API.
This function pulls the user's recent public events.
import { emailFromEvents } from "https://esm.town/v/stevekrouse/github-user-email/events.ts";
const emails = await emailFromEvents("stevekrouse");
console.log(emails); // [ "steveykrouse@gmail.com" ]
The limitation is that this endpoint only gets events from the last 30 days, so if the user hasn't committed in the last month, you won't get any results from this method. (Coming soon: a )
The GitHub API
rate limits
unauthenticated requests to 60 per hour per IP address. As a quick workaround,
Val Town provides an IP-randomizer fetch
proxy that makes it easy to get
around these limits. These functions use that proxy by default. However, if
you're using these functions at scale, please use a GITHUB_TOKEN to be a good
GitHub citizen.