From 573ceee73aae3e8b828c22beed65ff5df95e6bd4 Mon Sep 17 00:00:00 2001 From: Mark Beacom Date: Thu, 9 Aug 2018 09:00:36 -0400 Subject: [PATCH] Fix #1976 - Adjust gitcoin bot get_notifications to use pygh --- app/git/utils.py | 8 ++++++++ .../management/commands/get_notifications.py | 15 ++++++--------- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/app/git/utils.py b/app/git/utils.py index 5d42be406d5..5e92ac123b0 100644 --- a/app/git/utils.py +++ b/app/git/utils.py @@ -525,6 +525,14 @@ def get_notifications(): return response.json() +def get_gh_notifications(): + """Get the Github notifications for Gitcoin Bot.""" + gh_client = github_connect() + repo_user = gh_client.get_user(login=settings.GITHUB_API_USER) + notifications = repo_user.get_notifications(all=True) + return notifications + + def post_issue_comment(owner, repo, issue_num, comment): """Post a comment on an issue.""" url = f'https://api.github.com/repos/{owner}/{repo}/issues/{issue_num}/comments' diff --git a/app/gitcoinbot/management/commands/get_notifications.py b/app/gitcoinbot/management/commands/get_notifications.py index 04bf248d37e..d1828fb7c7b 100644 --- a/app/gitcoinbot/management/commands/get_notifications.py +++ b/app/gitcoinbot/management/commands/get_notifications.py @@ -23,27 +23,24 @@ from django.utils import timezone from git.utils import ( - get_issue_comments, get_notifications, issue_number, org_name, post_issue_comment_reaction, repo_name, + get_gh_notifications, get_issue_comments, issue_number, org_name, post_issue_comment_reaction, repo_name, ) class Command(BaseCommand): - # https://github.com/gitcoinco/web/issues/596 help = 'gets gitcoinbot notifications and responds if the user needs to install the app to get them to work' def handle(self, *args, **options): - - notifications = get_notifications() - print(len(notifications)) + notifications = get_gh_notifications() + print('Notifications Count: ', len(notifications)) for notification in notifications: - process_me = notification['reason'] == 'mention' - if process_me: + if notification.reason == 'mention': try: - url = notification['subject']['url'] + url = notification.subject.url url = url.replace('/repos', '') url = url.replace('//api.github', '//github') - latest_comment_url = notification['subject']['latest_comment_url'] + latest_comment_url = notification.subject.latest_comment_url _org_name = org_name(url) _repo_name = repo_name(url) _issue_number = issue_number(url)