Skip to content

Commit

Permalink
cli: Add --only-old argument to all commands
Browse files Browse the repository at this point in the history
By default, all commands show all annotations, branches, etc.,
including those that are recent. When exporting to a CSV format, it's
useful to filter out the recent items and only display old ones.
  • Loading branch information
dbaty committed Apr 12, 2024
1 parent c21c671 commit 0760f7b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/check_oldies/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class Config:
max_age: int = 180

output_format: output.OutputFormat = output.OutputFormat.TEXT
only_old: bool = False
colorize_errors: bool = True

annotations: typing.Sequence = ("todo", "fixme", ) # no-check-fixmes
Expand Down
1 change: 1 addition & 0 deletions src/check_oldies/branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class Config:

output_format: output.OutputFormat = output.OutputFormat.TEXT
colorize_errors: bool = True
only_old: bool = False

calm_branches: typing.Sequence = ("gh-pages", "master", "main", "prod", "maint(enance)?/.*")
ignore_branches_without_pull_request: bool = False
Expand Down
8 changes: 8 additions & 0 deletions src/check_oldies/check_branches.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def get_parser():
f"Defaults to {check_oldies.branches.Config.max_age}."
),
)
parser.add_argument(
"--only-old",
action="store_true",
default=False,
help="Show only old branches. By default, the command shows all branches."
)
parser.add_argument(
"--no-color",
action="store_false",
Expand All @@ -62,6 +68,8 @@ def main():
sys.exit(f'Invalid path: "{config.path}" is not a Git repository.')

branches = check_oldies.branches.get_branches(config)
if config.only_old:
branches = [branch for branch in branches if branch.is_old]
branches.sort(key=lambda branch: (branch.author, -branch.age, branch.name))
has_old_branches = any(branch for branch in branches if branch.is_old)

Expand Down
8 changes: 8 additions & 0 deletions src/check_oldies/check_fixmes.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def get_parser():
f"Defaults to {check_oldies.annotations.Config.max_age}."
),
)
parser.add_argument(
"--only-old",
action="store_true",
default=False,
help="Show only old annotations. By default, the command shows all annotations."
)
parser.add_argument(
"--no-color",
action="store_false",
Expand All @@ -62,6 +68,8 @@ def main():
sys.exit(f'Invalid path: "{config.path}" is not a Git repository.')

annotations = check_oldies.annotations.get_annotations(config)
if config.only_old:
annotations = [a for a in annotations if a.is_old]
annotations.sort(key=lambda f: (f.assignee, -f.age, f.filename, f.line_no))
has_old_annotations = any(ann for ann in annotations if ann.is_old)

Expand Down

0 comments on commit 0760f7b

Please sign in to comment.