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

Load users to robot.brain.users #381

Merged
merged 9 commits into from
Dec 31, 2016
Merged

Conversation

ysakasin
Copy link
Contributor

@ysakasin ysakasin commented Dec 13, 2016

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've been mindful about doing atomic commits, adding documentation to my changes, not refactoring too much.
  • I've a descriptive title and added any useful information for the reviewer. Where appropriate, I've attached a screenshot and/or screencast (gif preferrably).
  • I've written tests to cover the new code and functionality included in this PR.
  • I've read, agree to, and signed the Contributor License Agreement (CLA).

PR Summary

Store users in the robot.brain.users. PR is written with reference to old code.

Related Issues

Fix #352

Test strategy

Not yet.

Call userChange and loadUsers, after compare input data with data which in brain.

@codecov-io
Copy link

codecov-io commented Dec 13, 2016

Current coverage is 77.59% (diff: 78.94%)

Merging #381 into master will increase coverage by 0.15%

@@             master       #381   diff @@
==========================================
  Files             4          4          
  Lines           164        183    +19   
  Methods           0          0          
  Messages          0          0          
  Branches         37         42     +5   
==========================================
+ Hits            127        142    +15   
- Misses           26         30     +4   
  Partials         11         11          

Powered by Codecov. Last update 855b3e0...902b00f

@DEGoodmanWilson
Copy link

Thanks for this! I'll try to have a look at this more closely on Thursday. In the meantime, one of the acceptance criteria is that unit tests are written to cover the new functionality—can you add those in for us?

@ysakasin
Copy link
Contributor Author

@DEGoodmanWilson

In the meantime, one of the acceptance criteria is that unit tests are written to cover the new functionality—can you add those in for us?

Maybe. I'll try.

@ysakasin
Copy link
Contributor Author

@DEGoodmanWilson

Hi. I write unit tests.
Could you review these codes?

@sebastiandero
Copy link

@NKMR6194 Hey, can i help in some way? Help with test coverage maybe?

@ysakasin
Copy link
Contributor Author

@sebastiandero Thanks. I have just learned of "coverage" meaning. I try writing more unit test. Could you wait?

@sebastiandero
Copy link

@NKMR6194 sure can, i have tried to use your fork and it does not seem to load any users into the brain, is there something i am missing?

@ysakasin
Copy link
Contributor Author

@sebastiandero Do you use fix-users-in-brain branch? Hmm... I'll check code once more.

@sebastiandero
Copy link

@NKMR6194 yes I have, dont know what could have been the issue, i have setup a fork to help you with the test coverage

@ysakasin
Copy link
Contributor Author

@sebastiandero How did you check users in brain? Users are loaded into brain on my environment.

@sebastiandero
Copy link

@NKMR6194 I checked using hubot-brain-inspect. I added the bot, wrote a message on slack and was not in the brain

@ysakasin
Copy link
Contributor Author

@sebastiandero Oh... OK, I get your case.

@sebastiandero
Copy link

@NKMR6194 any idea on how to fix?

@ysakasin
Copy link
Contributor Author

@sebastiandero May be fix it. Could you try it?

@sebastiandero
Copy link

@NKMR6194 Yes it is indeed fixed now, thank you so much, have a digital coffee ☕! You solved my byfar biggest frustration with this adapter, hope they merge it soon

Copy link

@sebastiandero sebastiandero left a comment

Choose a reason for hiding this comment

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

Tested using hubot-brain-inspect and all data is now present from the moment the bot connects!

@sebastiandero
Copy link

This fixes these issues: #352 #348 #326

@DEGoodmanWilson
Copy link

@aoberoi could you have a look at this PR?

@aoberoi
Copy link
Contributor

aoberoi commented Dec 29, 2016

excellent work @NKMR6194!

regarding the implementation, i've taken a quick glance and i don't have any big concerns at the moment. i need to take a little more time to look closer at the change and then i'll add any feedback i might have.

besides the implementation, i do have a concern about whether this change is something we want. before i was involved with this project, this functionality existed, and it was seemingly removed. i'd like to understand if it was removed intentionally and what the reason might have been. the most obvious potential reason would be around keeping all this state in process (in memory). that makes scaling a hubot service horizontally and keeping the state in sync difficult. it seems like we might be fine though, since hubot provides a pluggable persistence mechanism for brain state. as long as i can confirm that this solves the concern, and i don't find any additional reasons for why the functionality was removed in the past, i'd be happy to land this functionality.

@@ -51,6 +51,11 @@ class SlackBot extends Adapter
@client.on 'reaction_added', @reaction
@client.on 'reaction_removed', @reaction
@client.on 'authenticated', @authenticated
@client.on 'userChange', @userChange
Copy link
Contributor

Choose a reason for hiding this comment

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

'userChange' -> 'user_change'

@robot.logger.error "Can't fetch users"
return

for id, user of res.members
Copy link
Contributor

Choose a reason for hiding this comment

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

