def post_easyconfigs_pr_test_report(pr_nr, test_report, msg,
                                    init_session_state, success):
    """Post test report in a gist, and submit comment in easyconfigs PR."""
    user = build_option('github_user')

    # create gist with test report
    descr = "EasyBuild test report for easyconfigs PR #%s" % pr_nr
    fn = 'easybuild_test_report_easyconfigs_pr%s_%s.md' % (
        pr_nr, strftime("%Y%M%d-UTC-%H-%M-%S", gmtime()))
    gist_url = upload_test_report_as_gist(test_report, descr=descr, fn=fn)

    # post comment to report test result
    system_info = init_session_state['system_info']
    short_system_info = "%(os_type)s %(os_name)s %(os_version)s, %(cpu_model)s, Python %(pyver)s" % {
        'cpu_model': system_info['cpu_model'],
        'os_name': system_info['os_name'],
        'os_type': system_info['os_type'],
        'os_version': system_info['os_version'],
        'pyver': system_info['python_version'].split(' ')[0],
    }
    comment_lines = [
        "Test report by @%s" % user,
        ('**FAILED**', '**SUCCESS**')[success],
        msg,
        short_system_info,
        "See %s for a full test report." % gist_url,
    ]
    comment = '\n'.join(comment_lines)
    post_comment_in_issue(pr_nr, comment, github_user=user)

    msg = "Test report uploaded to %s and mentioned in a comment in easyconfigs PR#%s" % (
        gist_url, pr_nr)
    return msg
def post_easyconfigs_pr_test_report(pr_nr, test_report, msg, init_session_state, success):
    """Post test report in a gist, and submit comment in easyconfigs PR."""
    user = build_option('github_user')

    # create gist with test report
    descr = "EasyBuild test report for easyconfigs PR #%s" % pr_nr
    fn = 'easybuild_test_report_easyconfigs_pr%s_%s.md' % (pr_nr, strftime("%Y%M%d-UTC-%H-%M-%S", gmtime()))
    gist_url = upload_test_report_as_gist(test_report, descr=descr, fn=fn)

    # post comment to report test result
    system_info = init_session_state['system_info']
    short_system_info = "%(hostname)s - %(os_type)s %(os_name)s %(os_version)s, %(cpu_model)s, Python %(pyver)s" % {
        'cpu_model': system_info['cpu_model'],
        'hostname': system_info['hostname'],
        'os_name': system_info['os_name'],
        'os_type': system_info['os_type'],
        'os_version': system_info['os_version'],
        'pyver': system_info['python_version'].split(' ')[0],
    }
    comment_lines = [
        "Test report by @%s" % user,
        ('**FAILED**', '**SUCCESS**')[success],
        msg,
        short_system_info,
        "See %s for a full test report." % gist_url,
    ]
    comment = '\n'.join(comment_lines)
    post_comment_in_issue(pr_nr, comment, github_user=user)

    msg = "Test report uploaded to %s and mentioned in a comment in easyconfigs PR#%s" % (gist_url, pr_nr)
    return msg
Exemple #3
0
def post_easyconfigs_pr_test_report(pr_nr, test_report, msg, init_session_state, success):
    """Post test report in a gist, and submit comment in easyconfigs PR."""
    user = build_option("github_user")

    # create gist with test report
    descr = "EasyBuild test report for easyconfigs PR #%s" % pr_nr
    fn = "easybuild_test_report_easyconfigs_pr%s_%s.md" % (pr_nr, strftime("%Y%M%d-UTC-%H-%M-%S", gmtime()))
    gist_url = upload_test_report_as_gist(test_report, descr=descr, fn=fn)

    # post comment to report test result
    system_info = init_session_state["system_info"]
    short_system_info = "%(os_type)s %(os_name)s %(os_version)s, %(cpu_model)s, Python %(pyver)s" % {
        "cpu_model": system_info["cpu_model"],
        "os_name": system_info["os_name"],
        "os_type": system_info["os_type"],
        "os_version": system_info["os_version"],
        "pyver": system_info["python_version"].split(" ")[0],
    }
    comment_lines = [
        "Test report by @%s" % user,
        ("**FAILED**", "**SUCCESS**")[success],
        msg,
        short_system_info,
        "See %s for a full test report." % gist_url,
    ]
    comment = "\n".join(comment_lines)
    post_comment_in_issue(pr_nr, comment, github_user=user)

    msg = "Test report uploaded to %s and mentioned in a comment in easyconfigs PR#%s" % (gist_url, pr_nr)
    return msg
