Пример #1
0
    def create_issue(issue_title, description):

        params = github._decorate_issue_params(issue_title, description)

        github_url = "https://api.github.com/repos/" + repository[
            'path'] + "/issues"
        headers = {
            "Authorization": "token " + GITHUB_TOKEN,
            "Content-Type": "application/json",
            "Cache-Control": "no-cache, no-store, must-revalidate"
        }

        # Setup the request
        try:
            r = requests.post(github_url, headers=headers, data=params)
        except:
            return print(
                "Github issue creation failed, please ensure that your repository path is properly configured"
            )

        issue_number = r.json()['number']
        with open(DEFAULT_WALLET_PATH, 'r') as f:
            json_data = json.load(f)
            ## ISSUE_TITLE is set as the wallet label / name
            json_data[-1]['issue_number'] = issue_number

        with open(DEFAULT_WALLET_PATH, 'w') as f:
            f.write(json.dumps(json_data))

        # Send tweet
        twitter.send("Bounty Issued: " + issue_title +
                     " https://github.com/21hackers/git-money/issues/" +
                     str(issue_number))
        # TODO: Take the response and check for an ACK, then return true, else handle error
        print(r.json())
Пример #2
0
    def create_issue(issue_title, description):

        params = github._decorate_issue_params(issue_title, description)

        github_url = "https://api.github.com/repos/" + repository['path'] + "/issues"
        headers = { "Authorization": "token " + GITHUB_TOKEN,
                    "Content-Type": "application/json",
                    "Cache-Control": "no-cache, no-store, must-revalidate"
        }

        # Setup the request
        try: 
            r = requests.post(github_url, headers=headers, data=params)
        except:
            return print("Github issue creation failed, please ensure that your repository path is properly configured")

        issue_number=r.json()['number']
        with open(DEFAULT_WALLET_PATH, 'r') as f:
            json_data = json.load(f)
            ## ISSUE_TITLE is set as the wallet label / name
            json_data[-1]['issue_number'] = issue_number

        with open(DEFAULT_WALLET_PATH, 'w') as f:
            f.write(json.dumps(json_data))

        # Send tweet
        twitter.send("Bounty Issued: " + issue_title + " https://github.com/21hackers/git-money/issues/" + str(issue_number))
        # TODO: Take the response and check for an ACK, then return true, else handle error
        print(r.json())
Пример #3
0
def index():
    if request.method == 'GET':
        return 'OK'
    elif request.method == 'POST':
        # Store the IP address of the requester
        request_ip = ipaddress.ip_address(u'{0}'.format(request.remote_addr))

        # If GHE_ADDRESS is specified, use it as the hook_blocks.
        if os.environ.get('GHE_ADDRESS', None):
            hook_blocks = [os.environ.get('GHE_ADDRESS')]
        # Otherwise get the hook address blocks from the API.
        else:
            hook_blocks = requests.get(
                'https://api.github.com/meta').json()['hooks']

        if request.headers.get('X-GitHub-Event') == "ping":
            return json.dumps({'msg': 'Hi!'})

        if request.headers.get('X-GitHub-Event') == 'pull_request':
            if (request.json['pull_request']['user']['site_admin'] == 'false'):
                return json.dumps(
                    {'message': 'Pull request not submitted by site admin'})
            merge_state = request.json['pull_request']['state']
            merge_body = request.json['pull_request']['body']
            if (merge_state == 'closed'):
                print('Merge state closed')
                print('Merge Body: ' + merge_body)
                parsed_bounty_issue = re.findall(r"#(\w+)", merge_body)[0]
                addresses = CommonRegex(merge_body).btc_addresses[0]
                bounty_address = github.get_address_from_issue(
                    parsed_bounty_issue)
                amount = multisig_wallet.get_address_balance(bounty_address)
                try:
                    # use username to look up wallet Id
                    with open(DEFAULT_WALLET_PATH, 'r') as wallet:
                        data = json.loads(wallet.read())
                    for user in data:
                        try:
                            if (user['issue_number'] == int(
                                    parsed_bounty_issue)):
                                print('Wallet found')
                                wallet_name = user['wallet_name']
                                walletId = user[wallet_name]['walletId']
                        except:
                            print('Loading wallet..')

                except:
                    print('Wallet not found, creating new user...')

                # Set up sending of the bounty

                issue_title = wallet_name
                repository_path_encode = repository_path.encode('utf-8')
                issue_title_encode = issue_title.encode('utf-8')
                passphrase = hashlib.sha256(repository_path_encode +
                                            issue_title_encode).hexdigest()
                multisig_wallet.send_bitcoin_simple(walletId, str(addresses),
                                                    amount, passphrase)

                # Set up sending of the tweet

                usd_per_btc = requests.get(
                    'https://bitpay.com/api/rates/usd').json()['rate']
                bounty_in_btc = round((int(bounty_in_satoshi) / 10**8), 3)
                bounty_in_usd = round(bounty_in_btc * usd_per_btc, 2)
                url = 'https://github.com/21hackers/git-money/issues/' + parsed_bounty_issue
                twitter.send('Bounty Granted (' + amount + ' bits ~ $' +
                             bounty_in_usd + '): ' + issue_title + ' ' + url)

                return json.dumps({'message': 'Pull request received'})
            return json.dumps({'message': 'Pull request payout failed'})

        if request.headers.get('X-GitHub-Event') == 'issue_comment':
            comment_data = {
                'url': request.json['comment']['issue_url'],
                'payout_address': request.json['issue']['labels'][0]['name'],
                'payout_amount': request.json['issue']['labels'][1]['name'],
                'body': request.json['comment']['body']
            }
            print(comment_data)
            return json.dumps({'message': 'Issue comment received'})
