Github has neat statistics for contributors, it shows number of commits and nice charts. But people contribute to Github projects not only via commits. Actually, a lot of contributions happens in issue or pull request comments 💬. Github doesn't have statistics to show "top commenters".
Fetch all existing comments for a given repository for a given period or till the API limit is exhausted, group by user and output it sorted by number of comments. The program should execute and look like:
node index.js --repo <owner>/<repo> --period 20d
Fetching comments for past 20 days for "<owner>/<repo>"...
< progress indicator here >
3012 comments, john.boy (20 commits)
1345 comments, hector (2104 commits)
8 comments, luis (234 commits)
Use the exact output format, notice that numbers are aligned (this is what famous left-pad is for). There msut be some indicator for the progress of the fetching process.
Fortunately Github has a great HTTP API to help with the task. There are 3 types of comments a person can make, comment on individual commit, comment in Issue/Pull Request or comment in Pull Request review (You can read more in their docs).
Mentioned 3 types of comments can be accessed using the following API endpoints:
After each name there is number of commits, here is an API to help fetch that:
Use "total".
- Support
--repo
and--period
parameters as indicated above, if--period
is not specified assume infinite and keep fetching till API Limits are exhausted.--period
only needs to support days in a format25d
where25
is number of days. - Focus on making code readable.
- Create small, focused commits.
- Test code with repositories of different sizes.
- Just like with about any API respect Github's rate limits. Handle errors when limit is exceeded. Reflect remaining limits in progress indicator. Make to not hit abuse limits.
- Use any package, except ones that wrap Github API. The API mus be used natively for this challenge.
- All packages must be installed in
package.json
.
Create personal access token, save it, and then use it to access API to get 5000 requests/hour.
To get started:
- install node 8.9
cd
into repository directory- run
npm install
- create
src/token/__do-not-commit-me__.js
file and add token there like that:
module.exports = '<token>'
- run
npm start
- make sure to see the following output
Your github token is:
<your token>
<details of your github account>
Remove this entry code afterwards. Mentioned file is added to .gitignore
already.
- run
npm run dev
, this will start development server (nodemon) that monitors changes and re-runs the script for faster development cycle - see
example.js
for how it's done, have fun 🎉
Run npm run eslint:fix
and fix all issues.