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 a34cdf1 commit 22a478b
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
- All commands now have a CSV output format, available with the
``--format=csv`` argument.

- **check-fixmes** and **check-branches** commands now have a
``--only-old`` argument to show, well, only old annotations or
branches.


0.8.10 (2023-08-16)
-------------------
Expand Down
11 changes: 11 additions & 0 deletions docs/check_branches.rst
Original file line number Diff line number Diff line change
Expand Up @@ -261,3 +261,14 @@ The output format.
| Type: string, one of: ``csv``, ``text`` or ``xunit``.
| Default: ``text``
| Example: ``format = "xunit"``.

``only-old`` (overridable via the command line)
...............................................

By default, all branches are displayed. When this option is enabled,
only old branches are displayed.

| Type: boolean.
| Default: ``false``
| Example: ``only-old = true``.
11 changes: 11 additions & 0 deletions docs/check_fixmes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ The output format.
| Example: ``format = "xunit"``.

``only-old`` (overridable via the command line)
...............................................

By default, all annotations are displayed. When this option is
enabled, only old annotations are displayed.

| Type: boolean.
| Default: ``false``
| Example: ``only-old = true``.

Detection options
-----------------

Expand Down
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 22a478b

Please sign in to comment.