Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
0
    def test_post_issue_comment_reaction(self):
        """Test the github utility post_issue_comment_reaction method."""
        comment_id = 1
        owner = 'gitcoinco'
        repo = 'web'
        url = f'https://api.github.com/repos/{owner}/{repo}/issues/comments/{comment_id}/reactions'
        responses.add(responses.POST,
                      url,
                      headers=HEADERS,
                      json={},
                      status=200)
        post_issue_comment_reaction(owner, repo, comment_id, 'A comment.')

        assert responses.calls[0].request.url == url
Exemplo n.º 4
0
def determine_response(owner, repo, comment_id, comment_text, issue_id,
                       install_id, sender):
    help_regex = r'@?[Gg]itcoinbot\s[Hh]elp'
    bounty_regex = r'@?[Gg]itcoinbot\s[Bb]ounty\s\d*\.?(\d+\s?)'
    submit_work_regex = r'@?[Gg]itcoinbot\s[Ss]ubmit(\s[Ww]ork)?'
    tip_regex = r'@?[Gg]itcoinbot\s[Tt]ip\s@\w*\s\d*\.?(\d+\s?)'
    start_work_regex = r'@?[Gg]itcoinbot\s[Ss]tart(\s[Ww]ork)?'

    if re.match(help_regex, comment_text) is not None:
        post_issue_comment_reaction(owner, repo, comment_id, '+1')
        post_gitcoin_app_comment(owner, repo, issue_id, help_text(),
                                 install_id)
    elif re.match(bounty_regex, comment_text) is not None:
        post_issue_comment_reaction(owner, repo, comment_id, '+1')
        bounty_text = new_bounty_text(owner, repo, issue_id, comment_text)
        post_gitcoin_app_comment(owner, repo, issue_id, bounty_text,
                                 install_id)
    elif re.match(submit_work_regex, comment_text) is not None:
        post_issue_comment_reaction(owner, repo, comment_id, '+1')
        result_text = submit_work_or_new_bounty_text(owner, repo, issue_id)
        post_gitcoin_app_comment(owner, repo, issue_id, result_text,
                                 install_id)
    elif re.match(tip_regex, comment_text) is not None:
        post_issue_comment_reaction(owner, repo, comment_id, 'heart')
        tip_text = new_tip_text(owner, repo, issue_id, comment_text)
        post_gitcoin_app_comment(owner, repo, issue_id, tip_text, install_id)
    elif re.match(start_work_regex, comment_text) is not None:
        post_issue_comment_reaction(owner, repo, comment_id, 'heart')
        start_text = start_work_text(owner, repo, issue_id)
        post_gitcoin_app_comment(owner, repo, issue_id, start_text, install_id)
    else:
        only_message = re.sub(r'@?[Gg]itcoinbot\s', '', comment_text)
        text_response = get_text_from_query_responses(
            re.sub(r'</?\[\d+>', '', only_message), sender)

        if text_response:
            post_issue_comment_reaction(owner, repo, comment_id, 'hooray')
            post_gitcoin_app_comment(owner, repo, issue_id, text_response,
                                     install_id)
        else:
            post_issue_comment_reaction(owner, repo, comment_id, 'confused')