wha you are getting here is the JavaScript for...of, but the usage looks confusing because it seems as though you are trying to do a comprehension and pull out properties id and user of members. since members is actually an array and not a normal object, you will get id that is the index in the array and user that is the value. this happens to work, but it doesn't read clearly.

I suggest:

@userChange member for member in res.members

@userChange user

userChange: (user) =>
return unless user?.id?
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious, when would there be no id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Probably nothing that case.

userChange: (user) =>
return unless user?.id?
newUser =
name: user.name
Copy link
Contributor

Choose a reason for hiding this comment

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

can we store id: user.id in here as well? if the idea that Slack-specific properties should go inside the slack property, then this is already not working since the ID that the user will be identified with in the brain is the Slack ID.

should.equal user.name, @stubs.user.name
should.equal user.real_name, @stubs.user.real_name
should.equal user.email_address, @stubs.user.profile.email
should.equal user.slack.misc, @stubs.user.misc
Copy link
Contributor

Choose a reason for hiding this comment

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

add id to this

it 'Should add a user data', ->
@slackbot.userChange(@stubs.user)

user = @slackbot.robot.brain.data.users[@stubs.user.id]
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of accesing the brain data directly, wouldn't it make more sense to use the brain.userForId() method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

brain.userForId() create User instance and return it when brain have no user.id.
I'm concerned about that behavior.

Copy link
Contributor

Choose a reason for hiding this comment

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

good call 👍

@@ -129,6 +131,12 @@ beforeEach ->
@stubs.channelsMock =
setTopic: (id, topic) =>
@stubs._topic = topic

@stubs.responseUsersList =
ok: 'ok'
Copy link
Contributor

Choose a reason for hiding this comment

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

ok: true

ok: 'ok'
members: [@stubs.user, @stubs.userperiod]
@stubs.wrongResponseUsersList =
members: [@stubs.user, @stubs.userperiod]
Copy link
Contributor

Choose a reason for hiding this comment

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

remove members and add ok: false

@aoberoi
Copy link
Contributor

aoberoi commented Dec 30, 2016

@johnagan: care to comment on why robot.brain.users didn't survive the refactor you did in 900402e?

@johnagan
Copy link

The RTM client already maintains an updated user list in the dataStore and is well tested. IMO we should just expose that a little cleaner in the client class.

@aoberoi
Copy link
Contributor

aoberoi commented Dec 30, 2016

You bring up a fair point about trying to have just one source of truth. My evaluation currently points to using brain and so I created #385 to track this work.

Pros (in favor of robot.brain):

  • hubot users expect to use the brain API in their scripts.
  • hubot brain has a robust story for persistence/sync.

Cons (in favor of dataStore):

  • already tested as part of @slackapi/node-slack-sdk

@johnagan: I can be convinced the other way if you have anything to add.

@sebastiandero
Copy link

@johnagan the beauty and reason many people use Hubot is because it is so adaptable. Most people will write a bot with it and expect similar behavior on various chat services and hence adapters. Having a different approach to storing the user data imo makes no sense when talking about Hubot.

@johnagan
Copy link

johnagan commented Dec 30, 2016

Having a different approach to storing the user data imo makes no sense when talking about Hubot.

I'm pretty sure most adapters don't offer brain.users. I seem to remember only one other adapter using this, which lead me to believe this wasn't a common interface across connectors.

I'll double check and see.

@johnagan
Copy link

@sebastiandero you're right! I found it in a couple that I looked at. I'm sold 👍

@sebastiandero
Copy link

@johnagan having it would improve usability quite a bit, I think. I know that I have been desperately waiting for this since I created a ticket on it couple months ago.

@aoberoi
Copy link
Contributor

aoberoi commented Dec 30, 2016

yay! i've approved the changes, but it looks like we are falling a little short of the coverage target. any takers on adding a few tests?

@ysakasin
Copy link
Contributor Author

@aoberoi Thank you reviewing. PR pass the coverage target. Should I squash this into one commit?

@aoberoi
Copy link
Contributor

aoberoi commented Dec 31, 2016

@NKMR6194: i personally prefer keeping commits in their original form rather than squashing. i hope the other maintainers agree because i'm merging! 🎆 🍾

@aoberoi aoberoi merged commit 1585a31 into slackapi:master Dec 31, 2016
@aoberoi
Copy link
Contributor

aoberoi commented Dec 31, 2016

i haven't done a release of this module myself yet, so i'm not going to do it late on a friday myself. you can expect a release early next week though!

@halkeye
Copy link

halkeye commented Jan 4, 2017

@aoberoi any chance you'll be able to do the release this week? (I hate to be that person)

I tried out the raw git master version and things seem to be pretty awesome.

@aoberoi
Copy link
Contributor

aoberoi commented Jan 6, 2017

@halkeye as of earlier today, the changes are out! thanks for your patience.

@asalaheldin
Copy link

Thanks a lot for this great work. I think this fix #326 as now after applying the new version of "hubot-slack" and "hubot-auth" I can see my slack users data inside hubot redis brain and this data include (slack names, real names, emails, ids, etc...).

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.

8 participants