Ever wondered how high is ranked your most starred/forked repository across all GitHub? Or whether if you're one of most followed user account π ?
Well, this is possible thanks to Metrics Insights!
There's also a few additional data, like the number of bytes you've written for each languages you used up until now!
Best of it is that you can use Metrics Insights in your browser without any account login nor cookies!
π€ How does it work though?
I'm currently working on Metrics, a project designed to gather data that you can then render as SVG to embed on your GitHub user profile, like below:
Currently, there's hundreds of options, including 4 templates and 30 plugins, one of them being the π Achievements
one:
As you can see, some of them include ranking. You may wonder of these are computed? Well it's actually a lot simpler that it may looks, using GitHub GraphQL API and Puppeteer.
The trick is to fetch the number of followers
, created repositories
of said user, along with their most starred repository
and most forked repository
.
Then using search
GitHub GraphQL API, we can count how many users and repositories are above using the following query (replacing each $
prefixed values with what we found earlier):
query AchievementsRanking {
repo_rank:search(query: "stars:>$stars", type: REPOSITORY, first: 0) {
repositoryCount
}
user_rank:search(query: "followers:>$followers", type: USER, first: 0) {
userCount
}
forks_rank:search(query: "forks:>$forks", type: REPOSITORY, first: 0) {
repositoryCount
}
created_rank:search(query: "repos:>$created", type: USER, first: 0) {
userCount
}
}
As you can see, we only retrieve the total count of each categorie, we don't even try to fetch any content. So basically, if an user has 100
followers and user_rank.userCount
send back 999
users, we can deduce that user is 1000th (999+1
) since 999 users has more followers. We do the same for each categorie.
One thing to note is that GitHub API may return incomplete count below some thresholds as there's too many results to compute for even GitHub to handle it. But if you have created a respository at least once, or having a repository which has been starred 5+ times or forked 1+ time or if you have 3+ followers, you can compete within each categorie π !
I guess it also means that there's a lot of inactive users and unused account, so if you're somewhat active on GitHub you'll be able to see your stats pretty easily with this tool.
Since it's not possible to estimate how many repositories and users exists through GitHub's own API, you may wonder how I got total repositories and users count?
Well, actually these are displayed on GitHub search:
This is why we needed puppeteer π We just crawl a few times (displayed stats is random between users, repositories and issues) and extract these. Once we got each categorie at least once, no more need for puppeteer, we're ready to go!
If you're interested, don't hesitate to take a look at this project source code and support it. There's even a plugin to update your profile readme with your latest post from dev.to!
lowlighter / metrics
π An infographics generator with 30+ plugins and 300+ options to display stats about your GitHub account and render them as SVG, Markdown, PDF or JSON!
You can provide some feedback like bug reports and suggestion for this feature on GitHub discussions π
Thanks a lot for reading, and don't hesitate to share your scores in comments section!
One last bonus: can you guess who is the most followed GitHub user? Click here to know!
Top comments (1)
Time for a new blog post about this! :P