用于监视git存储库中的代码债务的仪表板。
git-code-debt的Python项目详细描述
Git代码债务
用于监视git存储库中的代码债务的仪表板。
安装
pip install git-code-debt
用法
基本/tl;dr用法
制作generate_config.yaml
# required: repository to clone (can be anything `git clone` understands) even# a repository already on diskrepo:git@github.com:asottile/git-code-debt# required: database generation pathdatabase:database.db# optional: default Falseskip_default_metrics:false# optional: default []metric_package_names:[]# optional: default ^$ (python regex) to exclude paths such as '^vendor/'exclude:^$
调用cli
# Generate code metric data (substitute your own repo path)
$ git-code-debt-generate
# Start the server
$ git-code-debt-server database.db
< H3>更新现有数据库中的数据< EH3>
# Generate code metric data (substitute your own repo path)
$ git-code-debt-generate
# Start the server
$ git-code-debt-server database.db
向数据库添加数据就像再次运行generate一样简单。
git-code-debt
将从生成数据的git历史记录中提取
以前。
$ git-code-debt-generate
创建自己的指标
- 创建一个python项目,添加
git-code-debt
作为依赖项。 - 创建一个包,您可以在其中编写度量值
- 将包添加到
metric_package_names
中的generate_config.yaml
编写自定义度量的最简单方法是扩展
git_code_debt.metrics.base.SimpleLineCounterBase
下面是基类的外观
classSimpleLineCounterBase(DiffParserBase):# ...defshould_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: """returnTruedefline_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: """raiseNotImplementedError
下面是一个度量示例
fromgit_code_debt.metrics.baseimportSimpleLineCounterBaseclassPython__init__LineCount(SimpleLineCounterBase):"""Counts the number of lines in __init__.py"""defshould_include_file(self,file_diff_stat):returnfile_diff_stat.filename==b'__init__.py'defline_matches_metric(self,line,file_diff_stat):# All lines in __init__.py matchreturnTrue
更复杂的度量可以扩展DiffParserBase
classDiffParserBase(object):# Specify __metric__ = False to not be included (useful for base classes)__metric__=Falsedefget_metrics_from_stat(self,commit,file_diff_stats):"""Implement me to yield Metric objects from the input list of FileStat objects. Args: commit - Commit object file_diff_stats - list of FileDiffStat objects Returns: generator of Metric objects """raiseNotImplementedErrordefget_metrics_info(self):"""Implement me to yield `MetricInfo` objects."""raiseNotImplementedError