Coverage for little_loops/cli/issues/count_cmd.py: 0%

1"""ll-issues count: Count active issues with optional type/priority filters."""

2

3 from __future__ import annotations

4

5 import argparse

6 from typing import TYPE_CHECKING

7

8 from little_loops.cli.output import print_json

9

10 if TYPE_CHECKING:

11 from little_loops.config import BRConfig

12

13

14 def cmd_count(config: BRConfig, args: argparse.Namespace) -> int:

15 """Print active issue counts.

16

17 Args:

18 config: Project configuration

19 args: Parsed arguments with optional .type, .priority, and .json attributes

20

21 Returns:

22 Exit code (0 = success)

23 """

24 from little_loops.issue_parser import find_issues

25

26 type_prefixes = {args.type} if getattr(args, "type", None) else None

27 issues = find_issues(config, type_prefixes=type_prefixes)

28

29 if getattr(args, "priority", None):

30 issues = [i for i in issues if i.priority == args.priority]

31

32 if getattr(args, "json", False):

33 by_type: dict[str, int] = {"BUG": 0, "FEAT": 0, "ENH": 0}

34 by_priority: dict[str, int] = {

35 "P0": 0,

36 "P1": 0,

37 "P2": 0,

38 "P3": 0,

39 "P4": 0,

40 "P5": 0,

41 }

42 for issue in issues:

43 prefix = issue.issue_id.split("-", 1)[0]

44 if prefix in by_type:

45 by_type[prefix] += 1

46 if issue.priority in by_priority:

47 by_priority[issue.priority] += 1

48

49 print_json({"total": len(issues), "by_type": by_type, "by_priority": by_priority})

50 return 0

51

52 print(len(issues))

53 return 0