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
39 changes: 38 additions & 1 deletion .claude/ai-usage-prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ budjira epic show PROJ-100
# Progress: 12/20 issues done (60%)
```

## Adding Comments
## Managing Comments

### Add Comment to Issue

Expand Down Expand Up @@ -716,6 +716,43 @@ budjira comment add PROJ-789 "Status update" --connection prod-jira
- Multi-line content for detailed updates
- Empty content (whitespace only) aborts comment creation

### List Comments

```bash
budjira comment list ISSUE-KEY
```

Table with comment ID, author, creation date and first line of each body. Use `--format json` for machine-readable output.

### Show Comment

```bash
budjira comment show ISSUE-KEY COMMENT-ID
```

Prints the full body of a single comment. Find COMMENT-ID via `comment list`.

### Update Comment

```bash
budjira comment update ISSUE-KEY COMMENT-ID [TEXT] [OPTIONS]
```

Replaces the body of an existing comment. Same input rules as `comment add`:
- If TEXT is omitted, the editor opens **prefilled with the current body** — the reliable way to fix wording in place
- `--editor`, `-e`: Open editor (with TEXT as initial content if provided)
- Empty content (whitespace only) aborts without an API call

**Prefer update over delete:** Jira often forbids deleting comments, even for their author (reported as a 400 permission error). `comment update` is the reliable path to correct a posted comment.

### Delete Comment

```bash
budjira comment delete ISSUE-KEY COMMENT-ID [--force]
```

Deletes a comment after a confirmation prompt (`--force`/`-f` skips it). If Jira denies the deletion, the error message points to `comment update` as the fallback.

## Time Tracking

### Add Worklog Entry
Expand Down
3 changes: 2 additions & 1 deletion .claude/context.md
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ budjira/
| Transition Screen Fields | v1.23.0 | `budjira issue update --status X --field k=v --dry-run` |
| Description Dialect | v1.23.0 | `budjira connect add --description-dialect wiki`, `create issue/issue update --description-dialect` |
| Reproducible AI Prompt | v1.23.0 | `budjira ai usage-prompt --defaults --plain` |
| Comment CRUD | unreleased (#81) | `budjira comment list/show/update/delete` |
| Self-Update | v0.4.0 | `budjira update` |

---
Expand Down Expand Up @@ -514,5 +515,5 @@ budjira/

---

**Letzte Aktualisierung**: 2026-04-01
**Letzte Aktualisierung**: 2026-08-23
**Nächste Aktualisierung**: Bei "sichere context" oder signifikanten Änderungen
28 changes: 26 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
- 📋 **Definition of Ready**: Customizable templates for Story, Bug, Task with validation
- 🔄 **Update Issues**: Transition status, update fields, manage labels, delete issues
- 🎯 **Epic Management**: Link stories to epics and view epic progress
- 💬 **Comment Management**: Add comments to issues without time tracking
- 💬 **Comment Management**: Full comment CRUD (add, list, show, update, delete) without time tracking
- ⏱️ **Time Tracking**: Comprehensive worklog management and time estimates
- 🎼 **Tempo Integration**: Full support for Tempo Timesheets API for enterprise time tracking
- 📊 **JSON Output**: Machine-readable JSON format for automation and integration with other tools
Expand Down Expand Up @@ -559,7 +559,7 @@ budjira issue update PROJ-123 --log-work 2h --work-comment "Implemented API endp
- Date only: `2025-10-25` (time defaults to 00:00)
- Relative: `today`, `yesterday`

### Add Comments
### Manage Comments

Add comments to Jira issues without logging time (unlike worklogs which combine comments with time tracking).

Expand All @@ -577,6 +577,30 @@ budjira comment add PROJ-123
budjira comment add PROJ-123 "Comment text" --connection my-connection
```

Existing comments can be listed, inspected, corrected and deleted without leaving the CLI:

```bash
# List comments (id, author, date, first line)
budjira comment list PROJ-123

# Show the full body of a comment
budjira comment show PROJ-123 10234

# Replace a comment body directly
budjira comment update PROJ-123 10234 "Corrected deployment note"

# Or edit the current body in your editor (prefilled)
budjira comment update PROJ-123 10234

# Delete a comment (asks for confirmation; --force skips)
budjira comment delete PROJ-123 10234
```

**Prefer `update` over `delete`:** Jira often forbids deleting comments, even for their
author (it answers with a 400 permission error). `comment update` is the reliable path
to correct a posted comment — the editor opens prefilled with the current body. If a
deletion is denied, the error message points you to `comment update`.

**Use Cases:**
- Status updates without time tracking
- Analysis results and findings
Expand Down
261 changes: 260 additions & 1 deletion budjira/cli/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@

import typer
from rich.console import Console
from rich.table import Table

from budjira.core.jira_client import JiraClient
from budjira.utils.connection import get_active_connection
from budjira.utils.editor import open_editor
from budjira.utils.errors import BudjiraError
from budjira.utils.formatter import OutputFormatter

logger = logging.getLogger(__name__)
console = Console()

app = typer.Typer(help="Add comments to Jira issues")
app = typer.Typer(help="Manage comments on Jira issues (add, list, show, update, delete)")

_PREVIEW_LENGTH = 100
_LIST_PREVIEW_LENGTH = 80


@app.command(name="add")
Expand Down Expand Up @@ -85,3 +90,257 @@ def add_comment(
logger.exception("Unexpected error adding comment")
console.print(f"[red]Unexpected error:[/red] {e}")
raise typer.Exit(1) from e


@app.command(name="list")
def list_comments(
ctx: typer.Context,
issue_key: str = typer.Argument(..., help="Issue key (e.g., PROJ-123)"),
connection_name: str | None = typer.Option(
None,
"--connection",
"-c",
help="Connection name to use (overrides default)",
),
) -> None:
"""List all comments on a Jira issue.

Shows a table with comment ID, author, creation date and the first line
of each comment body. Use the ID with 'comment show', 'comment update'
or 'comment delete'.

Examples:
# List comments as table
budjira comment list PROJ-123

# List comments as JSON
budjira --format json comment list PROJ-123
"""
output_format = ctx.obj.get("format", "table") if ctx.obj else "table"

try:
connection = get_active_connection(connection_name)
jira_client = JiraClient.from_connection(connection)
comments = jira_client.comments.list(issue_key)

if OutputFormatter.is_json_format(output_format):
OutputFormatter.output_json(
{
"issue": issue_key,
"total": len(comments),
"comments": comments,
}
)
return

if not comments:
console.print(f"[yellow]No comments found on {issue_key}[/yellow]")
return

table = Table(title=f"Comments on {issue_key}", show_header=True)
table.add_column("ID", style="dim")
table.add_column("Author", style="cyan")
table.add_column("Created", style="blue")
table.add_column("Comment", style="white", no_wrap=False)

for comment in comments:
table.add_row(
str(comment["id"]),
str(comment["author"]),
_format_date(comment.get("created")),
_first_line(comment.get("body"), _LIST_PREVIEW_LENGTH),
)

console.print(table)
console.print(f"\n[green]Total: {len(comments)} comment(s)[/green]")

except BudjiraError as e:
console.print(f"[red]Error:[/red] {e}")
raise typer.Exit(1) from e
except Exception as e:
logger.exception("Unexpected error listing comments")
console.print(f"[red]Unexpected error:[/red] {e}")
raise typer.Exit(1) from e


@app.command(name="show")
def show_comment(
ctx: typer.Context,
issue_key: str = typer.Argument(..., help="Issue key (e.g., PROJ-123)"),
comment_id: str = typer.Argument(..., help="Comment ID (see 'comment list')"),
connection_name: str | None = typer.Option(
None,
"--connection",
"-c",
help="Connection name to use (overrides default)",
),
) -> None:
"""Show the full body of a single comment.

Examples:
# Show a comment
budjira comment show PROJ-123 10234

# Show a comment as JSON
budjira --format json comment show PROJ-123 10234
"""
output_format = ctx.obj.get("format", "table") if ctx.obj else "table"

try:
connection = get_active_connection(connection_name)
jira_client = JiraClient.from_connection(connection)
comment = jira_client.comments.get(issue_key, comment_id)

if OutputFormatter.is_json_format(output_format):
OutputFormatter.output_json(comment)
return

console.print(f"[bold]Comment {comment['id']} on {issue_key}[/bold]")
console.print(f" [dim]Author:[/dim] {comment['author']}")
if comment.get("created"):
console.print(f" [dim]Created:[/dim] {comment['created']}")
if comment.get("updated"):
console.print(f" [dim]Updated:[/dim] {comment['updated']}")
console.print()
console.print(comment["body"] or "")

except BudjiraError as e:
console.print(f"[red]Error:[/red] {e}")
raise typer.Exit(1) from e
except Exception as e:
logger.exception("Unexpected error showing comment")
console.print(f"[red]Unexpected error:[/red] {e}")
raise typer.Exit(1) from e


@app.command(name="update")
def update_comment(
issue_key: str = typer.Argument(..., help="Issue key (e.g., PROJ-123)"),
comment_id: str = typer.Argument(..., help="Comment ID (see 'comment list')"),
text: str | None = typer.Argument(None, help="New comment text (omit to open editor with current body)"),
editor: bool = typer.Option(False, "--editor", "-e", help="Open editor for multi-line comment"),
connection_name: str | None = typer.Option(
None,
"--connection",
"-c",
help="Connection name to use (overrides default)",
),
) -> None:
"""Replace the body of an existing comment.

Without TEXT the editor opens prefilled with the current comment body,
so you can adjust the wording in place. This is the reliable way to fix
a comment — Jira often forbids deleting comments even for their author.

Examples:
# Replace body directly
budjira comment update PROJ-123 10234 "Corrected deployment note"

# Edit current body in editor
budjira comment update PROJ-123 10234
"""
try:
# Resolve connection
connection = get_active_connection(connection_name)
jira_client = JiraClient.from_connection(connection)

# Get new comment text
if editor or text is None:
# Prefill the editor with the given text or the current body
initial_content = text if text else (jira_client.comments.get(issue_key, comment_id).get("body") or "")
comment_text = open_editor(initial_content, file_extension=".md")

# Check if user provided content
if not comment_text.strip():
console.print("[yellow]No comment text provided. Aborting.[/yellow]")
return
else:
comment_text = text

# Update comment
result = jira_client.comments.update(issue_key, comment_id, comment_text)

# Display success message
console.print(f"\n[green]✓[/green] Comment {result['id']} on {issue_key} updated")
console.print(f" [dim]Author:[/dim] {result['author']}")
if result.get("updated"):
console.print(f" [dim]Updated:[/dim] {result['updated']}")

# Show preview of comment (first 100 chars)
preview = comment_text[:_PREVIEW_LENGTH]
if len(comment_text) > _PREVIEW_LENGTH:
preview += "..."
console.print(f"\n[dim]Preview:[/dim] {preview}")

except BudjiraError as e:
console.print(f"[red]Error:[/red] {e}")
raise typer.Exit(1) from e
except Exception as e:
logger.exception("Unexpected error updating comment")
console.print(f"[red]Unexpected error:[/red] {e}")
raise typer.Exit(1) from e


@app.command(name="delete")
def delete_comment(
issue_key: str = typer.Argument(..., help="Issue key (e.g., PROJ-123)"),
comment_id: str = typer.Argument(..., help="Comment ID (see 'comment list')"),
force: bool = typer.Option(False, "--force", "-f", help="Skip confirmation prompt"),
connection_name: str | None = typer.Option(
None,
"--connection",
"-c",
help="Connection name to use (overrides default)",
),
) -> None:
"""Delete a comment from a Jira issue.

Note that Jira often forbids deleting comments even for their author.
If deletion is denied, use 'budjira comment update' to revise the body
instead.

Examples:
# Delete comment with confirmation
budjira comment delete PROJ-123 10234

# Delete comment without confirmation
budjira comment delete PROJ-123 10234 --force
"""
try:
# Resolve connection
connection = get_active_connection(connection_name)
jira_client = JiraClient.from_connection(connection)

# Confirm deletion unless --force is used
if not force:
confirm = typer.confirm(f"Delete comment {comment_id} on {issue_key}?")
if not confirm:
console.print("[yellow]Deletion cancelled[/yellow]")
return

# Delete comment
jira_client.comments.delete(issue_key, comment_id)
console.print(f"[green]✓[/green] Comment {comment_id} deleted from {issue_key}")

except BudjiraError as e:
console.print(f"[red]Error:[/red] {e}")
raise typer.Exit(1) from e
except Exception as e:
logger.exception("Unexpected error deleting comment")
console.print(f"[red]Unexpected error:[/red] {e}")
raise typer.Exit(1) from e


def _format_date(created: str | None) -> str:
"""Format a Jira timestamp for table display (date part only)."""
return created[:10] if created else ""


def _first_line(body: str | None, max_length: int) -> str:
"""Return the first line of a comment body, truncated to max_length."""
if not body:
return ""
first = body.splitlines()[0] if body.splitlines() else ""
if len(first) > max_length:
return first[:max_length] + "..."
return first
Loading
Loading