Exemple #4
0
def comment(github, github_user, repository, pr_data, msg):
    """Post a comment in the pull request."""
    # decode message first, if needed
    known_msgs = {
        'jok': "Jenkins: ok to test",
        'jt': "Jenkins: test this please",
    }
    if msg.startswith(':'):
        if msg[1:] in known_msgs:
            msg = known_msgs[msg[1:]]
        elif msg.startswith(':r'):
            github_login = msg[2:]
            try:
                github.users[github_login].get()
                msg = "@%s: please review?" % github_login
            except:
                error("No such user on GitHub: %s" % github_login)
        else:
            error("Unknown coded comment message: %s" % msg)

    target = '%s/%s' % (pr_data['base']['repo']['owner']['login'], pr_data['base']['repo']['name'])
    info("Posting comment as user '%s' in %s PR #%s: \"%s\"" % (github_user, target, pr_data['number'], msg))
    if not DRY_RUN:
        post_comment_in_issue(pr_data['number'], msg, repo=repository, github_user=github_user)
    print "Done!"
Exemple #5
0
def comment(github,
            github_user,
            repository,
            pr_data,
            msg,
            check_msg=None,
            verbose=True):
    """Post a comment in the pull request."""
    # decode message first, if needed
    known_msgs = {
        'jok': "Jenkins: ok to test",
        'jt': "Jenkins: test this please",
    }
    if msg.startswith(':'):
        if msg[1:] in known_msgs:
            msg = known_msgs[msg[1:]]
        elif msg.startswith(':r'):
            github_login = msg[2:]
            try:
                github.users[github_login].get()
                msg = "@%s: please review?" % github_login
            except Exception:
                error("No such user on GitHub: %s" % github_login)
        else:
            error("Unknown coded comment message: %s" % msg)

    # only actually post comment if it wasn't posted before
    if check_msg:
        msg_regex = re.compile(re.escape(check_msg), re.M)
        for comment in pr_data['issue_comments']:
            if msg_regex.search(comment['body']):
                msg = "Message already found (using pattern '%s'), " % check_msg
                msg += "not posting comment again to PR %s!" % pr_data['number']
                print(msg)
                return
        print(
            "Message not found yet (using pattern '%s'), stand back for posting!"
            % check_msg)

    target = '%s/%s' % (pr_data['base']['repo']['owner']['login'],
                        pr_data['base']['repo']['name'])
    if verbose:
        info("Posting comment as user '%s' in %s PR #%s: \"%s\"" %
             (github_user, target, pr_data['number'], msg))
    else:
        info("Posting comment as user '%s' in %s PR #%s" %
             (github_user, target, pr_data['number']))
    if not DRY_RUN:
        post_comment_in_issue(pr_data['number'],
                              msg,
                              repo=repository,
                              github_user=github_user)
    print("Done!")
