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

[ACHIEVEMENT] The Gladiator - achievement for getting all the reaction to a comment #51

Merged
merged 6 commits into from Feb 25, 2017

Conversation

dunaevsky
Copy link
Member

@dunaevsky dunaevsky commented Jan 27, 2017

The commenter gets the achievement.

-It still does not work for inline comments

-You can also add reactions to the PR itself, I wanted to give an achievement to the creator also, but I didn't see it being audited. @thatkookooguy LMKWYT

-I am uncertain about the name, so would like suggestions

-Big up and much 馃憤 to @ortichon who helped me de-bug this shit

@dunaevsky dunaevsky added achievements issues related to writing or fixing bugs in achievements help wanted issue is waiting for someone to shed some more light on pending... labels Jan 27, 2017
@thatkookooguy
Copy link
Member

@dunaevsky opened PR #52 so you'll have the data you want. you can review that one first so you'll have the data available to work in this branch

@thatkookooguy
Copy link
Member

Also added a data example in PullRequestExample.MD but it's pretty much the same as reactions on comments :-)

@ortichon
Copy link
Member

@dunaevsky let me know when you finish all your changes and I'll start reviewing.

@dunaevsky
Copy link
Member Author

@ortichon @thatkookooguy I'ma put a pin on it for tonight and pick up tomorrow sometime, Since there's 2 features to add.

If you have suggestions for the "short" and "description" it will be great.
I like it being called the Gladiator.

@thatkookooguy
Copy link
Member

@dunaevsky Cool. Just add the help wanted label so we'll know this is not up for review yet and just brainstorming

@dunaevsky
Copy link
Member Author

@thatkookooguy Already have 3 labels since this was my goal here from the get go

@thatkookooguy
Copy link
Member

Here's how I made a function that gives back all comments (or pull request) creators that got all 6 reactions:

function getCommentAuthorsWithAllReactions(pullRequest) {
    var allComments = _.concat(pullRequest.comments, pullRequest.inlineComments);
    var authors = _.map(allComments, 'author.username');
    var AllCommentsReactions = _.map(allComments, 'reactions');

    // also add pull request description reactions
    authors.push(pullRequest.creator.username);
    AllCommentsReactions.push(pullRequest.reactions);

    getOnlyUniqueReactionsWithoutAuthors(AllCommentsReactions, authors);

    return onlyUsersWithAllReactions(authors, AllCommentsReactions);
}

function reactionsWithoutAuthor(reactions, author) {
    return _.map(_.reject(reactions, ['user.username', author]), 'reaction');
}

function getOnlyUniqueReactionsWithoutAuthors(AllCommentsReactions, authors) {
    _.forEach(AllCommentsReactions, function(reactions, index) {
        AllCommentsReactions[index] =
            _.uniq(reactionsWithoutAuthor(reactions, authors[index]));

    });
}

function onlyUsersWithAllReactions(authors, AllCommentsReactions) {
    var commentAuthorsWithAllReactions = [];

    _.forEach(authors, function(author, index) {
        if (AllCommentsReactions[index].length === 6) {
            commentAuthorsWithAllReactions.push(author);
        }
    });

    return commentAuthorsWithAllReactions;
}

I try and remove all the data that I don't need so that data would be easier to understand.

  1. get all comments (of all types)
  2. from that, create two connected arrays of authors and reactions to that author's comment
  3. add the pull request creator as another author, and the pull request reactions to the reactions array

    Now, the PR data and the comments data are the same. from here, on, the code doesn't know it came from different sources

  4. for each reactions array, remove any reaction by the text author, and remove all the data that doesn't interest us.

    This is done with _map to change every reaction object to the reaction string. At this point, we have all reactions not by the author in string format (example [ "laugh", "+1", "+1" ] ). Finally, we run _.uniq on that array to get only unique values (example: [ "laugh", "+1" ] )

  5. Now, we have exactly the data we want to test. A list of authors we want to test for the achievements, and a list of unique reactions (not by the author). If all reactions were added, it means the unique reactions would be equal to 6 ('+1', '-1', 'laugh', 'confused', 'heart', 'hooray'). So, the final function, just creates an array of the authors that had 6 exactly reactions

So, when you call getCommentAuthorsWithAllReactions(pullRequest), you'll get all the usernames of the users who had something with all reactions but they weren't included in the calculation

getCommentAuthorsWithAllReactions(pullRequest)
// ["dunaevsky", "Thatkookooguy"]

@thatkookooguy
Copy link
Member

Notice that I don't use _.isEmpty at all. lodash have lots of little tricks to save code from edge cases. For example, you checked that !_.isEmpty(comment.reactions), but if you just did the _.forEach with an empty array or even undefined, lodash will just return undefined

_.forEach(undefined, function(dog) { return console.log('woof') });
_.forEach([], function(dog) { return console.log('woof') });
// both print nothing

Since all lodash function do that, you will just get an empty array if getCommentAuthorsWithAllReactions didn't find reactions at all.

@thatkookooguy
Copy link
Member

thatkookooguy commented Jan 28, 2017

@dunaevsky - So, make the function work and let's start the review.

Please test the achievement (if you already got the achievement in the DB, delete it to test you get it again). Also, test it after you took the latest changes from master into your work
please lint your code with our new eslint file.

you can use eslint inside atom by installing the following packages:

Then, make sure that inside the linter-eslint settings, you check the box image.

This will fix all common mistakes automatically for you when you save the file, and show you errors for things you need to fix manually.

restart atom, open achievibit, and the linter should recognize our settings file automatically and start showing you lint errors

@dunaevsky
Copy link
Member Author

@thatkookooguy cool. I'll go over it. But gonna have to postpone it again

This is not including inline comments Yet.
Also, I've noticed there is no collection of reactions for the PR itself. Can we?
The name will change. Also not sure about the beatles.
Can't distinguish between when trying to eliminate self reactions.

Also granting to creator is not set yet
@coveralls
Copy link

Coverage Status

Coverage decreased (-24.5%) to 18.939% when pulling c6c1ea5 on achiev-all-reactions into f6765b2 on master.

@dunaevsky
Copy link
Member Author

I did it for the memberberry :*

@coveralls
Copy link

Coverage Status

Coverage increased (+1.4%) to 44.854% when pulling b9e31d6 on achiev-all-reactions into f6765b2 on master.

@thatkookooguy thatkookooguy requested review from thatkookooguy and removed request for ortichon February 25, 2017 22:15
var achievement = {
avatar: 'images/achievements/gladiator.achievement.gif',
name: 'Gladiator',
short: 'Are You Not Entertained?',
Copy link
Member

Choose a reason for hiding this comment

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

E is uppercase

I think a ?! can work here

name: 'Gladiator',
short: 'Are You Not Entertained?',
description: [
'You got all the reactions to your comment. You make everybody feel.'
Copy link
Member

Choose a reason for hiding this comment

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

do you like this description? seems kind of too non-descriptive to me

@coveralls
Copy link

Coverage Status

Coverage increased (+1.4%) to 44.854% when pulling 808304d on achiev-all-reactions into f6765b2 on master.

@dunaevsky dunaevsky merged commit 591100a into master Feb 25, 2017
@thatkookooguy thatkookooguy deleted the achiev-all-reactions branch February 27, 2017 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
achievements issues related to writing or fixing bugs in achievements help wanted issue is waiting for someone to shed some more light on pending...
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants