Skip to content

Commit

Permalink
Improve printing of epics and stories
Browse files Browse the repository at this point in the history
* Add ability to sort by project and number of tasks
* Completed and non-active stories and epics and shown when `--all` flag
  is specified (by defalt only active entities are printed)
  • Loading branch information
AndreyMarkinPPC committed Jun 4, 2023
1 parent 8044bf7 commit 09a0f99
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name="terka",
version="1.12.0",
version="1.13.0",
description="CLI utility for creating and managing tasks in a terminal",
long_description=README,
long_description_content_type="text/markdown",
Expand Down
10 changes: 3 additions & 7 deletions terka/domain/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,22 +272,18 @@ def execute(self,
del kwargs["all"]
show_completed = True
if entity_type in ("stories", "epics"):
if "all" in kwargs:
if print_options.show_completed:
kwargs["status"] = "ACTIVE,COMPLETED"
del kwargs["all"]
print_options.show_completed = True
else:
kwargs["status"] = "ACTIVE"
if entity_type == "sprints":
if "all" in kwargs:
if print_options.show_completed:
kwargs["status"] = "PLANNED,ACTIVE,COMPLETED"
del kwargs["all"]
else:
kwargs["status"] = "PLANNED,ACTIVE"
if entity_type == "projects":
if "all" in kwargs:
if print_options.show_completed:
kwargs["status"] = "DELETED,ACTIVE,ON_HOLD,COMPLETED"
del kwargs["all"]
show_completed = True
else:
kwargs["status"] = "ACTIVE"
Expand Down
48 changes: 38 additions & 10 deletions terka/service_layer/printer.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ def print_entities(self, entities, type, repo, custom_sort, print_options):
repo=repo,
print_options=print_options)
elif type in ("epics", "stories"):
if custom_sort == "project":
entities.sort(key=lambda c: c.project, reverse=True)
elif custom_sort == "tasks":
entities.sort(key=lambda c: len(c.tasks), reverse=True)

self.print_composite(entities=entities,
repo=repo,
print_options=print_options,
Expand Down Expand Up @@ -208,9 +213,28 @@ def print_composite(self,
composite_type,
kwargs=None):
table = Table(box=self.box, title=composite_type.upper(), expand=True)
for column in ("id", "name", "description", "project", "tasks"):
non_active_entities = Table(box=self.box,
title=f"INACTIVE {composite_type.upper()}",
expand=True)
default_columns = ("id", "name", "description", "status", "project",
"tasks")
for column in default_columns:
table.add_column(column, style="bold")
for column in default_columns:
non_active_entities.add_column(column, style="bold")
for i, entity in enumerate(entities):
try:
project_obj = services.lookup_project_name(
entity.project, repo)
project = project_obj.name
except:
project = None
if entity.status.name == "COMPLETED":
non_active_entities.add_row(f"E{entity.id}", str(entity.name),
entity.description,
entity.status.name, project,
str(len(tasks)))
continue
tasks = []
completed_tasks = []
for entity_task in entity.tasks:
Expand All @@ -219,17 +243,21 @@ def print_composite(self,
tasks.append(task)
else:
completed_tasks.append(task)
try:
project_obj = services.lookup_project_name(
entity.project, repo)
project = project_obj.name
except:
project = None
if i == 0 or tasks or print_options.show_completed:
table.add_row(f"E{entity.id}", str(entity.name),
entity.description, project, str(len(tasks)))
if len(completed_tasks) == len(
entity.tasks):
non_active_entities.add_row(f"E{entity.id}", str(entity.name),
entity.description,
entity.status.name, project,
str(len(tasks)))
continue
# if i == 0 or tasks or print_options.show_completed:
table.add_row(f"E{entity.id}", str(entity.name),
entity.description, entity.status.name, project,
str(len(tasks)))
if table.row_count:
self.console.print(table)
if non_active_entities.row_count and print_options.show_completed:
self.console.print(non_active_entities)
if print_options.show_tasks and tasks:
self.print_task(entities=tasks,
repo=repo,
Expand Down

0 comments on commit 09a0f99

Please sign in to comment.