def handle(self, *args, **options): notifications = get_notifications() print(len(notifications)) for notification in notifications: process_me = notification['reason'] == 'mention' if process_me: 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') comment = f"@{comment_from}. :wave: thanks for the atMention, but you need to [install @gitcoinbot on this repo for me to be able to respond](https://github.com/apps/gitcoinbot). More details [in the documentation](https://github.com/gitcoinco/web/tree/master/app/gitcoinbot).\n\n:v:\n@gitcoinbot" post_issue_comment(_org_name, _repo_name, _issue_number, comment) except Exception as e: logging.exception(e) print(e)
def handle(self, *args, **options): num_days_back_to_warn = 3 num_days_back_to_delete_interest = 7 days = [i * 3 for i in range(1, 15)] if settings.DEBUG: days = range(1, 1000) for day in days: interests = Interest.objects.filter( created__gte=(timezone.now() - timezone.timedelta(days=(day+1))), created__lt=(timezone.now() - timezone.timedelta(days=day)), ).all() print('day {} got {} interests'.format(day, interests.count())) for interest in interests: for bounty in Bounty.objects.filter(interested=interest, current_bounty=True, idx_status__in=['open', 'started', 'submitted']): print("{} is interested in {}".format(interest, bounty)) try: owner = org_name(bounty.github_url) repo = repo_name(bounty.github_url) issue_num = issue_number(bounty.github_url) comments = get_issue_comments(owner, repo, issue_num) comments_by_interested_party = [comment for comment in comments if comment['user']['login'] == interest.profile.handle] should_warn_user = False should_delete_interest = False last_heard_from_user_days = None if len(comments_by_interested_party) == 0: should_warn_user = True should_delete_interest = False else: # example format: 2018-01-26T17:56:31Z' time_format = '%Y-%m-%dT%H:%M:%SZ' last_comment_by_user = datetime.strptime(comments_by_interested_party[0]['created_at'], time_format) delta_now_vs_last_comment = datetime.now() - last_comment_by_user last_heard_from_user_days = delta_now_vs_last_comment.days should_warn_user = last_heard_from_user_days >= num_days_back_to_warn should_delete_interest = last_heard_from_user_days >= num_days_back_to_delete_interest if should_delete_interest: print('executing should_delete_interest for {}'.format(interest.pk)) bounty_startwork_expired(interest.profile.email, bounty, interest, last_heard_from_user_days) interest.delete() elif should_warn_user: print('executing should_warn_user for {}'.format(interest.pk)) bounty_startwork_expire_warning(interest.profile.email, bounty, interest, last_heard_from_user_days) except Exception as e: print(e)
def get_relative_url(self, preceding_slash=True): """Get the relative URL for the Bounty. Attributes: preceding_slash (bool): Whether or not to include a preceding slash. Returns: str: The relative URL for the Bounty. """ try: _org_name = org_name(self.github_url) _issue_num = int(issue_number(self.github_url)) _repo_name = repo_name(self.github_url) return f"{'/' if preceding_slash else ''}issue/{_org_name}/{_repo_name}/{_issue_num}" except Exception: return f"{'/' if preceding_slash else ''}funding/details?url={self.github_url}"
def handle(self, *args, **options): notifications = get_notifications() print(len(notifications)) for notification in notifications: process_me = notification['reason'] == 'mention' if process_me: 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)
def github_issue_number(self): try: return int(issue_number(self.github_url)) except Exception: return None
def handle(self, *args, **options): num_days_back_to_warn = 3 num_days_back_to_delete_interest = 7 days = [i * 3 for i in range(1, 15)] if settings.DEBUG: days = range(1, 1000) for day in days: interests = Interest.objects.filter( created__gte=(timezone.now() - timezone.timedelta(days=(day + 1))), created__lt=(timezone.now() - timezone.timedelta(days=day)), ).all() print('day {} got {} interests'.format(day, interests.count())) for interest in interests: for bounty in Bounty.objects.filter( interested=interest, current_bounty=True, idx_status__in=['open', 'started']): print("{} is interested in {}".format(interest, bounty)) try: owner = org_name(bounty.github_url) repo = repo_name(bounty.github_url) issue_num = issue_number(bounty.github_url) comments = get_issue_comments(owner, repo, issue_num) comments_by_interested_party = [ comment for comment in comments if comment['user'] ['login'] == interest.profile.handle ] should_warn_user = False should_delete_interest = False last_heard_from_user_days = None if len(comments_by_interested_party) == 0: should_warn_user = True should_delete_interest = False else: # example format: 2018-01-26T17:56:31Z' comment_times = [ datetime.strptime(comment['created_at'], '%Y-%m-%dT%H:%M:%SZ') for comment in comments_by_interested_party ] last_comment_by_user = max(comment_times) # if user hasn't commented since they expressed interest, handled this condition # per https://github.com/gitcoinco/web/issues/462#issuecomment-368384384 if last_comment_by_user < interest.created_at.replace( tzinfo=None): last_comment_by_user = interest.created_at.replace( tzinfo=None) # some small calcs delta_now_vs_last_comment = datetime.now( ) - last_comment_by_user last_heard_from_user_days = delta_now_vs_last_comment.days # decide action params should_warn_user = last_heard_from_user_days >= num_days_back_to_warn should_delete_interest = last_heard_from_user_days >= num_days_back_to_delete_interest print( f"- its been {last_heard_from_user_days} days since we heard from the user" ) if should_delete_interest: print('executing should_delete_interest for {}'. format(interest.pk)) bounty_startwork_expired( interest.profile.email, bounty, interest, last_heard_from_user_days) interest.delete() elif should_warn_user: print('executing should_warn_user for {}'.format( interest.pk)) bounty_startwork_expire_warning( interest.profile.email, bounty, interest, last_heard_from_user_days) except Exception as e: print(e)