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 maybe_market_tip_to_github(tip): if not settings.GITHUB_CLIENT_ID: return False if not tip.github_url: return False if tip.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False # prepare message username = tip.username if '@' in tip.username else str('@' + tip.username) _from = " from {}".format(tip.from_name) if tip.from_name else "" warning = tip.network if tip.network != 'mainnet' else "" _comments = "\n\nThe sender had the following public comments: \n> {}".format(tip.comments_public) if tip.comments_public else "" msg = "⚡️ A tip worth {} {} {} {} has been granted to {} for this issue{}. ⚡️ {}\n\nNice work {}, check your email for further instructions. \n\n * ${} in Funded OSS Work Available at: https://gitcoin.co/explorer\n * Incentivize contributions to your repo: <a href='https://gitcoin.co/tip'>Send a Tip</a> or <a href='https://gitcoin.co/funding/new'>Fund a PR</a>\n * No Email? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>" msg = msg.format(round(tip.amount, 3), warning, tip.tokenName, "(${})".format(tip.value_in_usdt) if tip.value_in_usdt else "" , username, _from, _comments, username, amount_usdt_open_work()) # actually post url = tip.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] post_issue_comment(username, repo, issue_num, msg) except Exception as e: print(e) return False return True
def maybe_warn_user_removed_github(bounty, username): if (not settings.GITHUB_CLIENT_ID) or ( bounty.get_natural_value() < 0.0001) or ( bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK): return False msg = f"@{username} are you still working on this issue?" post_issue_comment(bounty.org_name, bounty.github_repo_name, bounty.github_issue_number, msg)
def test_post_issue_comment(self): """Test the github utility post_issue_comment method.""" owner = 'gitcoinco' repo = 'web' issue_num = 1 url = f'https://api.github.com/repos/{owner}/{repo}/issues/{issue_num}/comments' responses.add(responses.POST, url, headers=HEADERS, json={}, status=200) post_issue_comment(owner, repo, issue_num, 'A comment.') assert responses.calls[0].request.url == url
def maybe_warn_user_removed_github(bounty, username, last_heard_from_user_days): if not bounty.is_notification_eligible(var_to_check=settings.GITHUB_CLIENT_ID): return False msg = f"""@{username} Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions! * [x] warning ({num_days_back_to_warn} days) * [ ] escalation to mods ({num_days_back_to_delete_interest} days) {append_snooze_copy(bounty)}""" post_issue_comment(bounty.org_name, bounty.github_repo_name, bounty.github_issue_number, msg)
def maybe_notify_user_removed_github(bounty, username, last_heard_from_user_days=None): if (not settings.GITHUB_CLIENT_ID) or ( bounty.get_natural_value() < 0.0001) or ( bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK): return False msg = f"@{username} has been removed from this issue due to inactivity ({last_heard_from_user_days} days) on the github thread. @{username} if you believe this was done in error, please <a href={bounty.url}>go to the bounty</a> and click 'start work' again." post_issue_comment(bounty.org_name, bounty.github_repo_name, bounty.github_issue_number, msg)
def maybe_warn_user_removed_github(bounty, username, last_heard_from_user_days): if (not settings.GITHUB_CLIENT_ID) or ( bounty.get_natural_value() < 0.0001) or ( bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK): return False msg = f"""@{username} Hello from Gitcoin Core - are you still working on this issue? Please submit a WIP PR or comment back within the next 3 days or you will be removed from this ticket and it will be returned to an ‘Open’ status. Please let us know if you have questions! * [x] warning ({num_days_back_to_warn} days) * [ ] auto removal ({num_days_back_to_delete_interest} days) """ post_issue_comment(bounty.org_name, bounty.github_repo_name, bounty.github_issue_number, msg)
def maybe_notify_user_escalated_github(bounty, username, last_heard_from_user_days=None): if not bounty.is_notification_eligible(var_to_check=settings.GITHUB_CLIENT_ID): return False if not last_heard_from_user_days: last_heard_from_user_days = num_days_back_to_delete_interest status_header = get_status_header(bounty) msg = f"""{status_header}@{username} due to inactivity, we have escalated [this issue]({bounty.url}) to Gitcoin's moderation team. Let us know if you believe this has been done in error! * [x] warning ({num_days_back_to_warn} days) * [x] escalation to mods ({num_days_back_to_delete_interest} days) {append_snooze_copy(bounty)}""" post_issue_comment(bounty.org_name, bounty.github_repo_name, bounty.github_issue_number, msg)
def maybe_market_tip_to_github(tip): """Post a Github comment for the specified Tip. Args: tip (dashboard.models.Tip): The Tip to be marketed. Returns: bool: Whether or not the Github comment was posted successfully. """ if (not settings.GITHUB_CLIENT_ID) or (not tip.github_url) or ( tip.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK): return False # prepare message username = tip.username if '@' in tip.username else f'@{tip.username}' _from = f" from {tip.from_name}" if tip.from_name else "" warning = tip.network if tip.network != 'mainnet' else "" _comments = "\n\nThe sender had the following public comments: \n> " \ f"{tip.comments_public}" if tip.comments_public else "" try: value_in_usd = f"({tip.value_in_usdt_now} USD @ ${round(convert_token_to_usdt(tip.tokenName), 2)}/{tip.tokenName})" if tip.value_in_usdt_now else "" except Exception: pass # no USD conv rate msg = f"⚡️ A tip worth {round(tip.amount, 5)} {warning} {tip.tokenName} {value_in_usd} has been " \ f"granted to {username} for this issue{_from}. ⚡️ {_comments}\n\nNice work {username}! To " \ "redeem your tip, login to Gitcoin at https://gitcoin.co/explorer and select 'Claim Tip' " \ "from dropdown menu in the top right, or check your email for a link to the tip redemption " \ f"page. \n\n * ${amount_usdt_open_work()} in Funded OSS Work Available at: " \ "https://gitcoin.co/explorer\n * Incentivize contributions to your repo: " \ "<a href='https://gitcoin.co/tip'>Send a Tip</a> or <a href='https://gitcoin.co/funding/new'>" \ "Fund a PR</a>\n * No Email? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>" # actually post url = tip.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] post_issue_comment(username, repo, issue_num, msg) except Exception as e: print(e) return False return True
def maybe_market_tip_to_github(tip): """Post a Github comment for the specified Tip. Args: tip (dashboard.models.Tip): The Tip to be marketed. Returns: bool: Whether or not the Github comment was posted successfully. """ if not settings.GITHUB_CLIENT_ID: return False if not tip.github_url: return False if tip.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False # prepare message username = tip.username if '@' in tip.username else str('@' + tip.username) _from = " from {}".format(tip.from_name) if tip.from_name else "" warning = tip.network if tip.network != 'mainnet' else "" _comments = "\n\nThe sender had the following public comments: \n> {}".format( tip.comments_public) if tip.comments_public else "" msg = "⚡️ A tip worth {} {} {} {} has been granted to {} for this issue{}. ⚡️ {}\n\nNice work {}! To redeem your tip, login to Gitcoin at https://gitcoin.co/explorer and select 'Claim Tip' from dropdown menu in the top right, or check your email for a link to the tip redemption page. \n\n * ${} in Funded OSS Work Available at: https://gitcoin.co/explorer\n * Incentivize contributions to your repo: <a href='https://gitcoin.co/tip'>Send a Tip</a> or <a href='https://gitcoin.co/funding/new'>Fund a PR</a>\n * No Email? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>" msg = msg.format( round(tip.amount, 5), warning, tip.tokenName, "(${})".format(tip.value_in_usdt) if tip.value_in_usdt else "", username, _from, _comments, username, amount_usdt_open_work()) # actually post url = tip.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] post_issue_comment(username, repo, issue_num, msg) except Exception as e: print(e) return False return True
def maybe_notify_user_removed_github(bounty, username, last_heard_from_user_days=None): if (not settings.GITHUB_CLIENT_ID) or ( bounty.get_natural_value() < 0.0001) or ( bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK): return False if not last_heard_from_user_days: last_heard_from_user_days = num_days_back_to_delete_interest status_header = get_status_header(bounty) msg = f"""{status_header}@{username} has been removed for inactivity and [the issue]({bounty.url}) has been returned to an ‘Open’ Status. Let us know if you believe this has been done in error! * [x] warning ({num_days_back_to_warn} days) * [x] auto removal ({num_days_back_to_delete_interest} days) """ post_issue_comment(bounty.org_name, bounty.github_repo_name, bounty.github_issue_number, msg)
def maybe_notify_user_escalated_github(bounty, username, last_heard_from_user_days=None): if (not settings.GITHUB_CLIENT_ID) or ( bounty.get_natural_value() < 0.0001) or ( bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK): return False if not last_heard_from_user_days: last_heard_from_user_days = num_days_back_to_delete_interest status_header = get_status_header(bounty) msg = f"""{status_header}@{username} due to inactivity, we have escalated [this issue]({bounty.url}) to Gitcoin's moderation team. Let us know if you believe this has been done in error! * [x] warning ({num_days_back_to_warn} days) * [x] escalation to mods ({num_days_back_to_delete_interest} days) {append_snooze_copy(bounty)}""" post_issue_comment(bounty.org_name, bounty.github_repo_name, bounty.github_issue_number, msg)
def maybe_market_to_github(bounty, event_name, profile_pairs=None): """Post a Github comment for the specified Bounty. Args: bounty (dashboard.models.Bounty): The Bounty to be marketed. event_name (str): The name of the event. profile_pairs (list of tuples): The list of username and profile page URL tuple pairs. Returns: bool: Whether or not the Github comment was posted successfully. """ if (not settings.GITHUB_CLIENT_ID) or ( bounty.get_natural_value() < 0.0001) or ( bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK): return False # Define posting specific variables. comment_id = None url = bounty.github_url uri = parse(url).path uri_array = uri.split('/') # Prepare the comment message string. msg = build_github_notification(bounty, event_name, profile_pairs) if not msg: return False try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] if event_name == 'work_started': comment_id = bounty.interested_comment elif event_name in ['work_done', 'work_submitted']: comment_id = bounty.submissions_comment # Handle creating or updating comments if profiles are provided. if event_name in ['work_started', 'work_submitted'] and profile_pairs: if comment_id is not None: patch_issue_comment(comment_id, username, repo, msg) else: response = post_issue_comment(username, repo, issue_num, msg) if response.get('id'): if event_name == 'work_started': bounty.interested_comment = int(response.get('id')) elif event_name in ['work_done', 'work_submitted']: bounty.submissions_comment = int(response.get('id')) bounty.save() # Handle deleting comments if no profiles are provided. elif event_name in ['work_started'] and not profile_pairs: if comment_id: delete_issue_comment(comment_id, username, repo) if event_name == 'work_started': bounty.interested_comment = None elif event_name == 'work_done': bounty.submissions_comment = None bounty.save() # If this isn't work_started/done, simply post the issue comment. else: post_issue_comment(username, repo, issue_num, msg) except IndexError: return False except Exception as e: extra_data = { 'github_url': url, 'bounty_id': bounty.pk, 'event_name': event_name } rollbar.report_exc_info(sys.exc_info(), extra_data=extra_data) print(e) return False return True
def maybe_market_to_github(bounty, event_name, txid=None, interested=None): if not settings.GITHUB_CLIENT_ID: return False if bounty.get_natural_value() < 0.0001: return False if bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False # prepare message msg = '' usdt_value = "(" + str(round(bounty.value_in_usdt, 2)) + " USD)" if bounty.value_in_usdt else "" if event_name == 'new_bounty': msg = "__This issue now has a funding of {} {} {} attached to it.__\n\n * If you would like to work on this issue you can claim it [here]({}).\n * If you've completed this issue and want to claim the bounty you can do so [here]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, bounty.get_absolute_url(), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'killed_bounty': msg = "__The funding of {} {} {} attached to this issue has been **killed** by the bounty submitter__\n\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, amount_usdt_open_work(), ) elif event_name == 'rejected_claim': msg = "__This fulfillment for the funding of {} {} {} attached to this issue has been **rejected** and can now be fulfilled by someone else.__\n\n * If you would like to work on this issue you can claim it [here]({}).\n * If you've completed this issue and want to claim the bounty you can do so [here]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, bounty.get_absolute_url(), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'new_interest': msg = "__The funding of {} {} {} attached has been shown interest by: {}.__ {} \n\n * Learn more [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" # Build interested profiles string. interested_profiles = ", ".join("[@%s](%s)" % interest for interest in interested) msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, interested_profiles if interested_profiles else "", "\n\n If you are interested, please leave a comment to let the funder {} and the other parties involved why you're interested in working on this issue and your plans to resolve it. If you don't leave a comment, the funder may not think you're too interested.".format( "(@{})".format(bounty.bounty_owner_github_username) if bounty.bounty_owner_github_username else "", ), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'new_claim': msg = "__The funding of {} {} {} attached has been fulfilled {}.__ {} \n\n * Learn more [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, "by @{}".format(bounty.claimee_github_username) if bounty.claimee_github_username else "", "\n\n {}, please leave a comment to let the funder {} (and the other parties involved) that you've fulfilled the bounty. If you don't leave a comment, the funder may expire your claim at their discretion.".format( "@{}".format(bounty.claimee_github_username) if bounty.claimee_github_username else "If you are the claimee", "(@{})".format(bounty.bounty_owner_github_username) if bounty.bounty_owner_github_username else "", ), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'approved_claim': msg = "__The funding of {} {} {} attached to this issue has been approved & issued {}.__ \n\n * Learn more at [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, "to @{}".format(bounty.claimee_github_username) if bounty.claimee_github_username else "", bounty.get_absolute_url(), amount_usdt_open_work(), ) else: return False # actually post url = bounty.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] if event_name == 'new_interest' and interested: if bounty.interested_comment is not None: patch_issue_comment(bounty.interested_comment, username, repo, msg) else: response = post_issue_comment(username, repo, issue_num, msg) if response.get('id'): bounty.interested_comment = response.get('id') bounty.save() elif event_name == 'new_interest' and not interested: delete_issue_comment(bounty.interested_comment, username, repo) bounty.interested_comment = None bounty.save() else: post_issue_comment(username, repo, issue_num, msg) except Exception as e: extra_data = {'github_url': url, 'bounty_id': bounty.pk, 'event_name': event_name} rollbar.report_exc_info(sys.exc_info(), extra_data=extra_data) print(e) return False return True
def maybe_market_to_github(bounty, event_name, interested=None): """Post a Github comment for the specified Bounty. Args: bounty (dashboard.models.Bounty): The Bounty to be marketed. event_name (str): The name of the event. interested (list of tuples): The list of username and profile page URL tuple pairs. Returns: bool: Whether or not the Github comment was posted successfully. """ if not settings.GITHUB_CLIENT_ID: return False if bounty.get_natural_value() < 0.0001: return False if bounty.network != settings.ENABLE_NOTIFICATIONS_ON_NETWORK: return False # prepare message msg = '' usdt_value = "(" + str(round(bounty.value_in_usdt, 2)) + " USD)" if bounty.value_in_usdt else "" if event_name == 'new_bounty': msg = "__This issue now has a funding of {} {} {} attached to it.__\n\n * If you would like to work on this issue you can claim it [here]({}).\n * If you've completed this issue and want to claim the bounty you can do so [here]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, bounty.get_absolute_url(), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'killed_bounty': msg = "__The funding of {} {} {} attached to this issue has been **killed** by the bounty submitter__\n\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, amount_usdt_open_work(), ) elif event_name == 'rejected_claim': msg = "__The work submission for {} {} {} has been **rejected** and can now be submitted by someone else.__\n\n * If you would like to work on this issue you can claim it [here]({}).\n * If you've completed this issue and want to claim the bounty you can do so [here]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, bounty.get_absolute_url(), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'work_started': msg = "__Work has been started on the {} {} {} funding by__: \n 1. {} {} \n\n * Learn more [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" # Build interested profiles string. interested_profiles = "\n 1. ".join("[@%s](%s)" % interest for interest in interested) msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, interested_profiles if interested_profiles else "", "\n\n __Please work together__ and coordinate delivery of the issue scope. Gitcoin doesn't know enough about everyones skillsets / free time to say who should work on what, but we trust that the community is smart and well-intentioned enough to work together. As a general rule; if you start work first, youll be at the top of the above list ^^, and should have 'dibs' as long as you follow through. \n\n On the above list? Please leave a comment to let the funder {} and the other parties involved what you're working, with respect to this issue and your plans to resolve it. If you don't leave a comment, the funder may expire your submission at their discretion." .format( "(@{})".format(bounty.bounty_owner_github_username) if bounty.bounty_owner_github_username else "", ), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'work_submitted': msg = "__Work for {} {} {} has been submitted {}.__ {} \n\n * Learn more [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, "by @{}".format(bounty.fulfiller_github_username) if bounty.fulfiller_github_username else "", "\n\n {}, please leave a comment to let the funder {} (and the other parties involved) that you've submitted you work. If you don't leave a comment, the funder may expire your submission at their discretion." .format( "@{}".format(bounty.fulfiller_github_username) if bounty.fulfiller_github_username else "If you are the claimee", "(@{})".format(bounty.bounty_owner_github_username) if bounty.bounty_owner_github_username else "", ), bounty.get_absolute_url(), amount_usdt_open_work(), ) elif event_name == 'work_done': msg = "__The funding of {} {} {} attached to this issue has been approved & issued {}.__ \n\n * Learn more at [on the gitcoin issue page]({})\n * Questions? Get help on the <a href='https://gitcoin.co/slack'>Gitcoin Slack</a>\n * ${} more Funded OSS Work Available at: https://gitcoin.co/explorer\n" msg = msg.format( round(bounty.get_natural_value(), 4), bounty.token_name, usdt_value, "to @{}".format(bounty.fulfiller_github_username) if bounty.fulfiller_github_username else "", bounty.get_absolute_url(), amount_usdt_open_work(), ) else: return False # actually post url = bounty.github_url uri = parse(url).path uri_array = uri.split('/') try: username = uri_array[1] repo = uri_array[2] issue_num = uri_array[4] if event_name == 'work_started' and interested: if bounty.interested_comment is not None: patch_issue_comment(bounty.interested_comment, username, repo, msg) else: response = post_issue_comment(username, repo, issue_num, msg) if response.get('id'): bounty.interested_comment = int(response.get('id')) bounty.save() elif event_name == 'work_started' and not interested: delete_issue_comment(bounty.interested_comment, username, repo) bounty.interested_comment = None bounty.save() else: post_issue_comment(username, repo, issue_num, msg) except Exception as e: extra_data = { 'github_url': url, 'bounty_id': bounty.pk, 'event_name': event_name } rollbar.report_exc_info(sys.exc_info(), extra_data=extra_data) print(e) return False return True