-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add check command that compares GitHub contributors with credited ones #58
feat: Add check command that compares GitHub contributors with credited ones #58
Conversation
This is super awesome!
👍
You can get that from the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fine with the code as it is 👍 just a couple of things 😄
This is great 👏
cli.js
Outdated
@@ -23,6 +23,8 @@ var argv = yargs | |||
.usage('Usage: $0 add <username> <contribution>') | |||
.command('init', 'Prepare the project to be used with this tool') | |||
.usage('Usage: $0 init') | |||
.command('check', 'Compares contributors from Github with the ones credited in .all-contributorsrc') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github
should be GitHub
👍
cli.js
Outdated
@@ -23,6 +23,8 @@ var argv = yargs | |||
.usage('Usage: $0 add <username> <contribution>') | |||
.command('init', 'Prepare the project to be used with this tool') | |||
.usage('Usage: $0 init') | |||
.command('check', 'Compares contributors from Github with the ones credited in .all-contributorsrc') | |||
.usage('Usage: $0 check <repository>') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't forget to remove <repository>
when you refactor this to use projectOwner
and projectName
cli.js
Outdated
@@ -87,6 +108,9 @@ function promptForCommand(argv) { | |||
}, { | |||
name: 'Re-generate the contributors list', | |||
value: 'generate' | |||
}, { | |||
name: 'Compare contributors from Github with the credited ones', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Github
should be GitHub
Hi @kentcdodds, thank you for the feedback. I took care of it! I also implemented API pagination, but it's currently limited to 500 contributors max. I guess that will be more than enough for most projects 😄 For collaborators unknown to GitHub, I added a check to only report those whose contributions includes "code" or "tool". There might be room for improvement here, but I think it's enough for now. Added some documentation too, you may want to review it as I'm not a native speaker. And last but not least, I'm not sure how to write tests for this new feature. Aside from testing headers parsing in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super! Could you get rid of the yarn.lock
file (maybe add yarn.lock
to the gitignore?). Thanks!
Actually, let's make it |
Just realized that the It's also using AVA rather than Jest, so I'm not certain of the best way to test things either, but I think you'll want to mock the |
@kentcdodds took in account your remarks and added tests using fixtures are in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking great! Just a few things...
cli.js
Outdated
|
||
var missingInConfig = ghContributors.filter(login => knownContributors.indexOf(login) === -1); | ||
var missingFromGithub = knownContributors.filter(login => { | ||
return ghContributors.indexOf(login) === -1 && ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably use includes
here :)
cli.js
Outdated
}, {}); | ||
var knownContributors = configData.contributors.map(contributor => contributor.login); | ||
|
||
var missingInConfig = ghContributors.filter(login => knownContributors.indexOf(login) === -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could probably use includes
here.
lib/util/check.test.js
Outdated
}); | ||
|
||
test('Handle a single results page correctly', async t => { | ||
await check('jfmengels', 'all-contributors-cli').then(transformed => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you're using await
here, you don't need the then
you could do:
const transformed = await check ...
t.deepEqual(transformed ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, two more things!
lib/util/check.js
Outdated
return null; | ||
} | ||
|
||
var nextLink = link.split(',').find(s => s.indexOf('rel="next"') > -1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use includes
here
lib/util/check.js
Outdated
} | ||
|
||
module.exports = function getContributorsFromGithub(owner, name) { | ||
var url = 'https://api.github.com/repos/' + owner + '/' + name + '/contributors?per_page=100'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a template literal:
var url = `https://api.github.com/repos/${owner}/${name}/contributors?per_page=100`;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There you go. Also use template literals for the command output
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome! Thanks!
Great work @machour 👏 |
* docs: update README.md * docs: update .all-contributorsrc
More than often, I find myself having a diff between the numbers of contributors reported by Github, and the contributors actually credited in my
.all-contributorsrc
.This PR draft introduce a new CLI command that will fetch contributors from GH api, and run a two-ways diff with the known ones, allowing a project maintainer to easily find who is missing.
Sample output on this repo:
I still need to paginate the api response if there are more than 100 results, and avoid reporting unknown contributors if their contributions didn't involve coding (video, blog, funding, ..)
I'm also thinking about adding a
repository
field in the configuration file, to avoid retyping the repo name every time the command is executed.And I'm not sure if
utils/diff.js
is the right place for this script 🤔