[claude] Refactor timmyctl inbox() into helper functions (#1169) #1174
@@ -237,6 +237,88 @@ def log_run(
|
||||
console.print(f"[green]✓[/green] Entry logged to {logbook_path}")
|
||||
|
||||
|
||||
def _show_automations_table(limit: int) -> None:
|
||||
"""Display active automations from the automations config."""
|
||||
config_path = _get_config_dir() / "automations.json"
|
||||
config = _load_json_config(config_path)
|
||||
enabled = [a for a in config.get("automations", []) if a.get("enabled", False)]
|
||||
|
||||
table = Table(title="Active Automations")
|
||||
table.add_column("ID", style="cyan")
|
||||
table.add_column("Name", style="green")
|
||||
table.add_column("Category", style="yellow")
|
||||
table.add_column("Trigger", style="magenta")
|
||||
|
||||
for auto in enabled[:limit]:
|
||||
table.add_row(
|
||||
auto.get("id", ""),
|
||||
auto.get("name", ""),
|
||||
"✓" if auto.get("enabled", False) else "✗",
|
||||
auto.get("category", ""),
|
||||
)
|
||||
|
||||
console.print(table)
|
||||
console.print()
|
||||
|
||||
|
||||
def _show_prs_table(limit: int) -> None:
|
||||
"""Display open pull requests from Gitea."""
|
||||
table = Table(title="Open Pull Requests")
|
||||
table.add_column("#", style="cyan")
|
||||
table.add_column("Title", style="green")
|
||||
table.add_column("Author", style="yellow")
|
||||
table.add_column("Status", style="magenta")
|
||||
try:
|
||||
prs = _gitea_api_get(f"/repos/{GITEA_REPO}/pulls?state=open")
|
||||
if prs:
|
||||
for pr in prs[:limit]:
|
||||
table.add_row(
|
||||
str(pr.get("number", "")),
|
||||
pr.get("title", ""),
|
||||
pr.get("user", {}).get("login", ""),
|
||||
pr.get("state", ""),
|
||||
)
|
||||
else:
|
||||
table.add_row("—", "[dim]No open PRs[/dim]", "—", "—")
|
||||
except Exception as exc:
|
||||
table.add_row("—", f"[red]Error fetching PRs: {exc}[/red]", "—", "—")
|
||||
console.print(table)
|
||||
console.print()
|
||||
|
||||
|
||||
def _show_issues_table(limit: int) -> None:
|
||||
"""Display open issues from Gitea."""
|
||||
table = Table(title="Issues Calling for Attention")
|
||||
table.add_column("#", style="cyan")
|
||||
table.add_column("Title", style="green")
|
||||
table.add_column("Type", style="yellow")
|
||||
table.add_column("Priority", style="magenta")
|
||||
try:
|
||||
issues = _gitea_api_get(
|
||||
f"/repos/{GITEA_REPO}/issues?state=open&type=issues&limit={limit}"
|
||||
)
|
||||
if issues:
|
||||
for issue in issues[:limit]:
|
||||
labels = [lb.get("name", "") for lb in issue.get("labels", [])]
|
||||
priority = next((lb for lb in labels if "priority" in lb.lower()), "—")
|
||||
issue_type = next(
|
||||
(lb for lb in labels if lb.lower() in ("bug", "feature", "refactor", "enhancement")),
|
||||
"—",
|
||||
)
|
||||
table.add_row(
|
||||
str(issue.get("number", "")),
|
||||
issue.get("title", ""),
|
||||
issue_type,
|
||||
priority,
|
||||
)
|
||||
else:
|
||||
table.add_row("—", "[dim]No open issues[/dim]", "—", "—")
|
||||
except Exception as exc:
|
||||
table.add_row("—", f"[red]Error fetching issues: {exc}[/red]", "—", "—")
|
||||
console.print(table)
|
||||
console.print()
|
||||
|
||||
|
||||
@app.command()
|
||||
def inbox(
|
||||
limit: int = typer.Option(10, "--limit", "-l", help="Maximum items to show"),
|
||||
@@ -253,91 +335,13 @@ def inbox(
|
||||
console.print("[bold green]Timmy Inbox[/bold green]")
|
||||
console.print()
|
||||
|
||||
# Load automations to show what's enabled
|
||||
config_path = _get_config_dir() / "automations.json"
|
||||
config = _load_json_config(config_path)
|
||||
|
||||
automations = config.get("automations", [])
|
||||
enabled_automations = [a for a in automations if a.get("enabled", False)]
|
||||
|
||||
# Show automation status
|
||||
auto_table = Table(title="Active Automations")
|
||||
auto_table.add_column("ID", style="cyan")
|
||||
auto_table.add_column("Name", style="green")
|
||||
auto_table.add_column("Category", style="yellow")
|
||||
auto_table.add_column("Trigger", style="magenta")
|
||||
|
||||
for auto in enabled_automations[:limit]:
|
||||
auto_table.add_row(
|
||||
auto.get("id", ""),
|
||||
auto.get("name", ""),
|
||||
"✓" if auto.get("enabled", False) else "✗",
|
||||
auto.get("category", ""),
|
||||
)
|
||||
|
||||
console.print(auto_table)
|
||||
console.print()
|
||||
_show_automations_table(limit)
|
||||
|
||||
if include_prs:
|
||||
pr_table = Table(title="Open Pull Requests")
|
||||
pr_table.add_column("#", style="cyan")
|
||||
pr_table.add_column("Title", style="green")
|
||||
pr_table.add_column("Author", style="yellow")
|
||||
pr_table.add_column("Status", style="magenta")
|
||||
try:
|
||||
prs = _gitea_api_get(f"/repos/{GITEA_REPO}/pulls?state=open")
|
||||
if prs:
|
||||
for pr in prs[:limit]:
|
||||
pr_table.add_row(
|
||||
str(pr.get("number", "")),
|
||||
pr.get("title", ""),
|
||||
pr.get("user", {}).get("login", ""),
|
||||
pr.get("state", ""),
|
||||
)
|
||||
else:
|
||||
pr_table.add_row("—", "[dim]No open PRs[/dim]", "—", "—")
|
||||
except Exception as exc:
|
||||
pr_table.add_row(
|
||||
"—", f"[red]Error fetching PRs: {exc}[/red]", "—", "—"
|
||||
)
|
||||
console.print(pr_table)
|
||||
console.print()
|
||||
_show_prs_table(limit)
|
||||
|
||||
if include_issues:
|
||||
issue_table = Table(title="Issues Calling for Attention")
|
||||
issue_table.add_column("#", style="cyan")
|
||||
issue_table.add_column("Title", style="green")
|
||||
issue_table.add_column("Type", style="yellow")
|
||||
issue_table.add_column("Priority", style="magenta")
|
||||
try:
|
||||
issues = _gitea_api_get(
|
||||
f"/repos/{GITEA_REPO}/issues?state=open&type=issues&limit={limit}"
|
||||
)
|
||||
if issues:
|
||||
for issue in issues[:limit]:
|
||||
labels = [lb.get("name", "") for lb in issue.get("labels", [])]
|
||||
priority = next(
|
||||
(lb for lb in labels if "priority" in lb.lower()),
|
||||
"—",
|
||||
)
|
||||
issue_type = next(
|
||||
(lb for lb in labels if lb.lower() in ("bug", "feature", "refactor", "enhancement")),
|
||||
"—",
|
||||
)
|
||||
issue_table.add_row(
|
||||
str(issue.get("number", "")),
|
||||
issue.get("title", ""),
|
||||
issue_type,
|
||||
priority,
|
||||
)
|
||||
else:
|
||||
issue_table.add_row("—", "[dim]No open issues[/dim]", "—", "—")
|
||||
except Exception as exc:
|
||||
issue_table.add_row(
|
||||
"—", f"[red]Error fetching issues: {exc}[/red]", "—", "—"
|
||||
)
|
||||
console.print(issue_table)
|
||||
console.print()
|
||||
_show_issues_table(limit)
|
||||
|
||||
|
||||
@app.command()
|
||||
|
||||
Reference in New Issue
Block a user