Exemple #6
0
def post_easyconfigs_pr_test_report(pr_nr, test_report, msg,
                                    init_session_state, success):
    """Post test report in a gist, and submit comment in easyconfigs PR."""

    github_user = build_option('github_user')
    pr_target_account = build_option('pr_target_account')
    pr_target_repo = build_option('pr_target_repo') or GITHUB_EASYCONFIGS_REPO

    # create gist with test report
    descr = "EasyBuild test report for %s/%s PR #%s" % (pr_target_account,
                                                        pr_target_repo, pr_nr)
    timestamp = strftime("%Y%M%d-UTC-%H-%M-%S", gmtime())
    fn = 'easybuild_test_report_%s_%s_pr%s_%s.md' % (pr_nr, pr_target_account,
                                                     pr_target_repo, timestamp)
    gist_url = upload_test_report_as_gist(test_report, descr=descr, fn=fn)

    # post comment to report test result
    system_info = init_session_state['system_info']

    # also mention CPU architecture name, but only if it's known
    if system_info['cpu_arch_name'] != UNKNOWN:
        system_info['cpu_model'] += " (%s)" % system_info['cpu_arch_name']

    short_system_info = "%(hostname)s - %(os_type)s %(os_name)s %(os_version)s, %(cpu_model)s, Python %(pyver)s" % {
        'cpu_model': system_info['cpu_model'],
        'hostname': system_info['hostname'],
        'os_name': system_info['os_name'],
        'os_type': system_info['os_type'],
        'os_version': system_info['os_version'],
        'pyver': system_info['python_version'].split(' ')[0],
    }

    comment_lines = [
        "Test report by @%s" % github_user,
        ('**FAILED**', '**SUCCESS**')[success],
        msg,
        short_system_info,
        "See %s for a full test report." % gist_url,
    ]
    comment = '\n'.join(comment_lines)

    post_comment_in_issue(pr_nr,
                          comment,
                          account=pr_target_account,
                          repo=pr_target_repo,
                          github_user=github_user)

    msg = "Test report uploaded to %s and mentioned in a comment in easyconfigs PR#%s" % (
        gist_url, pr_nr)
    return msg
Exemple #7
0
def post_pr_test_report(pr_nrs, repo_type, test_report, msg,
                        init_session_state, success):
    """Post test report in a gist, and submit comment in easyconfigs or easyblocks PR."""

    # make sure pr_nrs is a list of strings
    if isinstance(pr_nrs, str):
        pr_nrs = [pr_nrs]
    elif isinstance(pr_nrs, int):
        pr_nrs = [str(pr_nrs)]
    else:
        try:
            pr_nrs = [str(x) for x in pr_nrs]
        except ValueError:
            raise EasyBuildError("Can't convert %s to a list of PR #s." %
                                 pr_nrs)

    github_user = build_option('github_user')
    pr_target_account = build_option('pr_target_account')
    pr_target_repo = build_option('pr_target_repo') or repo_type

    # create gist with test report
    descr = "EasyBuild test report for %s/%s PR(s) #%s" % (
        pr_target_account, pr_target_repo, ', #'.join(pr_nrs))
    timestamp = strftime("%Y%M%d-UTC-%H-%M-%S", gmtime())
    fn = 'easybuild_test_report_%s_%s_pr%s_%s.md' % (
        '_'.join(pr_nrs), pr_target_account, pr_target_repo, timestamp)
    gist_url = upload_test_report_as_gist(test_report['full'],
                                          descr=descr,
                                          fn=fn)

    # post comment to report test result
    system_info = init_session_state['system_info'].copy()

    # also mention CPU architecture name, but only if it's known
    if system_info['cpu_arch_name'] != UNKNOWN:
        system_info['cpu_model'] += " (%s)" % system_info['cpu_arch_name']

    # add GPU info, if known
    gpu_info = get_gpu_info()
    gpu_str = ""
    if gpu_info:
        for vendor in gpu_info:
            for gpu, num in gpu_info[vendor].items():
                gpu_str += ", %s x %s %s" % (num, vendor, gpu)

    os_info = '%(hostname)s - %(os_type)s %(os_name)s %(os_version)s' % system_info
    short_system_info = "%(os_info)s, %(cpu_arch)s, %(cpu_model)s%(gpu)s, Python %(pyver)s" % {
        'os_info': os_info,
        'cpu_arch': system_info['cpu_arch'],
        'cpu_model': system_info['cpu_model'],
        'gpu': gpu_str,
        'pyver': system_info['python_version'].split(' ')[0],
    }

    comment_lines = ["Test report by @%s" % github_user]

    if build_option('include_easyblocks_from_pr'):
        if repo_type == GITHUB_EASYCONFIGS_REPO:
            easyblocks_pr_nrs = [
                int(x) for x in build_option('include_easyblocks_from_pr')
            ]
            comment_lines.append("Using easyblocks from PR(s) %s" % ", ".join([
                "https://github.com/%s/%s/pull/%s" %
                (pr_target_account, GITHUB_EASYBLOCKS_REPO, easyblocks_pr_nr)
                for easyblocks_pr_nr in easyblocks_pr_nrs
            ]))
        elif repo_type == GITHUB_EASYBLOCKS_REPO:
            comment_lines.append(test_report['overview'])
        else:
            raise EasyBuildError(
                "Don't know how to submit test reports to repo %s.", repo_type)

    if repo_type == GITHUB_EASYCONFIGS_REPO:
        comment_lines.append(('**FAILED**', '**SUCCESS**')[success])

    comment_lines.extend([
        msg,
        short_system_info,
        "See %s for a full test report." % gist_url,
    ])
    comment = '\n'.join(comment_lines)

    for pr_nr in pr_nrs:
        post_comment_in_issue(pr_nr,
                              comment,
                              account=pr_target_account,
                              repo=pr_target_repo,
                              github_user=github_user)

    msg = "Test report uploaded to %s and mentioned in a comment in %s PR(s) #%s" % (
        gist_url, pr_target_repo, ', #'.join(pr_nrs))
    return msg
