-
Notifications
You must be signed in to change notification settings - Fork 636
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
Conversation
Current coverage is 77.59% (diff: 78.94%)@@ 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
|
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? |
Maybe. I'll try. |
Hi. I write unit tests. |
@NKMR6194 Hey, can i help in some way? Help with test coverage maybe? |
@sebastiandero Thanks. I have just learned of "coverage" meaning. I try writing more unit test. Could you wait? |
@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? |
@sebastiandero Do you use |
@NKMR6194 yes I have, dont know what could have been the issue, i have setup a fork to help you with the test coverage |
@sebastiandero How did you check users in brain? Users are loaded into brain on my environment. |
@NKMR6194 I checked using hubot-brain-inspect. I added the bot, wrote a message on slack and was not in the brain |
@sebastiandero Oh... OK, I get your case. |
@NKMR6194 any idea on how to fix? |
@sebastiandero May be fix it. Could you try it? |
@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 |
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.
Tested using hubot-brain-inspect and all data is now present from the moment the bot connects!
@aoberoi could you have a look at this PR? |
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 |
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.
'userChange'
-> 'user_change'
@robot.logger.error "Can't fetch users" | ||
return | ||
|
||
for id, user of res.members |
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.
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? |
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.
just curious, when would there be no id
?
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.
Probably nothing that case.
userChange: (user) => | ||
return unless user?.id? | ||
newUser = | ||
name: user.name |
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.
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 |
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.
add id
to this
it 'Should add a user data', -> | ||
@slackbot.userChange(@stubs.user) | ||
|
||
user = @slackbot.robot.brain.data.users[@stubs.user.id] |
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.
instead of accesing the brain data directly, wouldn't it make more sense to use the brain.userForId()
method?
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.
brain.userForId()
create User instance and return it when brain have no user.id
.
I'm concerned about that behavior.
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.
good call 👍
@@ -129,6 +131,12 @@ beforeEach -> | |||
@stubs.channelsMock = | |||
setTopic: (id, topic) => | |||
@stubs._topic = topic | |||
|
|||
@stubs.responseUsersList = | |||
ok: 'ok' |
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: true
ok: 'ok' | ||
members: [@stubs.user, @stubs.userperiod] | ||
@stubs.wrongResponseUsersList = | ||
members: [@stubs.user, @stubs.userperiod] |
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.
remove members
and add ok: false
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. |
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
Cons (in favor of
@johnagan: I can be convinced the other way if you have anything to add. |
@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. |
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. |
@sebastiandero you're right! I found it in a couple that I looked at. I'm sold 👍 |
@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. |
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? |
@aoberoi Thank you reviewing. PR pass the coverage target. Should I squash this into one commit? |
@NKMR6194: i personally prefer keeping commits in their original form rather than squashing. i hope the other maintainers agree because i'm merging! 🎆 🍾 |
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! |
@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. |
@halkeye as of earlier today, the changes are out! thanks for your patience. |
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...). |
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
andloadUsers
, after compare input data with data which in brain.