Example #1
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

    ci_states = iw.pullrequest_status_by_context(ShippableCI.state_context)
    if not ci_states:
        return rbmerge_meta

    last_run = ShippableCI.get_processed_run(ci_states[0])

    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
Example #2
0
def get_ci_facts(iw):
    cifacts = {u'ci_run_number': None}

    if not iw.is_pullrequest():
        return cifacts

    ci_states = iw.pullrequest_status_by_context(ShippableCI.state_context)

    if not ci_states:
        return cifacts

    last_run = ShippableCI.get_processed_run(ci_states[0])

    return {'ci_run_number': last_run[u'run_id']}
Example #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

    ci_states = iw.pullrequest_status_by_context(ShippableCI.state_context)
    if not ci_states:
        return rbmerge_meta

    last_run = ShippableCI.get_processed_run(ci_states[0])

    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