• Stars
    star
    573
  • Rank 77,865 (Top 2 %)
  • Language
    Python
  • License
    MIT License
  • Created about 11 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A dashboard for monitoring code debt in a git repository.

build status pre-commit.ci 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: [email protected]: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: 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

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: 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

An additional class is provided which feeds lines as text (SimpleLineCounterBase presents them as bytes): TextLineCounterBase. Here is an example metric using that base class:

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

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: 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

Some screenshots

Index

Example screen index

Graph

Example screen graph

More Repositories

1

pyupgrade

A tool (and pre-commit hook) to automatically upgrade syntax for newer versions of the language.
Python
3,498
star
2

reorder-python-imports

Rewrites source to reorder python imports
Python
731
star
3

all-repos

Clone all your repositories and apply sweeping changes.
Python
534
star
4

babi

a text editor
Python
393
star
5

add-trailing-comma

A tool (and pre-commit hook) to automatically add trailing commas to calls and literals.
Python
338
star
6

dead

dead simple python dead code detection
Python
331
star
7

yesqa

Automatically remove unnecessary `# noqa` comments
Python
265
star
8

astpretty

Pretty print the output of python stdlib `ast.parse`.
Python
189
star
9

detect-test-pollution

a tool to detect test pollution
Python
173
star
10

setup-cfg-fmt

apply a consistent format to `setup.cfg` files
Python
152
star
11

setup-py-upgrade

upgrade a setup.py to declarative metadata
Python
148
star
12

scratch

Haphazard things.
Python
118
star
13

importtime-waterfall

Generate waterfalls from `-Ximporttime` tracing.
Python
108
star
14

setuptools-golang

A setuptools extension for building cpython extensions written in golang.
Python
98
star
15

dockerfile

Parse a dockerfile into a high-level representation using the official go parser
Go
97
star
16

gh-perf-review

hackety tool to view github PRs for a period
Python
81
star
17

re-assert

show where your regex match assertion failed!
Python
81
star
18

covdefaults

A coverage plugin to provide sensible default settings
Python
63
star
19

tokenize-rt

A wrapper around the stdlib `tokenize` which roundtrips.
Python
50
star
20

flake8-typing-imports

flake8 plugin which checks that typing imports are properly guarded
Python
48
star
21

cfgv

Validate configuration and produce human readable error messages
Python
44
star
22

recipes

One day IoT will catch up and then I can use CI
26
star
23

classify-imports

Utilities for refactoring imports in python-like syntax.
Python
23
star
24

nintendo-microcontrollers

control various nintendo consoles with arduino!
Python
22
star
25

awshelp

awshelp forwards arguments to `aws` unless `-h` or `--help` are present
Python
20
star
26

setuptools-golang-examples

Example extensions written for https://github.com/asottile/setuptools-golang
Go
19
star
27

watch-plz

Ensure all of your repositories are watched.
Python
17
star
28

workflows

reusable github workflows / actions
17
star
29

ukkonen

Implementation of bounded Levenshtein distance (Ukkonen)
C++
16
star
30

onigurumacffi

python cffi bindings for the oniguruma regex engine
Python
16
star
31

color-code

Encodes files as color
Python
16
star
32

wat

my brain is full of wat
Python
11
star
33

personal-puppet

serverless puppet to manage my machines
Puppet
11
star
34

shiny-pokemon-scraper

automatically detect tera raid events with guaranteed shiny pokemon
Python
10
star
35

set-delete-branch-on-merge

github does not provide a way to set the `delete_branch_on_merge` as a default
Python
9
star
36

babi-grammars

pip installable package to provide syntax grammars for babi
Python
7
star
37

rubyvenv

Create no-hassle ruby "virtualenvs". No .bashrc, no shims, no cd-magic.
Python
7
star
38

tessdata

pip installable versions of tesseract-ocr data
Python
6
star
39

setuptools-download

setuptools plugin to download external files
Python
6
star
40

pygments-pre-commit

A pygments lexer for pre-commit output.
Python
6
star
41

t

haphazard code snippets
Python
4
star
42

markdown-code-blocks

Generate html from markdown with code-block highlighting
Python
4
star
43

asottile.github.io

Python
4
star
44

hiera-eyaml-sshagent

A hiera-eyaml plugin which uses the ssh agent connected to `SSH_AUTH_SOCK` to encrypt / decrypt values.
Ruby
4
star
45

kensquared

Kotlin
2
star
46

.github

centralized github metadata for asottile
2
star
47

itl

Python
2
star
48

asottile

2
star
49

gnome-terminal-broken

rip
1
star