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

Adjust gitcoin bot get_notifications to use pygithub #1977

Merged
merged 2 commits into from
Sep 27, 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
8 changes: 8 additions & 0 deletions app/git/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
15 changes: 6 additions & 9 deletions app/gitcoinbot/management/commands/get_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down