-
-
Notifications
You must be signed in to change notification settings - Fork 775
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
Add slack bot integration #935
Conversation
- send same messages to user's slack as to gitcoin's slack Fixes: gitcoinco#259
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.
Thanks for the contribution! A few review notes, but overall looks pretty good so far! I'll pull this down and test shortly!
app/dashboard/notifications.py
Outdated
conv_details = "" | ||
usdt_details = "" | ||
try: | ||
conv_details = f"@ (${round(convert_token_to_usdt(bounty.token_name),2)}/{bounty.token_name})" | ||
usdt_details = f"({bounty.value_in_usdt_now} USD {conv_details} " | ||
except Exception: | ||
pass # no USD conversion rate | ||
except Exception as e: |
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 modify this method to msg = ''
and return msg
regardless, so we aren't mixing return types and drop the second except Exception as e
return True | ||
|
||
|
||
def build_message_for_slack(bounty, event_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 you add a docstring here like the one added below?
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've added it with previous commit
app/dashboard/notifications.py
Outdated
except Exception as e: | ||
print(e) | ||
except IndexError: | ||
return False |
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.
Should be able to pass on this since sent
will be False
at lines 233-234.
app/dashboard/notifications.py
Outdated
except Exception as e: | ||
print(e) | ||
except IndexError: | ||
return False | ||
except Exception as e: | ||
print(e) | ||
return False |
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.
Same as above.
app/marketing/models.py
Outdated
@@ -37,6 +37,9 @@ class EmailSubscriber(SuperModel): | |||
priv = models.CharField(max_length=30, default='') | |||
github = models.CharField(max_length=255, default='') | |||
keywords = ArrayField(models.CharField(max_length=200), blank=True, default=[]) | |||
repos = ArrayField(models.CharField(max_length=200), blank=True, default=[]) | |||
slack_token = models.CharField(max_length=255, default='') |
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 move these new fields to: dashboard.models.Profile
?
app/marketing/views.py
Outdated
else: | ||
es.metadata['ip'].append(ip) | ||
es.save() | ||
msg = "Updated your preferences. " |
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.
This message should be wrapped in the gettext_lazy
helper: _()
app/marketing/views.py
Outdated
@@ -615,6 +619,44 @@ def email_settings(request, key): | |||
return TemplateResponse(request, 'settings/email.html', context) | |||
|
|||
|
|||
def slack_settings(request): | |||
|
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 you replace this new line with a docstring?
{% load i18n static %} | ||
|
||
{% block settings_content %} | ||
<form id="settings" method="POST"> |
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 you update this file to use 2 space indentation?
app/marketing/views.py
Outdated
repos = request.POST.get('repos').split(',') | ||
channel = request.POST.get('channel', '') | ||
es.slack_token = token | ||
es.repos = repos |
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 not certain, but we might want to validate the user is a member of the tracked repo or limit trackable repos to those returned from GH for the authenticated user.
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 actually checking if notfication needs to be sent using users github name:
subscribers = EmailSubscriber.objects.filter(profile__handle=username, repos__contains=[repo])
that way user will be able to get notification only for his own repos.
but I don't know how this will behave if user wants to monitor repos that belong to organization,
and I don't know how to test such use case.
Any thoughts on how I can test this use case?
app/marketing/views.py
Outdated
@@ -417,6 +417,10 @@ def funnel(request): | |||
'body': 'Feedback', | |||
'href': '/settings/feedback', | |||
}, | |||
{ | |||
'body': 'Slack', | |||
'href': '/settings/slack', |
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 you modify this to use reverse()
Codecov Report
@@ Coverage Diff @@
## master #935 +/- ##
===========================================
- Coverage 33.32% 17.27% -16.06%
===========================================
Files 100 99 -1
Lines 6361 6419 +58
Branches 768 776 +8
===========================================
- Hits 2120 1109 -1011
- Misses 4142 5304 +1162
+ Partials 99 6 -93
Continue to review full report at Codecov.
|
migrations.AddField( | ||
model_name='profile', | ||
name='repos', | ||
field=django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=200), blank=True, default=[], size=None), |
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.
E501 line too long (140 > 120 characters)
app/marketing/views.py
Outdated
}, | ||
] | ||
{ |
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.
E122 continuation line missing indentation or outdented
@mbeacom Can you provide some feed? I think I've covered all comments. |
when i try to migrate
|
http://bits.owocki.com/2t1W1X2z3R2f/Screen%20Shot%202018-04-23%20at%205.25.44%20PM.png usability feedback:
|
doesnt seem to work with these settings.. what am i doing wrong? http://bits.owocki.com/1t0i3Y333C0t/Screen%20Shot%202018-04-23%20at%205.29.51%20PM.png |
@@ -0,0 +1,30 @@ | |||
# Generated by Django 2.0.4 on 2018-04-23 13:43 |
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.
You'll need to rebase with master
, delete this file, and recreate your migrations via: make migrations
Checklist
Affected core subsystem(s)
Testing
Tested manually
Refers/Fixes
Fixes: #259