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
Conversation
if ( !person ) return person; | ||
|
||
var allStar = allStars( person ); | ||
if ( allStar ) { |
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.
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. :)
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 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' ] }
Looking good - only a few notes. Great that you thought of the tests! 馃憤 |
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 ) ); | ||
} |
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.
Hey hey,
why don't you take the summary
result here?
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.
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?
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.
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?
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.
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
stringgithubUser
stringtwitter
stringid
stringemails
arraynames
arraynpmUsers
arraygithubUsers
arraytwitters
arraysummary
functiontoString
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
stringemail
stringnpm
stringgithub
stringtwitter
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;
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 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.
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?
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.
Ok, I think I can handle that. I will update. 馃樃 Thanks for working this out with me!
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.
馃懐 馃憤
Added commit 08efff7, which merges only the following properties from
Let me know what you think. Thanks! |
Thanks for contributing. :) |
Leverage all-stars for author de-dupe and additional usernames
馃尃 Initial stab to implement issue #6.
Basically adds a private
getAllStar()
function toutil/package.js
that all returned objects fromgetAuthor()
andgetMaintainers()
are filtered through. The new method checks if the person is known toall-stars
and merges its data with the current person object. This adds all properties and functions from theallStars.AllStar
object (e.g.githubUser
,npmUser
,twitter
, etc), which may havenull
orundefined
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!