Exemplo n.º 1
0
    def test_delete_issue_comment(self):
        """Test the github utility delete_issue_comment method."""
        comment_id = 1
        owner = 'gitcoinco'
        repo = 'web'
        url = f'https://api.github.com/repos/{owner}/{repo}/issues/comments/{comment_id}'
        responses.add(responses.DELETE, url, headers=HEADERS, json={}, status=200)
        result = delete_issue_comment(comment_id, owner, repo)

        assert responses.calls[0].request.url == url
        assert result == {}
Exemplo n.º 2
0
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
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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