def test_commit_delta_with_overrides(): overrides = {'OtherMetric'} ret = CommitDelta.from_data('OtherMetric', mock.sentinel.delta, overrides) assert ret == CommitDelta( 'OtherMetric', 'color-override', mock.sentinel.delta, )
def show(metric_name, start_timestamp, end_timestamp): start_timestamp = int(start_timestamp) end_timestamp = int(end_timestamp) metric_info = logic.get_metric_info(flask.g.db, metric_name) metric_changes = sorted( logic.get_major_changes_for_metric( flask.g.db, start_timestamp, end_timestamp, metric_info.id, )) metric_changes = [( datetime.datetime.fromtimestamp(timestamp).strftime( '%Y-%m-%d %H:%M:%S', ), sha, CommitDelta.from_data( metric_name, Delta('javascript:;', value), color_overrides=flask.g.config.color_overrides, ), ) for timestamp, sha, value in metric_changes] override_classname = ('color-override' if metric_name in flask.g.config.color_overrides else '') rendered_template = render_template( 'changes.mako', changes=metric_changes, override_classname=override_classname, ) return json.dumps({'body': rendered_template})
def data() -> str: metric_names = frozenset(flask.g.config.widget_metrics) diff = flask.request.form['diff'].encode('UTF-8') metric_config = GenerateOptions.from_yaml( yaml.load(open('generate_config.yaml').read()), ) parsers = get_metric_parsers_from_args( metric_config.metric_package_names, skip_defaults=False, ) metrics = get_metrics(BLANK_COMMIT, diff, parsers, metric_config.exclude) metrics = tuple( metric for metric in metrics if metric.value and metric.name in metric_names ) commit_deltas = sorted( CommitDelta.from_data( metric.name, Delta('javascript:;', metric.value), color_overrides=flask.g.config.color_overrides, ) for metric in metrics ) return json.dumps({ 'metrics': render_template('widget.mako', commit_deltas=commit_deltas), })
def data(): metric_names = frozenset(flask.g.config.widget_metrics) diff = flask.request.form['diff'].encode('UTF-8') metric_config = GenerateOptions.from_yaml( yaml.load(io.open('generate_config.yaml').read()), ) parsers = get_metric_parsers_from_args( metric_config.metric_package_names, skip_defaults=False, ) metrics = get_metrics(Commit.blank, diff, parsers, metric_config.exclude) metrics = [ metric for metric in metrics if metric.value and metric.name in metric_names ] commit_deltas = sorted([ CommitDelta.from_data( metric.name, Delta('javascript:;', metric.value), color_overrides=flask.g.config.color_overrides, ) for metric in metrics ]) return json.dumps({ 'metrics': render_template('widget.mako', commit_deltas=commit_deltas), })
def show(sha: str) -> str: changes = logic.get_metric_changes(flask.g.db, sha) commit_deltas = sorted( CommitDelta.from_data( metric_name, Delta('javascript:;', change), color_overrides=flask.g.config.color_overrides, ) for metric_name, change in changes) links = [(link_name, link.format(sha=sha)) for link_name, link in flask.g.config.commit_links] return render_template( 'commit.mako', sha=sha, short_sha=sha[:8], commit_deltas=commit_deltas, links=links, )
def show(sha): changes = logic.get_metric_changes(flask.g.db, sha) commit_deltas = sorted( CommitDelta.from_data( metric_name, Delta('javascript:;', change), color_overrides=flask.g.config.color_overrides, ) for metric_name, change in changes ) links = [ (link_name, link.format(sha=sha)) for link_name, link in flask.g.config.commit_links ] return render_template( 'commit.mako', sha=sha, short_sha=sha[:8], commit_deltas=commit_deltas, links=links, )
def show(metric_name, start_timestamp, end_timestamp): start_timestamp = int(start_timestamp) end_timestamp = int(end_timestamp) metric_info = logic.get_metric_info(flask.g.db, metric_name) metric_changes = sorted( logic.get_major_changes_for_metric( flask.g.db, start_timestamp, end_timestamp, metric_info.id, ), ) metric_changes = [ ( datetime.datetime.fromtimestamp(timestamp).strftime( '%Y-%m-%d %H:%M:%S', ), sha, CommitDelta.from_data( metric_name, Delta('javascript:;', value), color_overrides=flask.g.config.color_overrides, ), ) for timestamp, sha, value in metric_changes ] override_classname = ( 'color-override' if metric_name in flask.g.config.color_overrides else '' ) rendered_template = render_template( 'changes.mako', changes=metric_changes, override_classname=override_classname, ) return json.dumps({'body': rendered_template})
def test_commit_delta_not_overriden(): overrides = {'OtherMetric'} ret = CommitDelta.from_data('MyMetric', mock.sentinel.delta, overrides) assert ret == CommitDelta('MyMetric', '', mock.sentinel.delta)