Пример #4
0
def index():
    if request.method == "GET":
        return "OK"
    elif request.method == "POST":
        # Store the IP address of the requester
        request_ip = ipaddress.ip_address(u"{0}".format(request.remote_addr))

        # If GHE_ADDRESS is specified, use it as the hook_blocks.
        if os.environ.get("GHE_ADDRESS", None):
            hook_blocks = [os.environ.get("GHE_ADDRESS")]
        # Otherwise get the hook address blocks from the API.
        else:
            hook_blocks = requests.get("https://api.github.com/meta").json()["hooks"]

        if request.headers.get("X-GitHub-Event") == "ping":
            return json.dumps({"msg": "Hi!"})

        if request.headers.get("X-GitHub-Event") == "pull_request":
            if request.json["pull_request"]["user"]["site_admin"] == "false":
                return json.dumps({"message": "Pull request not submitted by site admin"})
            merge_state = request.json["pull_request"]["state"]
            merge_body = request.json["pull_request"]["body"]
            if merge_state == "closed":
                print("Merge state closed")
                print("Merge Body: " + merge_body)
                parsed_bounty_issue = re.findall(r"#(\w+)", merge_body)[0]
                addresses = CommonRegex(merge_body).btc_addresses[0]
                bounty_address = github.get_address_from_issue(parsed_bounty_issue)
                amount = multisig_wallet.get_address_balance(bounty_address)
                try:
                    # use username to look up wallet Id
                    with open(DEFAULT_WALLET_PATH, "r") as wallet:
                        data = json.loads(wallet.read())
                    for user in data:
                        try:
                            if user["issue_number"] == int(parsed_bounty_issue):
                                print("Wallet found")
                                wallet_name = user["wallet_name"]
                                walletId = user[wallet_name]["walletId"]
                        except:
                            print("Loading wallet..")

                except:
                    print("Wallet not found, creating new user...")

                # Set up sending of the bounty

                issue_title = wallet_name
                repository_path_encode = repository_path.encode("utf-8")
                issue_title_encode = issue_title.encode("utf-8")
                passphrase = hashlib.sha256(repository_path_encode + issue_title_encode).hexdigest()
                multisig_wallet.send_bitcoin_simple(walletId, str(addresses), amount, passphrase)

                # Set up sending of the tweet

                usd_per_btc = requests.get("https://bitpay.com/api/rates/usd").json()["rate"]
                bounty_in_btc = round((int(bounty_in_satoshi) / 10 ** 8), 3)
                bounty_in_usd = round(bounty_in_btc * usd_per_btc, 2)
                url = "https://github.com/21hackers/git-money/issues/" + parsed_bounty_issue
                twitter.send(
                    "Bounty Granted (" + amount + " bits ~ $" + bounty_in_usd + "): " + issue_title + " " + url
                )

                return json.dumps({"message": "Pull request received"})
            return json.dumps({"message": "Pull request payout failed"})

        if request.headers.get("X-GitHub-Event") == "issue_comment":
            comment_data = {
                "url": request.json["comment"]["issue_url"],
                "payout_address": request.json["issue"]["labels"][0]["name"],
                "payout_amount": request.json["issue"]["labels"][1]["name"],
                "body": request.json["comment"]["body"],
            }
            print(comment_data)
            return json.dumps({"message": "Issue comment received"})