Exemplo n.º 1
0
def get_shippable_run_facts(iw, meta, shippable=None):
    '''Does an issue need the test result comment?'''

    # https://github.com/ansible/ansibullbot/issues/312
    # https://github.com/ansible/ansibullbot/issues/404
    # https://github.com/ansible/ansibullbot/issues/418

    rmeta = {
        u'shippable_test_results': None,
        u'ci_verified': None,
        u'needs_testresult_notification': None
    }

    # should only be here if the run state is failed ...
    if not meta[u'has_shippable']:
        return rmeta
    if meta[u'ci_state'] != u'failure':
        return rmeta

    if not shippable:
        spath = os.path.expanduser(u'~/.ansibullbot/cache/shippable.runs')
        shippable = ShippableRuns(cachedir=spath, writecache=True)

    ci_status = iw.pullrequest_status
    ci_verified = None
    shippable_test_results = None
    needs_testresult_notification = False

    # find the last chronological run id
    #   https://app.shippable.com/github/ansible/ansible/runs/21001/summary
    #   https://app.shippable.com/github/ansible/ansible/runs/21001
    last_run = [x[u'target_url'] for x in ci_status if x.get(u'context', u'') == u'Shippable'][0]
    last_run = last_run.split(u'/')
    if last_run[-1] == u'summary':
        last_run = last_run[-2]
    else:
        last_run = last_run[-1]

    # filter by the last run id
    (run_data, commitSha, shippable_test_results, ci_verified) = \
        shippable.get_test_results(
            last_run,
            usecache=True,
            filter_paths=[u'/testresults/ansible-test-.*.json'],
    )

    # do validation so that we're not stepping on toes
    if u'ci_verified' in iw.labels and not ci_verified:

        sh = ShippableHistory(iw, shippable, ci_status)
        vinfo = sh.info_for_last_ci_verified_run()

        if vinfo:
            if last_run == vinfo[u'run_id']:
                ci_verified = True
            else:
                if C.DEFAULT_BREAKPOINTS:
                    logging.error(u'breakpoint!')
                    import epdb; epdb.st()

    # no results means no notification required
    if len(shippable_test_results) < 1:
        needs_testresult_notification = False
    else:

        s_bpcs = iw.history.get_boilerplate_comments_content(
            bfilter='shippable_test_result'
        )

        if s_bpcs:
            # was this specific result shown?
            job_ids = [x[u'job_id'] for x in shippable_test_results]
            job_ids = sorted(set(job_ids))
            found = []
            for bp in s_bpcs:
                for job_id in [x for x in job_ids if x not in found]:
                    if job_id in bp and job_id not in found:
                        found.append(job_id)
            if len(found) == len(job_ids):
                needs_testresult_notification = False
            else:
                needs_testresult_notification = True
        else:
            needs_testresult_notification = True

    # https://github.com/ansible/ansibullbot/issues/421
    if rmeta[u'needs_testresult_notification']:
        hcd = has_commentable_data(shippable_test_results)
        rmeta[u'needs_testresult_notification'] = hcd

    rmeta = {
        u'shippable_test_results': shippable_test_results,
        u'ci_verified': ci_verified,
        u'needs_testresult_notification': needs_testresult_notification
    }

    return rmeta
