December 07, 2020 in articles
I wanted, actually needed, to track the number of times some of our repositories in Github got cloned by others. Fortunately, Github provides the clones traffic data from the repository’s Insights. If you are the owner of the repository, or you are an administrator of the github organization, you’d find the “Traffic” link in the sidebar of Insights page.
Unfortunately, this page only shows the data of the last two weeks and it cannot be exported. Another problem is that there are few repositories that I need to track. Opening the repository pages one by one is such a hassle.
So I made a small command line interface (CLI) script, called export-github-clones-views, to fetch the traffic of the git clones and views from multiple repositories then optionally store them in a mongo database. You can read the instructions on how to install and to use the script in the README.md file.
To execute the script regularly, I created a workflow in the Github Actions since a workflow in Github Actions can be triggered automatically at a scheduled time. Check out an example of the workflow file to run the export-github-clones-views script every week here.
Finally I created a mongo database in MongoDB Atlas to store the data fetched by the script. Since I will be the only one who is using the database, the free shared clusters plan in Atlas is more than enough. The cool thing about using MongoDB Atlas is I can easily create the chart from the data.
For those who wonder how much this costs, it doesn’t even cost one banana, Lucille. It’s all FREE!
The script is open source and is written in TypeScript. So if you found a bug or wanted a new feature, your contribution is welcomed. It’s using oclif to make it easy to build CLI. The project is also equipped with some tests which will be run automatically whenever a Pull Request is opened.
Articles, drawings, and codes by Nico Prananta, a software developer (iOS and web) and digital artist (for fun!) in Basel, Switzerland. I'm on Twitter.