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
11 changes: 6 additions & 5 deletions .claude/ai-usage-prompt.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
╭─ 🦖 budjira v1.35.0 ─ Your CLI Pal for Jira ─╮
╰──────────────────────────────────────────────╯

# budjira - Jira CLI Tool Usage Guide for AI Assistants

## Overview
Expand Down Expand Up @@ -748,13 +745,17 @@ Add comments to Jira issues without logging time (unlike worklogs which combine
**Options:**
- `--editor`, `-e`: Open editor for multi-line comment
- `--attach FILE`: Attach file(s) to the issue and reference them in the comment (repeatable; images are embedded via `!file!` wiki markup, other files linked via `[^file]`)
- `--embed FILE`: Embed image file(s) inline in the comment body (repeatable; Jira Cloud only — posts the comment as ADF via REST API v3 so the image renders inside the body)
- `--embed FILE`: Embed image file(s) inline in the comment body (repeatable; Jira Cloud only — posts the comment as ADF via REST API v3 so the image renders inside the body; no dialect applies)
- `--dialect {markdown,wiki}`: Dialect the comment is written in (overrides the connection's `comment_dialect` for this call)
- `--connection NAME`, `-c`: Use specific connection

**Behavior:**
- If TEXT is omitted, editor opens automatically (unless `--attach`/`--embed` files carry the comment)
- If TEXT is provided with `--editor`, editor opens with TEXT as initial content
- Supports markdown formatting
- The connection's `comment_dialect` decides the treatment: `wiki` (the default)
sends the text unchanged — the historical behaviour; `markdown` converts to
wiki markup first. Descriptions follow the separate `description_dialect`
(default `markdown`) — the two fields are configured independently.
- Comments are posted immediately without time tracking

**Examples:**
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,26 @@ budjira issue update PROJ-123 --description-dialect markdown --description "## N
The option wins over the connection setting, which wins over the default. Existing
configurations keep working unchanged: a connection without the key is `markdown`.

**Comment dialect:**

Comments historically went out raw, so their connection setting
`comment_dialect` defaults to `wiki` (sent unchanged). Set it to `markdown` on
an instance where authors write Markdown in comments as well, and one written
dialect then serves both fields — descriptions follow `description_dialect`
(default `markdown`), comments follow `comment_dialect` (default `wiki`); the
two are independent so an instance that differs per field stays representable.
`comment add`/`comment update` accept `--dialect` to deviate for a single call
(the `--embed` path posts ADF via REST v3 verbatim; no dialect applies there).

```bash
# An instance whose comments are authored in Markdown
budjira connect add --name work --url https://work.atlassian.net \
--email user@work.com --project PROJ --comment-dialect markdown

# Deviate for a single comment
budjira comment add PROJ-123 "## Notes" --dialect markdown
```

**Project metadata:** issue types, priorities and components are discovered from Jira and
cached locally — they drive validation of `--type`/`--priority` and sub-task detection:

Expand Down
36 changes: 33 additions & 3 deletions budjira/cli/comment.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from budjira.core.jira_client import JiraClient
from budjira.utils.connection import get_active_connection
from budjira.utils.description import DescriptionDialectOption, resolve_comment_dialect
from budjira.utils.editor import open_editor
from budjira.utils.errors import BudjiraError
from budjira.utils.formatter import OutputFormatter
Expand Down Expand Up @@ -101,6 +102,11 @@ def add_comment(
"-c",
help="Connection name to use (overrides default)",
),
dialect: DescriptionDialectOption | None = typer.Option(
None,
"--dialect",
help="Dialect the comment is written in (overrides the connection's comment_dialect for this call)",
),
) -> None:
"""Add a comment to a Jira issue.

Expand All @@ -109,6 +115,12 @@ def add_comment(
comment text, '--embed' renders images inline in the comment body
(Jira Cloud only).

Comment dialect: the connection's comment_dialect decides whether the
text is converted ('markdown') or sent unchanged ('wiki', the default -
the historical raw behaviour). '--dialect' deviates for a single call.
The '--embed' path posts ADF (REST API v3) verbatim; no dialect applies
there.

Examples:
# Quick single-line comment
budjira comment add PROJ-123 "Fixed in latest deployment"
Expand All @@ -121,6 +133,9 @@ def add_comment(

# Comment with an image embedded inline (Jira Cloud)
budjira comment add PROJ-123 "Before/after:" --embed chart.png

# A markdown comment on a wiki-dialect connection
budjira comment add PROJ-123 "## Notes" --dialect markdown
"""
try:
# Resolve connection
Expand Down Expand Up @@ -157,11 +172,15 @@ def add_comment(
elif attach:
attached = [jira_client.attachments.add(issue_key, path) for path in attach]
comment_text = _append_attachment_refs(comment_text, attached)
result = jira_client.add_comment(issue_key, comment_text)
result = jira_client.comments.add(
issue_key, comment_text, dialect=resolve_comment_dialect(dialect, connection)
)
for attachment in attached:
console.print(f" [dim]Attached:[/dim] {attachment['filename']}")
else:
result = jira_client.add_comment(issue_key, comment_text)
result = jira_client.comments.add(
issue_key, comment_text, dialect=resolve_comment_dialect(dialect, connection)
)

# Display success message
console.print(f"\n[green]✓[/green] Comment added to {issue_key}")
Expand Down Expand Up @@ -319,13 +338,22 @@ def update_comment(
"-c",
help="Connection name to use (overrides default)",
),
dialect: DescriptionDialectOption | None = typer.Option(
None,
"--dialect",
help="Dialect the new comment text is written in (overrides the connection's comment_dialect for this call)",
),
) -> 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.

The connection's comment_dialect decides whether the new text is
converted ('markdown') or sent unchanged ('wiki', the default);
'--dialect' deviates for a single call.

Examples:
# Replace body directly
budjira comment update PROJ-123 10234 "Corrected deployment note"
Expand All @@ -352,7 +380,9 @@ def update_comment(
comment_text = text

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

# Display success message
console.print(f"\n[green]✓[/green] Comment {result['id']} on {issue_key} updated")
Expand Down
14 changes: 14 additions & 0 deletions budjira/cli/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ def add_connection(
"--description-dialect",
help="Dialect descriptions on this instance are written in (default: markdown)",
),
comment_dialect: DescriptionDialectOption = typer.Option(
None,
"--comment-dialect",
help="Dialect comments on this instance are written in (default: wiki - sent unchanged)",
),
api_token_ref: str = typer.Option(
None,
"--api-token-ref",
Expand Down Expand Up @@ -102,6 +107,11 @@ def add_connection(
markup, e.g. panel macros and "#" ordered lists; descriptions are then sent
unchanged. Individual calls can deviate with --description-dialect.

Comment dialect: comments were historically posted raw, so the default is
"wiki" (sent unchanged). Set --comment-dialect markdown for an instance
where authors write Markdown in comments as well. Individual calls can
deviate with 'comment add/update --dialect'.

Examples:
# Interactive mode
budjira connect add
Expand Down Expand Up @@ -210,6 +220,8 @@ def add_connection(
}
if description_dialect is not None:
changed_values["description_dialect"] = description_dialect.value
if comment_dialect is not None:
changed_values["comment_dialect"] = comment_dialect.value
if api_token_ref is not None:
changed_values["api_token_ref"] = api_token_ref
elif store_token:
Expand Down Expand Up @@ -242,6 +254,7 @@ def add_connection(
console.print(f" Email: {connection.email}")
console.print(f" Project: {connection.project_key}")
console.print(f" Descriptions: {connection.description_dialect}")
console.print(f" Comments: {connection.comment_dialect}")
console.print(f" API token: {describe_api_token_source(connection)}")

# Auto-sync project metadata
Expand Down Expand Up @@ -344,6 +357,7 @@ def show_connection(
console.print(f"[bold]Email:[/bold] {connection.email}")
console.print(f"[bold]Project Key:[/bold] {connection.project_key}")
console.print(f"[bold]Descriptions:[/bold] {connection.description_dialect}")
console.print(f"[bold]Comments:[/bold] {connection.comment_dialect}")
console.print(f"[bold]Cache:[/bold] {'Enabled' if connection.cache_enabled else 'Disabled'}")

# Token source (references shown verbatim, never the resolved value)
Expand Down
1 change: 1 addition & 0 deletions budjira/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def _serialize_connection(self, conn: Connection) -> dict[str, object]:
"cache_ttl_hours": conn.cache_ttl_hours,
"tempo_enabled": conn.tempo_enabled,
"description_dialect": conn.description_dialect,
"comment_dialect": conn.comment_dialect,
}

# Add board_id if set
Expand Down
8 changes: 6 additions & 2 deletions budjira/models/ai_prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -924,13 +924,17 @@ def get_default_ai_prompt_template() -> AiPromptTemplate:
**Options:**
- `--editor`, `-e`: Open editor for multi-line comment
- `--attach FILE`: Attach file(s) to the issue and reference them in the comment (repeatable; images are embedded via `!file!` wiki markup, other files linked via `[^file]`)
- `--embed FILE`: Embed image file(s) inline in the comment body (repeatable; Jira Cloud only — posts the comment as ADF via REST API v3 so the image renders inside the body)
- `--embed FILE`: Embed image file(s) inline in the comment body (repeatable; Jira Cloud only — posts the comment as ADF via REST API v3 so the image renders inside the body; no dialect applies)
- `--dialect {markdown,wiki}`: Dialect the comment is written in (overrides the connection's `comment_dialect` for this call)
- `--connection NAME`, `-c`: Use specific connection

**Behavior:**
- If TEXT is omitted, editor opens automatically (unless `--attach`/`--embed` files carry the comment)
- If TEXT is provided with `--editor`, editor opens with TEXT as initial content
- Supports markdown formatting
- The connection's `comment_dialect` decides the treatment: `wiki` (the default)
sends the text unchanged — the historical behaviour; `markdown` converts to
wiki markup first. Descriptions follow the separate `description_dialect`
(default `markdown`) — the two fields are configured independently.
- Comments are posted immediately without time tracking

**Examples:**
Expand Down
7 changes: 7 additions & 0 deletions budjira/models/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ class Connection(BaseModel):
"upload, 'wiki' sends the text unchanged"
),
)
comment_dialect: DescriptionDialect = Field(
default="wiki",
description=(
"Dialect comments are authored in: 'wiki' sends the text unchanged (the historical "
"default), 'markdown' converts to Jira wiki markup on upload"
),
)
custom_fields: dict[str, CustomFieldConfig] = Field(
default_factory=dict,
description="Custom field configurations mapped by friendly name",
Expand Down
22 changes: 16 additions & 6 deletions budjira/services/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
from jira.exceptions import JIRAError

from budjira.services.base import BaseJiraService
from budjira.utils.description import render_description
from budjira.utils.errors import InvalidIssueError, JiraAPIError, PermissionError

if TYPE_CHECKING:
from jira.resources import Comment

from budjira.models.connection import DescriptionDialect


class CommentService(BaseJiraService):
"""Service for managing Jira issue comments."""

def add(self, issue_key: str, body: str) -> dict[str, Any]:
def add(self, issue_key: str, body: str, dialect: DescriptionDialect = "wiki") -> dict[str, Any]:
"""Add a comment to an issue.

Args:
issue_key: Issue key (e.g., PROJ-123)
body: Comment text (can be markdown or plain text)
body: Comment text, authored in the given dialect
dialect: ``wiki`` sends the text unchanged (the historical
behaviour), ``markdown`` converts to wiki markup first

Returns:
Dictionary with comment details (id, author, body, created)
Expand All @@ -33,7 +38,7 @@ def add(self, issue_key: str, body: str) -> dict[str, Any]:
"""
try:
self._log_operation("Add comment", issue_key=issue_key)
comment = self.client.add_comment(issue_key, body)
comment = self.client.add_comment(issue_key, render_description(body, dialect))

# Return comment details
return {
Expand Down Expand Up @@ -177,13 +182,18 @@ def get(self, issue_key: str, comment_id: str) -> dict[str, Any]:
except Exception as e:
raise JiraAPIError(f"Unexpected error fetching comment '{comment_id}' on '{issue_key}': {e}") from e

def update(self, issue_key: str, comment_id: str, body: str) -> dict[str, Any]:
def update(
self, issue_key: str, comment_id: str, body: str, dialect: DescriptionDialect = "wiki"
) -> dict[str, Any]:
"""Replace the body of an existing comment.

Args:
issue_key: Issue key (e.g., PROJ-123)
comment_id: Comment ID
body: New comment text (replaces the existing body)
body: New comment text (replaces the existing body), authored in
the given dialect
dialect: ``wiki`` sends the text unchanged (the historical
behaviour), ``markdown`` converts to wiki markup first

Returns:
Dictionary with updated comment details (id, author, body, created, updated)
Expand All @@ -196,7 +206,7 @@ def update(self, issue_key: str, comment_id: str, body: str) -> dict[str, Any]:
try:
self._log_operation("Update comment", issue_key=issue_key, comment_id=comment_id)
comment = self.client.comment(issue_key, comment_id)
comment.update(body=body)
comment.update(body=render_description(body, dialect))
return self._to_dict(comment)
except JIRAError as e:
if e.status_code == 404:
Expand Down
35 changes: 32 additions & 3 deletions budjira/utils/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@

The dialect therefore belongs to the instance, not to the converter. This
module holds the two decisions in one place each: which dialect applies
(:func:`resolve_description_dialect`) and what that means for the payload
(:func:`render_description`). The service layer only passes the resolved
dialect through - it never decides whether to convert.
(:func:`resolve_description_dialect` for descriptions,
:func:`resolve_comment_dialect` for comments) and what that means for the
payload (:func:`render_description`). The service layer only passes the
resolved dialect through - it never decides whether to convert.

Descriptions and comments have independent connection settings on purpose:
descriptions historically went through the converter (default ``markdown``),
comments were posted raw (default ``wiki``). An instance whose authors write
one dialect for both can now express that; an instance that differs per field
keeps the asymmetry configurable rather than reversed.
"""

from __future__ import annotations
Expand Down Expand Up @@ -56,6 +63,28 @@ def resolve_description_dialect(
return connection.description_dialect


def resolve_comment_dialect(
override: DescriptionDialectOption | None,
connection: Connection,
) -> DescriptionDialect:
"""Resolve the dialect for a single comment write.

Same priority as :func:`resolve_description_dialect` (CLI override, then
connection setting), but the connection default is ``wiki`` - the
historical raw behaviour for comments.

Args:
override: Value of a ``--dialect`` option on a comment command, if given.
connection: The connection the write goes to.

Returns:
The dialect to hand to the service layer.
"""
if override is not None:
return override.value
return connection.comment_dialect


def render_description(text: str, dialect: DescriptionDialect) -> str:
"""Render a description for upload according to its dialect.

Expand Down
Loading
Loading