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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Leverage all-stars for author de-dupe and additional usernames #8

Merged
merged 3 commits into from Nov 21, 2015

Conversation

nexdrew
Copy link
Contributor

@nexdrew nexdrew commented Nov 8, 2015

馃尃 Initial stab to implement issue #6.

Basically adds a private getAllStar() function to util/package.js that all returned objects from getAuthor() and getMaintainers() are filtered through. The new method checks if the person is known to all-stars and merges its data with the current person object. This adds all properties and functions from the allStars.AllStar object (e.g. githubUser, npmUser, twitter, etc), which may have null or undefined values.

Added a single test to util/package.spec.js to cover the "found in all-stars" scenario. It uses mocked author data so that it's not dependent on actual data in all-stars, but unfortunately the mocking requires knowledge of how the data within all-stars is organized. If you think this is a problem, I'll probably need to add a mocking library (as a dev dependency) to mock out the all-stars methods instead.

This gets the job done, but suggestions for improvement are welcomed!

if ( !person ) return person;

var allStar = allStars( person );
if ( allStar ) {
Copy link
Owner

Choose a reason for hiding this comment

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

Hey hey - thanks. :)

Could we maybe use an extend or assign function here to get rid of the if's?

As I see allStars is providing a summary function which could be easily used for that. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will change this, but keep in mind that it will couple the object structure returned by credits to the object structure returned by all-stars. (And you may get more info than you want.) 馃槃

Here's an example:

{ name: 'Benjamin Coe',
  email: 'ben@npmjs.com',
  id: 'bcoe',
  npmUsers: [ 'bcoe' ],
  npmUser: 'bcoe',
  emails: [ 'ben@npmjs.com', 'bencoe@gmail.com' ],
  names: [ 'Benjamin Coe', 'Ben Coe', 'Benjamin E. Coe' ],
  githubUsers: [ 'bcoe' ],
  githubUser: 'bcoe',
  twitters: [ 'benjamincoe' ],
  twitter: 'benjamincoe',
  summary: [Function: summary],
  toString: [Function: toString],
  packages: 
   [ 'cliui',
     'os-locale',
     'y18n',
     'signal-exit',
     'nyc',
     'yargs',
     'wrap-ansi' ] }

@stefanjudis
Copy link
Owner

Looking good - only a few notes. :bowtie:

Great that you thought of the tests! 馃憤

@nexdrew
Copy link
Contributor Author

nexdrew commented Nov 16, 2015

Thanks for the feedback, it is much appreciated! I added commit 0cde7c0 to address your comments. Let me know if you find anything else. 馃槑

function getAllStar( person ) {
// override properties from all-stars if available
return objectAssign( person, allStars( person ) );
}
Copy link
Owner

Choose a reason for hiding this comment

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

Hey hey,

why don't you take the summary result here? :bowtie:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, did you want the "long" or "short" summary? Long looks like:

Rod Vagg <r@va.gg> (npm: rvagg, GitHub: rvagg, Twitter: rvagg)

While short looks like:

Rod Vagg <r@va.gg>

BTW, did you see this comment about assigning? Are you ok returning all that stuff?

Copy link
Owner

Choose a reason for hiding this comment

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

Rod Vagg r@va.gg (npm: rvagg, GitHub: rvagg, Twitter: rvagg)

The representation thing is something related to the given reporter in credits-cli.
We should provide as much data as possible here without cluttering everything. :)

In a perfect world I'd like to have name, email, npm, github, twitter as strings ( or even array - I don't care too much about that one ).

BTW, did you see this comment about assigning? Are you ok returning all that stuff?

Jup - that's why I am asking for the summary call in all-stars. This will pretty much do the job, without exposing too much data, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok I'm confused.

My first approach explicitly added string properties npm, github, and twitter to the person object. But it was using a few if statements. You suggested using extend or assign instead.

My second approach used object-assign to implicitly override name and email and add the following properties to the person object:

  • npmUser string
  • githubUser string
  • twitter string
  • id string
  • emails array
  • names array
  • npmUsers array
  • githubUsers array
  • twitters array
  • summary function
  • toString function

Which is probably a bit too much.

You mentioned you'd like the summary result, which could be represented as one of two strings (instead of a function). I asked which string you'd prefer, and I didn't understand your answer.

How many of the properties listed above would you like? Are you suggesting that the summary() function in all-stars return an object (instead of a string) with the following properties?

  • name string
  • email string
  • npm string
  • github string
  • twitter string

And then merge this with the person object via object-assign? Something like this?

var allStar = allStars( person );
return allStar ? objectAssign( person, allStar.summary() ) : person;

Copy link
Owner

Choose a reason for hiding this comment

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

I'm really sorry about the confusion. :(

My first approach explicitly added string properties npm, github, and twitter to the person object. But it was using a few if statements. You suggested using extend or assign instead.

Using a lot of if/else statements in a row doesn't look good in my opinion and is not really extendable. Hopefully you agree there?

How many of the properties listed above would you like? Are you suggesting that the summary() function in all-stars return an object (instead of a string) with the following properties?

Aaah I see - here is the confusing coming from. I thought it is returning an object containing strings.
E.g.

{
  name : 'John Doe',
  email : 'john@doe.io',
  npm : 'johndoe',
  github : 'johndow',
  twitter : '@johndoe'
}
var allStar = allStars( person );
return allStar ? objectAssign( person, allStar.summary() ) : person;

This was pretty much what I had in mind, yes. :bowtie:


For all-stars I see 2 requests here ( if you agree ):

  • provide a summary object
  • improve documentation to make return clearer.

What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I think I can handle that. I will update. 馃樃 Thanks for working this out with me!

Copy link
Owner

Choose a reason for hiding this comment

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

馃懐 馃憤

@nexdrew
Copy link
Contributor Author

nexdrew commented Nov 20, 2015

Added commit 08efff7, which merges only the following properties from all-stars (each one is a string that may be null):

  • name
  • email
  • npm
  • github
  • twitter

Let me know what you think. Thanks!

@stefanjudis
Copy link
Owner

Thanks for contributing. :)

stefanjudis added a commit that referenced this pull request Nov 21, 2015
Leverage all-stars for author de-dupe and additional usernames
@stefanjudis stefanjudis merged commit ce3a422 into stefanjudis:master Nov 21, 2015
@nexdrew nexdrew deleted the all-stars-yay branch December 4, 2015 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants