跳转到主要内容

用于监控git仓库中代码债务的仪表板。

项目描述

Build Status Azure DevOps coverage pre-commit.ci status

git-code-debt

用于监控git仓库中代码债务的仪表板。

安装

pip安装git-code-debt

用法

基本/简单用法

创建一个generate_config.yaml

# required: repository to clone (can be anything `git clone` understands) even
# a repository already on disk
repo: git@github.com:asottile/git-code-debt

# required: database generation path
database: database.db

# optional: default False
skip_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

更新现有数据库中的数据

向数据库添加数据就像再次运行generate一样简单。 git-code-debt将从上次生成数据的地方获取git历史记录。

$ git-code-debt-generate

创建自己的指标

  1. 创建一个python项目,将git-code-debt作为依赖项。
  2. 创建一个包,你将在其中编写指标
  3. 将你的包添加到generate_config.yaml中的metric_package_names

编写自定义指标的最简单方法是扩展git_code_debt.metrics.base.SimpleLineCounterBase

以下是基类的外观

class SimpleLineCounterBase(DiffParserBase):
    # ...

    def should_include_file(self, file_diff_stat: FileDiffStat) -> bool:
        """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: bytes, file_diff_stat: FileDiffStat) -> bool:
        """Implement me to return whether a line matches the metric.

        :param bytes line: Line in the file
        :param FileDiffStat file_diff_stat:
        """
        raise NotImplementedError

以下是一个示例指标

from git_code_debt.metrics.base import SimpleLineCounterBase


class Python__init__LineCount(SimpleLineCounterBase):
    """Counts the number of lines in __init__.py"""

    def should_include_file(self, file_diff_stat: FileDiffStat) -> bool:
        return file_diff_stat.filename == b'__init__.py'

    def line_matches_metric(self, line: bytes, file_diff_stat -> FileDiffStat) -> bool:
        # All lines in __init__.py match
        return True

提供了一个额外的类,它将行作为文本提供(SimpleLineCounterBase将它们作为bytes提供):TextLineCounterBase。以下是一个使用该基类的示例指标

from git_code_debt.metrics.base import TextLineCounterBase


class XXXLineCount(TextLineCounterBase):
    """Counts the number of lines which are XXX comments"""

    def text_line_matches_metric(self, line: str, file_diff_stat: FileDiffStat) -> bool:
        return '# XXX' in line

更复杂的指标可以扩展DiffParserBase

class DiffParserBase(object):
    # Specify __metric__ = False to not be included (useful for base classes)
    __metric__ = False

    def get_metrics_from_stat(self, commit: Commit, file_diff_stats: Tuple[FileDiffStat, ...]) -> bool:
        """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
        """
        raise NotImplementedError

    def get_metrics_info(self) -> List[MetricInfo]:
        """Implement me to yield `MetricInfo` objects."""
        raise NotImplementedError

一些截图

索引

Example screen index

图表

Example screen graph

项目详情


下载文件

下载适合您平台的文件。如果您不确定该选择哪个,请了解有关安装包的更多信息。

源代码分发

git_code_debt-1.1.1.tar.gz (56.5 kB 查看哈希值)

上传时间 源代码

构建分发

git_code_debt-1.1.1-py2.py3-none-any.whl (69.6 kB 查看哈希值)

上传时间 Python 2 Python 3