Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions phable/cli/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,22 @@
default="plain",
help="Output format",
)
@click.option("--full", "show_full", is_flag=True, help="Also show task comments")
@click.argument("task-id", type=TASK_ID, required=True)
@click.pass_obj
def show_task(
client: PhabricatorClient, task_id: int, format: TaskFormat = TaskFormat.plain
client: PhabricatorClient,
task_id: int,
format: TaskFormat = TaskFormat.plain,
show_full: bool = False,
):
"""Show task details

\b
Examples:
$ phable show T123456 # show task details as plaintext
$ phable show T123456 --format=json # show task details as json
$ phable show T123456 --full # show task details with comments
$ phable show T123456 --format=json # show task details as json

"""
if task := client.show_task(task_id):
Expand All @@ -32,6 +37,7 @@ def show_task(
with_tags=True,
with_subtasks=True,
with_parent=True,
with_comments=show_full,
)
display_task(task=task, format=format)
else:
Expand Down
8 changes: 8 additions & 0 deletions phable/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ def print(self, task: dict) -> None:
print(
f"{status} - {Task.from_int(subtask['id'])} - @{subtask['owner']:<10} - {subtask['fields']['name']}"
)
if "comments" in task:
print("Comments:")
if task["comments"]:
for i, comment in enumerate(task["comments"], start=1):
print(f"--- Comment #{i} ---")
print(comment)
else:
print("(none)")

def print_list(self, tasks: list[dict]) -> None:
for task in tasks:
Expand Down
18 changes: 18 additions & 0 deletions phable/phabricator.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ def enrich_task(
with_tags: bool = False,
with_subtasks: bool = False,
with_parent: bool = False,
with_comments: bool = False,
) -> dict[str, Any]:
"""Load additional data about a task.

Expand All @@ -128,6 +129,8 @@ def enrich_task(
self.enrich_task_with_subtasks(task)
if with_parent:
self.enrich_task_with_parent(task)
if with_comments:
self.enrich_task_with_comments(task)
return task

def enrich_task_with_author_owner(self, task: dict[str, Any]) -> None:
Expand Down Expand Up @@ -168,6 +171,21 @@ def enrich_task_with_parent(self, task: dict[str, Any]) -> None:
parent = self.find_parent_task(subtask_id=task["id"])
task["parent"] = parent

def enrich_task_with_comments(self, task: dict[str, Any]) -> None:
transactions = self.find_task_transactions(task_id=task["id"])
task["comments"] = [
comment["content"]["raw"]
for transaction in transactions
for comment in transaction.get("comments", [])
if not comment.get("removed") and comment.get("content", {}).get("raw")
]

def find_task_transactions(self, task_id: int) -> list[dict[str, Any]]:
return self._make_request(
"transaction.search",
params={"objectIdentifier": Task.from_int(task_id)},
)["result"]["data"]

def find_tasks(
self,
column_phids: Optional[list[str]] = None,
Expand Down
Loading