예제 #1
0
    def test_get_issue_comments(self):
        """Test the github utility get_issue_comments method."""
        params = {
            'sort': 'created',
            'direction': 'desc',
            'per_page': 100,
        }
        params = urlencode(params, quote_via=quote_plus)
        owner = 'gitcoinco'
        repo = 'web'
        url = f'https://api.github.com/repos/{owner}/{repo}/issues/comments?' + params
        responses.add(responses.GET, url, headers=HEADERS, json={}, status=200)
        get_issue_comments(owner, repo)

        assert responses.calls[0].request.url == url
예제 #2
0
 def handle(self, *args, **options):
     notifications = get_gh_notifications()
     print('Notifications Count: ', notifications.totalCount)
     for notification in notifications:
         if notification.reason == 'mention':
             try:
                 url = notification.subject.url
                 url = url.replace('/repos', '')
                 url = url.replace('//api.github', '//github')
                 latest_comment_url = notification.subject.latest_comment_url
                 _org_name = org_name(url)
                 _repo_name = repo_name(url)
                 _issue_number = issue_number(url)
                 _comment_id = latest_comment_url.split('/')[-1]
                 comment = get_issue_comments(_org_name, _repo_name,
                                              _issue_number, _comment_id)
                 does_mention_gitcoinbot = settings.GITHUB_API_USER in comment.get(
                     'body', '')
                 if comment.get('message', '') == "Not Found":
                     print("comment was not found")
                 elif not does_mention_gitcoinbot:
                     print("does not mention gitcoinbot")
                 else:
                     comment_from = comment['user']['login']
                     num_reactions = comment['reactions']['total_count']
                     print(_org_name, _repo_name, _issue_number,
                           _comment_id, num_reactions, comment_from)
                     is_from_gitcoinbot = settings.GITHUB_API_USER in comment_from
                     if num_reactions == 0 and not is_from_gitcoinbot:
                         print("unprocessed")
                         post_issue_comment_reaction(
                             _org_name, _repo_name, _comment_id, 'heart')
             except Exception as e:
                 logging.exception(e)
                 print(e)
예제 #3
0
 def handle(self, *args, **options):
     notifications = get_notifications()
     try:
         print('Notifications Count: ', notifications.totalCount)
         for notification in notifications:
             if hasattr(notification,
                        '_subject') and notification.reason == 'mention':
                 try:
                     url = notification.subject.url
                     url = url.replace('/repos', '')
                     url = url.replace('//api.github', '//github')
                     latest_comment_url = notification.subject.latest_comment_url
                     if latest_comment_url is None:
                         print("no latest comment url")
                         continue
                     _org_name = org_name(url)
                     _repo_name = repo_name(url)
                     _issue_number = issue_number(url)
                     if not latest_comment_url:
                         continue
                     _comment_id = latest_comment_url.split('/')[-1]
                     comment = get_issue_comments(_org_name, _repo_name,
                                                  _issue_number,
                                                  _comment_id)
                     does_mention_gitcoinbot = settings.GITHUB_API_USER in comment.body
                     if isinstance(comment, dict) and comment.get(
                             'message', '') == 'Not Found':
                         print("comment was not found")
                     elif not does_mention_gitcoinbot:
                         print("does not mention gitcoinbot")
                     else:
                         comment_from = comment.user.login
                         num_reactions = comment.get_reactions().totalCount
                         print(_org_name, _repo_name, _issue_number,
                               _comment_id, num_reactions, comment_from)
                         is_from_gitcoinbot = settings.GITHUB_API_USER in comment_from
                         if num_reactions == 0 and not is_from_gitcoinbot:
                             print("unprocessed")
                             post_issue_comment_reaction(
                                 _org_name, _repo_name, _comment_id,
                                 'heart')
                 except RateLimitExceededException as e:
                     logging.debug(e)
                     print(e)
                     time.sleep(60)
                 except Exception as e:
                     logging.exception(e)
                     print(e)
     except RateLimitExceededException as e:
         logging.debug(e)
         print(e)
     except AttributeError as e:
         logging.debug(e)
         print(e)