Skip to content
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

Merged
merged 9 commits into from
Nov 8, 2017

Conversation

machour
Copy link
Collaborator

@machour machour commented Nov 3, 2017

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:

🍺  ~/all-contributors-cli $ ./cli.js check jfmengels/all-contributors-cli
Missing contributors in .all-contributorsrc:
    brycereynolds, chrisinajar, jmeas, spirosikmd, fadc80, snipe
Unknown contributors found in .all-contributorsrc:
    charlike

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 🤔

@kentcdodds
Copy link
Collaborator

This is super awesome!

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.

You can get that from the projectOwner and projectName fields 👍

Copy link
Collaborator

@kentcdodds kentcdodds left a 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')
Copy link
Collaborator

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>')
Copy link
Collaborator

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',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github should be GitHub

@machour
Copy link
Collaborator Author

machour commented Nov 3, 2017

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 getNextLink, not really sure what I can do. I would love to have your input on that.

Copy link
Collaborator

@kentcdodds kentcdodds left a 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!

@kentcdodds
Copy link
Collaborator

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.

Actually, let's make it code or test because tool is often referencing another related project and may or may not be something that happened in the repo. What do you think?

@kentcdodds
Copy link
Collaborator

Just realized that the yarn.lock file is already in the project. That's fine. This isn't really set up the way my projects are normally. It's @jfmengels project after all 😉

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 request library somehow when testing the check functionality. I'm afraid I don't have too much time to give you feedback or ideas on this point :-/

@machour machour changed the title feat: Add checking functionality that compares contributors with GH data feat: Add check command that compares contributors with GH data Nov 6, 2017
@machour
Copy link
Collaborator Author

machour commented Nov 8, 2017

@kentcdodds took in account your remarks and added tests using nock() which was already included in the project. 100% coverage for check.js, so if the test suite looks good for you I think I'm done with this PR:
https://github.com/jfmengels/all-contributors-cli/pull/58/files#diff-4c2289f0a9b1e98a126e9406cae8c04b

fixtures are in fixtures/ which is ignored in package.json, the test file uses the .test.js suffix in its name.. I think I won't mess a thing by publishing this. (I'm still a bit new to publishing, triple checking with you 😊 )

@machour machour removed the wip label Nov 8, 2017
Copy link
Collaborator

@kentcdodds kentcdodds left a 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 && (
Copy link
Collaborator

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);
Copy link
Collaborator

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.

});

test('Handle a single results page correctly', async t => {
await check('jfmengels', 'all-contributors-cli').then(transformed => {
Copy link
Collaborator

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 ....

Copy link
Collaborator

@kentcdodds kentcdodds left a 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!

return null;
}

var nextLink = link.split(',').find(s => s.indexOf('rel="next"') > -1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use includes here

}

module.exports = function getContributorsFromGithub(owner, name) {
var url = 'https://api.github.com/repos/' + owner + '/' + name + '/contributors?per_page=100';
Copy link
Collaborator

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`;

Copy link
Collaborator Author

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

@machour machour changed the title feat: Add check command that compares contributors with GH data feat: Add check command that compares GitHub contributors with credited ones Nov 8, 2017
Copy link
Collaborator

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks!

@kentcdodds kentcdodds merged commit 88c7a29 into all-contributors:master Nov 8, 2017
@kentcdodds
Copy link
Collaborator

Great work @machour 👏

@machour machour deleted the diff-functionality branch November 8, 2017 17:23
Berkmann18 pushed a commit that referenced this pull request May 24, 2020
* docs: update README.md

* docs: update .all-contributorsrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants