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

Github comments when user is warned/removed (in addition to the emails that are sent when this happens) #897

Merged
merged 5 commits into from
Apr 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 56 additions & 1 deletion app/dashboard/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def maybe_market_tip_to_slack(tip, event_name):

try:
sc = SlackClient(settings.SLACK_TOKEN)
channel = 'bounties'
channel = 'notif-gitcoin'
sc.api_call("chat.postMessage", channel=channel, text=msg)
except Exception as e:
print(e)
Expand Down Expand Up @@ -416,6 +416,7 @@ def amount_usdt_open_work():
bounties = Bounty.objects.filter(network='mainnet', current_bounty=True, idx_status__in=['open', 'submitted'])
return round(sum([b.value_in_usdt_now for b in bounties if b.value_in_usdt_now]), 2)


def maybe_market_tip_to_github(tip):
"""Post a Github comment for the specified Tip.

Expand Down Expand Up @@ -613,3 +614,57 @@ def maybe_post_on_craigslist(bounty):
# in case of invalid links
return False
return False


def maybe_notify_bounty_user_removed_to_slack(bounty, username):
if not settings.SLACK_TOKEN or bounty.get_natural_value() < 0.0001 or (
bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK):
return False

msg = f"@{username} has been removed from {bounty.github_url} due to inactivity on the github thread."

try:
sc = SlackClient(settings.SLACK_TOKEN)
channel = 'notif-gitcoin'
sc.api_call("chat.postMessage", channel=channel, text=msg)
except Exception as e:
print(e)
return False
return True


def maybe_notify_user_removed_github(bounty, username, last_heard_from_user_days=None):
if (not settings.GITHUB_CLIENT_ID) or (bounty.get_natural_value() < 0.0001) or (
bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK):
return False

msg = f"@{username} has been removed from this issue due to inactivity ({last_heard_from_user_days} days) on the github thread. @{username} if you believe this was done in error, please <a href={bounty.url}>go to the bounty</a> and click 'start work' again."

post_issue_comment(bounty.org_name, bounty.github_repo_name, bounty.github_issue_number, msg)


def maybe_warn_user_removed_github(bounty, username):
if (not settings.GITHUB_CLIENT_ID) or (bounty.get_natural_value() < 0.0001) or (
bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK):
return False

msg = f"@{username} are you still working on this issue?"

post_issue_comment(bounty.org_name, bounty.github_repo_name, bounty.github_issue_number, msg)


def maybe_notify_bounty_user_warned_removed_to_slack(bounty, username, last_heard_from_user_days=None):
if not settings.SLACK_TOKEN or bounty.get_natural_value() < 0.0001 or (
bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK):
return False

msg = f"@{username} has warned about inactivity ({last_heard_from_user_days} days) on {bounty.github_url}"

try:
sc = SlackClient(settings.SLACK_TOKEN)
channel = 'notif-gitcoin'
sc.api_call("chat.postMessage", channel=channel, text=msg)
except Exception as e:
print(e)
return False
return True
16 changes: 15 additions & 1 deletion app/marketing/management/commands/expiration_start_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,14 @@
from django.utils import timezone

from dashboard.models import Bounty, Interest
from dashboard.notifications import (
maybe_notify_bounty_user_removed_to_slack, maybe_notify_bounty_user_warned_removed_to_slack,
maybe_notify_user_removed_github, maybe_warn_user_removed_github,
)
from github.utils import get_interested_actions
from marketing.mails import bounty_startwork_expire_warning, bounty_startwork_expired

warnings.filterwarnings("ignore", category=DeprecationWarning)
warnings.filterwarnings("ignore", category=DeprecationWarning)
logging.getLogger("requests").setLevel(logging.WARNING)
logging.getLogger("urllib3").setLevel(logging.WARNING)

Expand Down Expand Up @@ -97,11 +101,21 @@ def handle(self, *args, **options):

if should_delete_interest:
print(f'executing should_delete_interest for {interest.profile} / {bounty.github_url} ')
# commenting on the GH issue
maybe_notify_user_removed_github(bounty, interest.profile.handle, last_heard_from_user_days)
# commenting in slack
maybe_notify_bounty_user_removed_to_slack(bounty, interest.profile.handle)
# send email
bounty_startwork_expired(interest.profile.email, bounty, interest, last_heard_from_user_days)
interest.delete()

elif should_warn_user:
print(f'executing should_warn_user for {interest.profile} / {bounty.github_url} ')
# commenting on the GH issue
maybe_warn_user_removed_github(bounty, interest.profile.handle)
# commenting in slack
maybe_notify_bounty_user_warned_removed_to_slack(bounty, interest.profile.handle, last_heard_from_user_days)
# send email
bounty_startwork_expire_warning(interest.profile.email, bounty, interest, last_heard_from_user_days)

except Exception as e:
Expand Down