def testpull(number, comment_url, clone_url, commit):
    print(('Testing pull %d: %s : %s' % (number, clone_url, commit)))
    dir = (((os.environ['RESULTS_DIR'] + '/') + commit) + '/')
    print((' ouput to %s' % dir))
    if os.path.exists(dir):
        os.system(('rm -r ' + dir))
    os.makedirs(dir)
    currentdir = (os.environ['RESULTS_DIR'] + '/current')
    os.system(('rm -r ' + currentdir))
    os.system(((('ln -s ' + dir) + ' ') + currentdir))
    out = open((dir + 'test.log'), 'w+')
    resultsurl = (os.environ['RESULTS_URL'] + commit)
    checkedout = checkout_pull(clone_url, commit, out)
    if (checkedout != True):
        print(('Failed to test pull - sending comment to: ' + comment_url))
        commentOn(comment_url, False, True, False, resultsurl)
        open(os.environ['TESTED_DB'], 'a').write((commit + '\n'))
        return
    run('rm -rf ${CHROOT_COPY}/${OUT_DIR}', fail_hard=False)
    run('mkdir -p ${CHROOT_COPY}/${OUT_DIR}', fail_hard=False)
    run('chown -R ${BUILD_USER}:${BUILD_GROUP} ${CHROOT_COPY}/${OUT_DIR}', fail_hard=False)
    script = (os.environ['BUILD_PATH'] + '/qa/pull-tester/pull-tester.sh')
    script += ' ${BUILD_PATH} ${MINGW_DEPS_DIR} ${SCRIPTS_DIR}/BitcoindComparisonTool_jar/BitcoindComparisonTool.jar 0 6 ${OUT_DIR}'
    returncode = run(('chroot ${CHROOT_COPY} sudo -u ${BUILD_USER} -H timeout ${TEST_TIMEOUT} ' + script), fail_hard=False, stdout=out, stderr=out)
    run(('mv ${CHROOT_COPY}/${OUT_DIR} ' + dir))
    run(('mv ${BUILD_DIR} ' + dir))
    if (returncode == 42):
        print(('Successfully tested pull (needs tests) - sending comment to: ' + comment_url))
        commentOn(comment_url, True, False, True, resultsurl)
    elif (returncode != 0):
        print(('Failed to test pull - sending comment to: ' + comment_url))
        commentOn(comment_url, False, False, False, resultsurl)
    else:
        print(('Successfully tested pull - sending comment to: ' + comment_url))
        commentOn(comment_url, True, False, False, resultsurl)
    open(os.environ['TESTED_DB'], 'a').write((commit + '\n'))
def testpull(number, comment_url, clone_url, commit):
    print(('Testing pull %d: %s : %s' % (number, clone_url, commit)))
    dir = (((os.environ['RESULTS_DIR'] + '/') + commit) + '/')
    print((' ouput to %s' % dir))
    if os.path.exists(dir):
        os.system(('rm -r ' + dir))
    os.makedirs(dir)
    currentdir = (os.environ['RESULTS_DIR'] + '/current')
    os.system(('rm -r ' + currentdir))
    os.system(((('ln -s ' + dir) + ' ') + currentdir))
    out = open((dir + 'test.log'), 'w+')
    resultsurl = (os.environ['RESULTS_URL'] + commit)
    checkedout = checkout_pull(clone_url, commit, out)
    if (checkedout != True):
        print(('Failed to test pull - sending comment to: ' + comment_url))
        commentOn(comment_url, False, True, False, resultsurl)
        open(os.environ['TESTED_DB'], 'a').write((commit + '\n'))
        return
    run('rm -rf ${CHROOT_COPY}/${OUT_DIR}', fail_hard=False)
    run('mkdir -p ${CHROOT_COPY}/${OUT_DIR}', fail_hard=False)
    run('chown -R ${BUILD_USER}:${BUILD_GROUP} ${CHROOT_COPY}/${OUT_DIR}', fail_hard=False)
    script = (os.environ['BUILD_PATH'] + '/qa/pull-tester/pull-tester.sh')
    script += ' ${BUILD_PATH} ${MINGW_DEPS_DIR} ${SCRIPTS_DIR}/BitcoindComparisonTool_jar/BitcoindComparisonTool.jar 0 6 ${OUT_DIR}'
    returncode = run(('chroot ${CHROOT_COPY} sudo -u ${BUILD_USER} -H timeout ${TEST_TIMEOUT} ' + script), fail_hard=False, stdout=out, stderr=out)
    run(('mv ${CHROOT_COPY}/${OUT_DIR} ' + dir))
    run(('mv ${BUILD_DIR} ' + dir))
    if (returncode == 42):
        print(('Successfully tested pull (needs tests) - sending comment to: ' + comment_url))
        commentOn(comment_url, True, False, True, resultsurl)
    elif (returncode != 0):
        print(('Failed to test pull - sending comment to: ' + comment_url))
        commentOn(comment_url, False, False, False, resultsurl)
    else:
        print(('Successfully tested pull - sending comment to: ' + comment_url))
        commentOn(comment_url, True, False, False, resultsurl)
    open(os.environ['TESTED_DB'], 'a').write((commit + '\n'))