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
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']}
def test3(): """command given, new commit created, do not rebuild or merge""" datafile = 'tests/fixtures/rebuild_merge/3_issue.yml' statusfile = 'tests/fixtures/rebuild_merge/3_prstatus.json' with get_issue(datafile, statusfile) as iw: meta = { 'is_pullrequest': True, 'is_needs_revision': False, 'is_needs_rebase': False, 'needs_rebuild': False, 'ci_run_number': 0 } rbfacts = get_rebuild_merge_facts(iw, meta, ['superman'], ShippableCI('', iw)) assert not rbfacts['needs_rebuild'] assert not rbfacts['needs_rebuild_all'] assert not rbfacts['admin_merge']
def test0(): """command issued, test ran, time to merge""" datafile = 'tests/fixtures/rebuild_merge/0_issue.yml' statusfile = 'tests/fixtures/rebuild_merge/0_prstatus.json' with get_issue(datafile, statusfile) as iw: meta = { 'is_pullrequest': True, 'is_needs_revision': False, 'is_needs_rebase': False, 'needs_rebuild': False, 'ci_run_number': 0, } rbfacts = get_rebuild_merge_facts(iw, meta, ['superman'], ShippableCI('', iw)) assert not rbfacts['needs_rebuild'] assert not rbfacts['needs_rebuild_all'] assert rbfacts['admin_merge']
def test1(): """new test is in progress, do not rebuild and do not merge""" datafile = 'tests/fixtures/rebuild_merge/1_issue.yml' statusfile = 'tests/fixtures/rebuild_merge/1_prstatus.json' with get_issue(datafile, statusfile) as iw: meta = { 'is_pullrequest': True, 'is_needs_revision': False, 'is_needs_rebase': False, 'needs_rebuild': False, 'ci_run_number': 0 } rbfacts = get_rebuild_merge_facts(iw, meta, ['superman'], ShippableCI('', iw)) assert not rbfacts['needs_rebuild'] assert not rbfacts['needs_rebuild_all'] assert not rbfacts['admin_merge']
def test_rebuild_failed_and_rebuild_commands(): """Test ran and failed. /rebuild_failed and /rebuild commands issued, in that order.""" datafile = u'tests/fixtures/rebuild/3_issue.yml' statusfile = u'tests/fixtures/rebuild/3_prstatus.json' with get_issue(datafile, statusfile) as iw: meta = { u'is_pullrequest': True, u'is_needs_revision': False, u'is_needs_rebase': False, u'needs_rebuild': False, u'ci_run_number': 0, } rbfacts = get_rebuild_command_facts(iw, meta, ShippableCI('', iw)) assert rbfacts[u'needs_rebuild'] assert rbfacts[u'needs_rebuild_all'] assert not rbfacts[u'needs_rebuild_failed']
def test_rebuild_failed_command(): """Test ran and failed. /rebuild_failed command issued.""" datafile = 'tests/fixtures/rebuild/1_issue.yml' statusfile = 'tests/fixtures/rebuild/1_prstatus.json' with get_issue(datafile, statusfile) as iw: meta = { 'is_pullrequest': True, 'is_needs_revision': False, 'is_needs_rebase': False, 'needs_rebuild': False, 'ci_run_number': 0, } rbfacts = get_rebuild_command_facts(iw, meta, ShippableCI('', iw)) assert rbfacts['needs_rebuild'] assert rbfacts['needs_rebuild_failed'] assert not rbfacts['needs_rebuild_all']
def test2(): """command given, time to rebuild but not merge""" datafile = u'tests/fixtures/rebuild_merge/2_issue.yml' statusfile = u'tests/fixtures/rebuild_merge/2_prstatus.json' with get_issue(datafile, statusfile) as iw: meta = { u'is_pullrequest': True, u'is_needs_revision': False, u'is_needs_rebase': False, u'needs_rebuild': False, u'ci_run_number': 0 } rbfacts = get_rebuild_merge_facts(iw, meta, [u'superman'], ShippableCI('', iw)) assert rbfacts[u'needs_rebuild'] assert rbfacts[u'needs_rebuild_all'] assert not rbfacts[u'admin_merge']
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