Exemple #8
0
def post_pr_test_report(pr_nr, repo_type, test_report, msg, init_session_state,
                        success):
    """Post test report in a gist, and submit comment in easyconfigs or easyblocks PR."""

    github_user = build_option('github_user')
    pr_target_account = build_option('pr_target_account')
    pr_target_repo = build_option('pr_target_repo') or repo_type

    # create gist with test report
    descr = "EasyBuild test report for %s/%s PR #%s" % (pr_target_account,
                                                        pr_target_repo, pr_nr)
    timestamp = strftime("%Y%M%d-UTC-%H-%M-%S", gmtime())
    fn = 'easybuild_test_report_%s_%s_pr%s_%s.md' % (pr_nr, pr_target_account,
                                                     pr_target_repo, timestamp)
    gist_url = upload_test_report_as_gist(test_report['full'],
                                          descr=descr,
                                          fn=fn)

    # post comment to report test result
    system_info = init_session_state['system_info']

    # also mention CPU architecture name, but only if it's known
    if system_info['cpu_arch_name'] != UNKNOWN:
        system_info['cpu_model'] += " (%s)" % system_info['cpu_arch_name']

    os_info = '%(hostname)s - %(os_type)s %(os_name)s %(os_version)s' % system_info
    short_system_info = "%(os_info)s, %(cpu_arch)s, %(cpu_model)s, Python %(pyver)s" % {
        'os_info': os_info,
        'cpu_arch': system_info['cpu_arch'],
        'cpu_model': system_info['cpu_model'],
        'pyver': system_info['python_version'].split(' ')[0],
    }

    comment_lines = ["Test report by @%s" % github_user]

    if build_option('include_easyblocks_from_pr'):
        if repo_type == GITHUB_EASYCONFIGS_REPO:
            easyblocks_pr_nrs = map(int,
                                    build_option('include_easyblocks_from_pr'))
            comment_lines.append("Using easyblocks from PR(s) %s" % ", ".join([
                "https://github.com/%s/%s/pull/%s" %
                (pr_target_account, GITHUB_EASYBLOCKS_REPO, easyblocks_pr_nr)
                for easyblocks_pr_nr in easyblocks_pr_nrs
            ]))
        elif repo_type == GITHUB_EASYBLOCKS_REPO:
            comment_lines.append(test_report['overview'])
        else:
            raise EasyBuildError(
                "Don't know how to submit test reports to repo %s.", repo_type)

    if repo_type == GITHUB_EASYCONFIGS_REPO:
        comment_lines.append(('**FAILED**', '**SUCCESS**')[success])

    comment_lines.extend([
        msg,
        short_system_info,
        "See %s for a full test report." % gist_url,
    ])
    comment = '\n'.join(comment_lines)

    post_comment_in_issue(pr_nr,
                          comment,
                          account=pr_target_account,
                          repo=pr_target_repo,
                          github_user=github_user)

    msg = "Test report uploaded to %s and mentioned in a comment in %s PR#%s" % (
        gist_url, pr_target_repo, pr_nr)
    return msg