Exemplo n.º 2
0
def get_shippable_run_facts(iw, meta, shippable=None):
    '''Does an issue need the test result comment?'''

    # https://github.com/ansible/ansibullbot/issues/312
    # https://github.com/ansible/ansibullbot/issues/404
    # https://github.com/ansible/ansibullbot/issues/418

    rmeta = {
        'shippable_test_results': None,
        'ci_verified': None,
        'needs_testresult_notification': None
    }

    # should only be here if the run state is failed ...
    if not meta['has_shippable']:
        return rmeta
    if meta['ci_state'] != 'failure':
        return rmeta

    if not shippable:
        spath = os.path.expanduser('~/.ansibullbot/cache/shippable.runs')
        shippable = ShippableRuns(cachedir=spath, writecache=True)

    ci_status = iw.pullrequest_status
    ci_verified = None
    shippable_test_results = None
    needs_testresult_notification = False

    # find the last chronological run id
    #   https://app.shippable.com/github/ansible/ansible/runs/21001/summary
    #   https://app.shippable.com/github/ansible/ansible/runs/21001
    last_run = [x['target_url'] for x in ci_status][0]
    last_run = last_run.split('/')
    if last_run[-1] == 'summary':
        last_run = last_run[-2]
    else:
        last_run = last_run[-1]

    # filter by the last run id
    (run_data, commitSha, shippable_test_results, ci_verified) = \
        shippable.get_test_results(
            last_run,
            usecache=True,
            filter_paths=['/testresults/ansible-test-.*.json'],
    )

    # do validation so that we're not stepping on toes
    if 'ci_verified' in iw.labels and not ci_verified:

        sh = ShippableHistory(iw, shippable, ci_status)
        vinfo = sh.info_for_last_ci_verified_run()

        if vinfo:
            if last_run == vinfo['run_id']:
                ci_verified = True
            else:
                #logging.error('breakpoint!')
                #import epdb; epdb.st()
                pass

    # no results means no notification required
    if len(shippable_test_results) < 1:
        needs_testresult_notification = False
    else:

        s_bpcs = iw.history.get_boilerplate_comments_content(
            bfilter='shippable_test_result')

        if s_bpcs:
            # was this specific result shown?
            job_ids = [x['job_id'] for x in shippable_test_results]
            job_ids = sorted(set(job_ids))
            found = []
            for bp in s_bpcs:
                for job_id in [x for x in job_ids if x not in found]:
                    if job_id in bp and job_id not in found:
                        found.append(job_id)
            if len(found) == len(job_ids):
                needs_testresult_notification = False
            else:
                needs_testresult_notification = True
        else:
            needs_testresult_notification = True

    # https://github.com/ansible/ansibullbot/issues/421
    if rmeta['needs_testresult_notification']:
        hcd = has_commentable_data(shippable_test_results)
        rmeta['needs_testresult_notification'] = hcd

    rmeta = {
        'shippable_test_results': shippable_test_results,
        'ci_verified': ci_verified,
        'needs_testresult_notification': needs_testresult_notification
    }

    return rmeta
Exemplo n.º 3
0
def get_shippable_run_facts(iw, meta, shippable):
    '''Does an issue need the test result comment?'''
    # https://github.com/ansible/ansibullbot/issues/312
    # https://github.com/ansible/ansibullbot/issues/404
    # https://github.com/ansible/ansibullbot/issues/418
    rmeta = {
        u'shippable_test_results': None,
        u'ci_verified': None,
        u'needs_testresult_notification': None
    }

    # should only be here if the run state is failed ...
    if not meta[u'has_shippable']:
        return rmeta
    if meta[u'ci_state'] != u'failure':
        return rmeta

    ci_status = iw.pullrequest_status
    ci_verified = None
    shippable_test_results = None
    needs_testresult_notification = False

    # find the last chronological run id
    #   https://app.shippable.com/github/ansible/ansible/runs/21001/summary
    #   https://app.shippable.com/github/ansible/ansible/runs/21001
    last_run = [
        x[u'target_url'] for x in ci_status
        if x.get(u'context', u'') == u'Shippable'
    ][0]
    last_run = last_run.split(u'/')
    if last_run[-1] == u'summary':
        last_run = last_run[-2]
    else:
        last_run = last_run[-1]

    # filter by the last run id
    # FIXME this needs to be split into two methods
    shippable_test_results, ci_verified = \
        shippable.get_test_results(
            last_run,
            usecache=True,
            filter_paths=[u'/testresults/ansible-test-.*.json'],
    )

    # do validation so that we're not stepping on toes
    if u'ci_verified' in iw.labels and not ci_verified:
        sh = ShippableHistory(iw, shippable, ci_status)
        vinfo = sh.info_for_last_ci_verified_run()
        if vinfo:
            if last_run == vinfo[u'run_id']:
                ci_verified = True

    # no results means no notification required
    if len(shippable_test_results) < 1:
        needs_testresult_notification = False
    else:
        s_bpcs = iw.history.get_boilerplate_comments_content(
            bfilter='shippable_test_result')

        if s_bpcs:
            # was this specific result shown?
            job_ids = [x[u'job_id'] for x in shippable_test_results]
            job_ids = sorted(set(job_ids))
            found = []
            for bp in s_bpcs:
                for job_id in [x for x in job_ids if x not in found]:
                    if job_id in bp and job_id not in found:
                        found.append(job_id)
            if len(found) == len(job_ids):
                needs_testresult_notification = False
            else:
                needs_testresult_notification = True
        else:
            needs_testresult_notification = True

    # https://github.com/ansible/ansibullbot/issues/421
    if rmeta[u'needs_testresult_notification']:
        hcd = has_commentable_data(shippable_test_results)
        # FIXME needs_testresult_notification = hcd ???
        rmeta[u'needs_testresult_notification'] = hcd

    rmeta = {
        u'shippable_test_results': shippable_test_results,
        u'ci_verified': ci_verified,
        u'needs_testresult_notification': needs_testresult_notification
    }

    return rmeta