A dashboard for monitoring code debt in a git repository.
pip install git-code-debt
# Create tables
$ git-code-debt-create-tables database.db
# Generate code metric data (substitute your own repo path)
$ git-code-debt-generate git://github.com/Yelp/git-code-debt database.db
# Start the server
$ git-code-debt-server database.db
Adding data to the database is as simple as running generate again.
git-code-debt
will pick up in the git history from where data was generated
previously.
# (substitute your own repo path)
$ git-code-debt-generate git://github.com/Yelp/git-code-debt database.db
- Create a python project which adds
git-code-debt
as a dependency. - Create a package where you'll write your metrics
- Pass your package(s) as positional argument(s) to
git-code-debt-create-tables
as well asgit-code-debt-generate
.
The simplest way to write your own custom metrics is to extend
git_code_debt.metrics.base.SimpleLineCounterBase
Here's what the base class looks like
class SimpleLineCounterBase(DiffParserBase:
# ...
def should_include_file(self, file_diff_stat):
"""Implement me to return whether a filename should be included.
By default, this returns True.
:param FileDiffStat file_diff_stat:
"""
return True
def line_matches_metric(self, line, file_diff_stat):
"""Implement me to return whether a line matches the metric.
:param bytes line: Line in the file
:param FileDiffStat file_diff_stat:
"""
raise NotImplementedError
Here's an example metric
from git_code_debt.metrics.base import SimpleLineCounterBase
class Python__init__LineCount(SimpleLineCounterBase):
def should_include_file(self, file_diff_stat):
return file_diff_stat.filename == b'__init__.py'
def line_matches_metric(self, line, file_diff_stat):
# All lines in __init__.py match
return True
More complex metrics can extend DiffParserBase
class DiffParserBase(object):
"""Generates metrics from git show"""
# Specify __metric__ = False to not be included (useful for base classes)
__metric__ = False
def get_metrics_from_stat(self, file_diff_stats):
"""Implement me to yield Metric objects from the input list of
FileStat objects.
Args:
file_diff_stats - list of FileDiffStat objects
Returns:
generator of Metric objects
"""
raise NotImplementedError
def get_possible_metric_ids(self):
raise NotImplementedError