Skip to main content

A dashboard for monitoring code debt in a git repository.

Project description

Build Status Coverage Status

git-code-debt

A dashboard for monitoring code debt in a git repository.

Installation

pip install git-code-debt

Usage

Basic / tl;dr Usage

make a 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: ^$

invoke the cli

# Generate code metric data (substitute your own repo path)
$ git-code-debt-generate
# Start the server
$ git-code-debt-server database.db

Updating data on an existing database

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.

$ git-code-debt-generate

Creating your own metrics

  1. Create a python project which adds git-code-debt as a dependency.
  2. Create a package where you'll write your metrics
  3. Add your package to metric_package_names in your generate_config.yaml

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):
    """Counts the number of lines in __init__.py"""

    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):
    # Specify __metric__ = False to not be included (useful for base classes)
    __metric__ = False

    def get_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
        """
        raise NotImplementedError

    def get_metrics_info(self):
        """Implement me to yield `MetricInfo` objects."""
        raise NotImplementedError

Some screenshots

Index

Example screen index

Graph

Example screen graph

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

git_code_debt-0.11.0.tar.gz (51.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

git_code_debt-0.11.0-py2.py3-none-any.whl (68.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file git_code_debt-0.11.0.tar.gz.

File metadata

  • Download URL: git_code_debt-0.11.0.tar.gz
  • Upload date:
  • Size: 51.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for git_code_debt-0.11.0.tar.gz
Algorithm Hash digest
SHA256 a8585493b92f52b573f40cba0561ba1ca850f7d71a094d1d922d6a2c979c36ef
MD5 ef95ef3b035e97ed94baea72fd1c95be
BLAKE2b-256 9e1dc3ecf84a2b5ff58c1fb614f1e9995be7eb61b02ebbda24c5fdb5502b51cf

See more details on using hashes here.

File details

Details for the file git_code_debt-0.11.0-py2.py3-none-any.whl.

File metadata

  • Download URL: git_code_debt-0.11.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 68.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

File hashes

Hashes for git_code_debt-0.11.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 53031e25438aec5c78dfbb91430174ea5c43f9361d11784a246ec299a627e27e
MD5 a79c0102016dc7e8fbab4c6e37a827e5
BLAKE2b-256 56457a9d8dc3c2331ae501ca61c8744d4383675e707816484ca9a37527dc1eb1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page