示例#1
0
def get_ci_facts(iw):
    cifacts = {u'ci_run_number': None}

    if not iw.is_pullrequest():
        return cifacts

    last_run = ShippableRuns.get_processed_last_run(iw.pullrequest_status)

    return {'ci_run_number': last_run[u'run_id']}
示例#2
0
def get_rebuild_command_facts(iw, meta):
    rbmerge_meta = {
        u'needs_rebuild': meta.get(u'needs_rebuild', False),
        u'needs_rebuild_all': meta.get(u'needs_rebuild_all', False),
        u'needs_rebuild_failed': meta.get(u'needs_rebuild_failed', False),
    }

    if not iw.is_pullrequest():
        return rbmerge_meta

    if rbmerge_meta[u'needs_rebuild'] and (
            rbmerge_meta[u'needs_rebuild_all']
            or rbmerge_meta[u'needs_rebuild_failed']):
        return rbmerge_meta

    last_rebuild_failed_command = _get_last_command(iw, u'/rebuild_failed',
                                                    None)
    last_rebuild_command = _get_last_command(iw, u'/rebuild', None)

    if last_rebuild_command is None and last_rebuild_failed_command is None:
        return rbmerge_meta
    elif last_rebuild_command is None and last_rebuild_failed_command is not None:
        last_command = last_rebuild_failed_command
        meta_key = u'needs_rebuild_failed'
    elif last_rebuild_command is not None and last_rebuild_failed_command is None:
        last_command = last_rebuild_command
        meta_key = u'needs_rebuild_all'
    else:
        if last_rebuild_command >= last_rebuild_failed_command:
            last_command = last_rebuild_command
            meta_key = u'needs_rebuild_all'
        else:
            last_command = last_rebuild_failed_command
            meta_key = u'needs_rebuild_failed'

    # new commits should reset everything
    lc = iw.history.last_commit_date
    if lc and lc > last_command:
        return rbmerge_meta

    last_run = ShippableRuns.get_processed_last_run(iw.pullrequest_status)

    if last_run[u'state'] != u'pending' and last_run[
            u'created_at'] < last_command:
        rbmerge_meta[u'needs_rebuild'] = True
        rbmerge_meta[meta_key] = True

    return rbmerge_meta
示例#3
0
def get_rebuild_merge_facts(iw, meta, core_team):
    rbmerge_meta = {
        u'needs_rebuild': meta.get(u'needs_rebuild', False),
        u'needs_rebuild_all': meta.get(u'needs_rebuild_all', False),
        u'admin_merge': False
    }

    if not iw.is_pullrequest():
        return rbmerge_meta

    if rbmerge_meta[u'needs_rebuild'] and rbmerge_meta[u'needs_rebuild_all']:
        return rbmerge_meta

    if meta[u'is_needs_revision']:
        return rbmerge_meta

    if meta[u'is_needs_rebase']:
        return rbmerge_meta

    last_command = _get_last_command(iw, u'rebuild_merge', core_team)

    if last_command is None:
        return rbmerge_meta

    # new commits should reset everything
    lc = iw.history.last_commit_date
    if lc and lc > last_command:
        return rbmerge_meta

    last_run = ShippableRuns.get_processed_last_run(iw.pullrequest_status)

    if last_run[u'state'] != u'pending' and last_run[
            u'created_at'] < last_command:
        rbmerge_meta[u'needs_rebuild'] = True
        rbmerge_meta[u'needs_rebuild_all'] = True

    if last_run[
            u'state'] == u'success' and last_run[u'created_at'] > last_command:
        rbmerge_meta[u'admin_merge'] = True

    return rbmerge_meta
示例#4
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
示例#5
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