Skip to content

Commit

Permalink
feat: ✨ Improve report (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanderleek authored Dec 23, 2024
1 parent 52d6959 commit 7199730
Show file tree
Hide file tree
Showing 24 changed files with 4,771 additions and 4,701 deletions.
53 changes: 33 additions & 20 deletions codelimit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
from typer.core import TyperGroup

from codelimit.commands.check import check_command
from codelimit.commands.report.report import ReportFormat, report_command
from codelimit.commands.findings import findings_command
from codelimit.commands.report import ReportFormat, report_command
from codelimit.commands.scan import scan_command
from codelimit.common.Configuration import Configuration
from codelimit.common.utils import configure_github_repository
Expand All @@ -27,22 +28,6 @@ def list_commands(self, ctx: Context):
# cli.add_typer(app.app, name="app", help="Code Limit GitHub App commands")


@cli.command(help="Check file(s)")
def check(
paths: Annotated[List[Path], typer.Argument(exists=True)],
exclude: Annotated[
Optional[list[str]], typer.Option(help="Glob patterns for exclusion")
] = None,
quiet: Annotated[
bool, typer.Option("--quiet", help="No output when successful")
] = False,
):
if exclude:
Configuration.exclude.extend(exclude)
Configuration.load(Path('.'))
check_command(paths, quiet)


@cli.command(help="Scan a codebase")
def scan(
path: Annotated[
Expand All @@ -64,14 +49,42 @@ def report(
path: Annotated[
Path, typer.Argument(exists=True, file_okay=False, help="Codebase root")
] = Path("."),
full: Annotated[bool, typer.Option("--full", help="Show full report")] = False,
totals: Annotated[bool, typer.Option("--totals", help="Only show totals")] = False,
fmt: Annotated[
ReportFormat, typer.Option("--format", help="Output format")
] = ReportFormat.text,
):
Configuration.load(path)
report_command(path, full, totals, fmt)
report_command(path, fmt)


@cli.command(help="Show findings for codebase")
def findings(
path: Annotated[
Path, typer.Argument(exists=True, file_okay=False, help="Codebase root")
] = Path("."),
full: Annotated[bool, typer.Option("--full", help="Show full findings")] = False,
fmt: Annotated[
ReportFormat, typer.Option("--format", help="Output format")
] = ReportFormat.text,
):
Configuration.load(path)
findings_command(path, full, fmt)


@cli.command(help="Check file(s)")
def check(
paths: Annotated[List[Path], typer.Argument(exists=True)],
exclude: Annotated[
Optional[list[str]], typer.Option(help="Glob patterns for exclusion")
] = None,
quiet: Annotated[
bool, typer.Option("--quiet", help="No output when successful")
] = False,
):
if exclude:
Configuration.exclude.extend(exclude)
Configuration.load(Path('.'))
check_command(paths, quiet)


@cli.command(help="Generate badge Markdown")
Expand Down
16 changes: 16 additions & 0 deletions codelimit/commands/findings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path

from rich.console import Console

from codelimit.commands.report import ReportFormat
from codelimit.common.report import format_markdown, format_text
from codelimit.utils import read_report


def findings_command(path: Path, full: bool, fmt: ReportFormat):
stdout = Console(soft_wrap=True)
report = read_report(path, stdout)
if fmt == ReportFormat.markdown:
format_markdown.print_findings(report, stdout, full)
else:
format_text.print_findings(report, stdout, full)
16 changes: 16 additions & 0 deletions codelimit/commands/report.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from pathlib import Path

from rich.console import Console

from codelimit.common.report import format_markdown, format_text
from codelimit.common.report.ReportFormat import ReportFormat
from codelimit.utils import read_report


def report_command(path: Path, fmt: ReportFormat):
stdout = Console(soft_wrap=True)
report = read_report(path, stdout)
if fmt == ReportFormat.markdown:
format_markdown.print_report(report, stdout)
else:
format_text.print_report(report, stdout)
Empty file.
80 changes: 0 additions & 80 deletions codelimit/commands/report/format_markdown.py

This file was deleted.

90 changes: 0 additions & 90 deletions codelimit/commands/report/report.py

This file was deleted.

6 changes: 6 additions & 0 deletions codelimit/commands/scan.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
from pathlib import Path
from typing import Optional

from rich.console import Console

from codelimit.common.Configuration import Configuration
from codelimit.common.Scanner import scan_codebase
from codelimit.common.report import format_text
from codelimit.common.report.Report import Report
from codelimit.common.report.ReportReader import ReportReader
from codelimit.common.report.ReportWriter import ReportWriter


def scan_command(path: Path):
stdout = Console(soft_wrap=True)
cache_dir = path.joinpath(".codelimit_cache").resolve()
report_path = cache_dir.joinpath("codelimit.json").resolve()
cached_report = _read_cached_report(report_path)
format_text.print_totals_header(stdout)
codebase = scan_codebase(path, cached_report)
codebase.aggregate()
report = Report(codebase, Configuration.repository)
format_text.print_summary(report, stdout)
if not cache_dir.exists():
cache_dir.mkdir()
cache_dir_tag = cache_dir.joinpath("CACHEDIR.TAG").resolve()
Expand Down
17 changes: 2 additions & 15 deletions codelimit/common/ScanResultTable.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from rich import box
from rich.table import Table
from rich.text import Text

from codelimit.common.ScanTotals import ScanTotals

Expand Down Expand Up @@ -29,23 +28,11 @@ def __init__(self, scan_totals: ScanTotals):

def _populate(self):
for language_totals in self.scan_totals.languages_totals():
hard_to_maintain = language_totals.hard_to_maintain
if hard_to_maintain > 0:
hard_to_maintain_text = Text(
f"{hard_to_maintain:n}", style="dark_orange"
)
else:
hard_to_maintain_text = "0"
unmaintainable = language_totals.unmaintainable
if unmaintainable > 0:
unmaintainable_text = Text(f"{unmaintainable:n}", style="red")
else:
unmaintainable_text = "0"
self.add_row(
language_totals.language,
f"{language_totals.files:n}",
f"{language_totals.loc:n}",
f"{language_totals.functions:n}",
hard_to_maintain_text,
unmaintainable_text,
f"{language_totals.hard_to_maintain:n}",
f"{language_totals.unmaintainable:n}"
)
Loading

0 comments on commit 7199730

Please sign in to comment.