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: 9 additions & 1 deletion .claude/ai-usage-prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,9 @@ budjira create issue "Issue summary" --no-interactive [OPTIONS]
- `--epic KEY`: Link to epic during creation
- `--parent KEY`: Parent issue key for sub-tasks (required when the type is a sub-task)
- `--custom NAME=VALUE`: Set custom field (repeatable, requires configuration)
- `--dry-run`: Print the exact fields payload and the converted description
without creating anything (no API call; use this to verify the customer
format before the irreversible write)

**Sub-tasks:** Use `--parent PROJ-123` to create a sub-task under a parent issue.
The sub-task type name varies per instance (often `Subtask`, sometimes `Sub-task`);
Expand Down Expand Up @@ -532,7 +535,9 @@ Update existing issues with status transitions, field changes, and label managem
- `--remove-label TAG`: Remove label (repeatable)
- `--epic EPIC-KEY`, `-e`: Link issue to epic
- `--field KEY=VALUE`: Transition screen field, by field id or display name (repeatable, requires `--status`)
- `--dry-run`: Show the transition and its fields without performing it
- `--dry-run`: Show what would be sent without doing it — the transition and its
screen fields, and for field updates the exact fields payload with the
description after conversion (no API write)
- `--interactive/--no-interactive`, `-i/-n`: Prompt for missing required fields (default: interactive)

**Examples:**
Expand Down Expand Up @@ -569,6 +574,9 @@ budjira issue update PROJ-123 \
--add-label urgent \
--add-label backend \
--add-label security

# Preview the exact payload without applying it (no API write)
budjira issue update PROJ-123 --priority High --description "Text" --dry-run
```

### Transition Screen Fields
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,22 @@ budjira connect add --name work --url https://work.atlassian.net \
budjira comment add PROJ-123 "## Notes" --dialect markdown
```

**Dry run — verify the exact payload before the irreversible write:**

`--dry-run` on `create issue` and `issue update` prints the resolved `fields`
payload and the description *after* dialect conversion — the exact string that
would be sent — and performs no API write. On instances where issues cannot be
deleted and API-posted comments cannot be edited, this is the way to check the
customer format first.

```bash
# Preview creation (fields + converted description), no API call
budjira create issue "Fix login bug" --type Bug --description "## Notes" --dry-run --no-interactive

# Preview an update the same way
budjira issue update PROJ-123 --priority High --description "## Notes" --dry-run
```

**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
90 changes: 85 additions & 5 deletions budjira/cli/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

from __future__ import annotations

import json
from typing import TYPE_CHECKING, Any

import typer
from rich.console import Console
from rich.panel import Panel
from rich.prompt import Confirm, Prompt
from rich.syntax import Syntax
from rich.table import Table

from budjira.config.metadata_cache import MetadataCache
from budjira.config.settings import get_settings
from budjira.core.jira_client import JiraClient
from budjira.models.issue import IssueType, Priority
from budjira.services.issues import build_create_fields
from budjira.utils.connection import get_active_connection
from budjira.utils.description import DescriptionDialectOption, resolve_description_dialect
from budjira.utils.dor_validator import format_validation_result, validate_description
Expand All @@ -21,7 +25,7 @@

if TYPE_CHECKING:
from budjira.config.settings import Settings
from budjira.models.connection import Connection
from budjira.models.connection import Connection, DescriptionDialect
from budjira.models.custom_field import CustomFieldConfig
from budjira.models.issue import Issue
from budjira.models.project_metadata import ProjectMetadata
Expand Down Expand Up @@ -625,6 +629,55 @@ def _display_created_issue(
console.print(f"\n[dim]View in Jira: {issue_url}[/dim]")


def _display_create_dry_run(
project_key: str,
issue_type: str,
summary: str,
description: str | None,
dialect: DescriptionDialect,
extra_fields: dict[str, Any],
priority: str | None,
assignee: str | None,
labels: list[str],
epic: str | None,
) -> None:
"""Show the exact create payload without touching the API.

Args:
project_key: Target project key
issue_type: Resolved issue type
summary: Issue summary
description: Raw description as authored (None if not set)
dialect: Resolved description dialect
extra_fields: Timetracking, parent and custom field payloads
priority: Priority if given
assignee: Assignee if given
labels: Labels if given
epic: Epic key the issue would be linked to after creation
"""
fields = build_create_fields(
project_key,
summary,
issue_type,
description,
priority,
assignee,
labels,
dialect,
extra_fields,
)
console.print(f"\n[cyan]Dry run:[/cyan] would create {issue_type} in project {project_key} — no API call made")
console.print("[cyan]fields payload:[/cyan]")
console.print(Syntax(json.dumps(fields, indent=2, ensure_ascii=False), "json", word_wrap=True))
if description:
console.print(
f"[cyan]Description after conversion (dialect: {dialect}) — the exact string that would be sent:[/cyan]"
)
console.print(Panel(fields["description"], expand=False))
if epic:
console.print(f"[dim]Would then link the new issue to epic {epic}[/dim]")


@app.command()
def issue(
summary: str | None = typer.Argument(None, help="Issue summary/title"),
Expand Down Expand Up @@ -712,6 +765,11 @@ def issue(
"--custom",
help="Custom field value as name=value (can be specified multiple times)",
),
dry_run: bool = typer.Option(
False,
"--dry-run",
help="Show the exact fields payload and converted description without creating anything",
),
) -> None:
"""Create a new Jira issue.

Expand Down Expand Up @@ -751,6 +809,9 @@ def issue(

# Multiple custom fields
budjira create issue "New feature" --type Story --custom env=Production --custom component=API

# Preview the exact payload (fields + converted description) without creating
budjira create issue "Fix login bug" --type Bug --dry-run --no-interactive
"""
try:
# Setup
Expand Down Expand Up @@ -784,9 +845,9 @@ def issue(
_validate_parent(parent, issue_type, project_metadata)
_validate_dor(description, issue_type, skip_dor, settings, interactive)

# Create issue
client = JiraClient.from_connection(active_connection)
console.print(f"\n[dim]Creating {issue_type} in project {project_key}...[/dim]")
# Resolve the payload pieces before any client exists, so a dry run
# never constructs one
resolved_dialect = resolve_description_dialect(description_dialect, active_connection)

extra_fields = _prepare_time_tracking(original_estimate, remaining_estimate)

Expand All @@ -798,6 +859,25 @@ def issue(
custom_api_fields = _format_custom_fields_for_api(custom_values, custom_field_configs)
extra_fields.update(custom_api_fields)

if dry_run:
_display_create_dry_run(
project_key,
issue_type,
summary,
description,
resolved_dialect,
extra_fields,
priority,
assignee,
labels,
epic,
)
return

# Create issue
client = JiraClient.from_connection(active_connection)
console.print(f"\n[dim]Creating {issue_type} in project {project_key}...[/dim]")

created_issue = client.create_issue(
project_key=project_key,
summary=summary,
Expand All @@ -806,7 +886,7 @@ def issue(
priority=priority,
assignee=assignee,
labels=labels,
description_dialect=resolve_description_dialect(description_dialect, active_connection),
description_dialect=resolved_dialect,
**extra_fields,
)

Expand Down
124 changes: 118 additions & 6 deletions budjira/cli/issue.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""CLI commands for updating Jira issues."""

import json
import sys
from typing import Annotated, Any

import typer
from rich.console import Console
from rich.panel import Panel
from rich.syntax import Syntax
from rich.table import Table

from budjira.core.jira_client import JiraClient
from budjira.models.transition import Transition
from budjira.services.issues import CURRENT_USER_PLACEHOLDER, build_update_fields
from budjira.utils.connection import get_active_connection
from budjira.utils.description import DescriptionDialectOption, resolve_description_dialect
from budjira.utils.errors import BudjiraError, InvalidIssueError, PermissionError
Expand Down Expand Up @@ -227,6 +231,89 @@ def _execute_transition(
client.transitions.transition(issue_key, matched.name, fields=resolved)


def _display_update_dry_run(
issue_key: str,
conn: Any,
*,
assignee: str | None,
priority: str | None,
summary: str | None,
description: str | None,
description_dialect: DescriptionDialectOption | None,
add_label: list[str] | None,
remove_label: list[str] | None,
epic: str | None,
original_estimate: str | None,
remaining_estimate: str | None,
log_work: str | None,
work_comment: str | None,
) -> None:
"""Show the exact update payload(s) without touching the API.

Prints the ``fields`` dict the update call would send (with the
description already converted) plus one line per non-fields operation
(labels, epic link, worklog).

Args:
issue_key: Issue that would be updated
conn: Active connection (resolves the description dialect)
assignee: Assignee option value
priority: Priority option value
summary: Summary option value
description: Description option value (raw, as authored)
description_dialect: Dialect override option value
add_label: Labels that would be added
remove_label: Labels that would be removed
epic: Epic the issue would be linked to
original_estimate: Original estimate option value
remaining_estimate: Remaining estimate option value
log_work: Work time that would be logged
work_comment: Worklog comment
"""
if any([assignee is not None, priority, summary, description]):
update_fields = build_update_fields(
assignee=assignee,
priority=priority,
summary=summary,
description=description,
description_dialect=resolve_description_dialect(description_dialect, conn),
)
console.print(f"[cyan]Dry run:[/cyan] would update {issue_key} — no API call made")
console.print("[cyan]fields payload:[/cyan]")
console.print(Syntax(json.dumps(update_fields, indent=2, ensure_ascii=False), "json", word_wrap=True))
if assignee is not None and assignee.lower() == "currentuser()":
console.print(
f"[dim]{CURRENT_USER_PLACEHOLDER} is resolved to an account id via a read call when the update is applied[/dim]"
)
if description:
dialect = resolve_description_dialect(description_dialect, conn)
console.print(
f"[cyan]Description after conversion (dialect: {dialect}) — the exact string that would be sent:[/cyan]"
)
console.print(Panel(update_fields["description"], expand=False))

if add_label:
console.print(f"[dim]Would add labels: {', '.join(add_label)}[/dim]")
if remove_label:
console.print(f"[dim]Would remove labels: {', '.join(remove_label)}[/dim]")
if epic:
console.print(f"[dim]Would link to epic {epic}[/dim]")
if original_estimate or remaining_estimate:
timetracking: dict[str, str] = {}
if original_estimate:
timetracking["originalEstimate"] = original_estimate
if remaining_estimate:
timetracking["remainingEstimate"] = remaining_estimate
console.print("[cyan]timetracking fields payload:[/cyan]")
console.print(
Syntax(json.dumps({"timetracking": timetracking}, indent=2, ensure_ascii=False), "json", word_wrap=True)
)
if log_work:
console.print(f"[dim]Would log work: {log_work}[/dim]")
if work_comment:
console.print(f"[dim] Worklog comment: {work_comment}[/dim]")


@app.command("update")
def update_issue(
issue_key: Annotated[str, typer.Argument(help="Issue key (e.g., PROJ-123)")],
Expand All @@ -236,7 +323,11 @@ def update_issue(
typer.Option("--field", help="Transition screen field as key=value (repeatable)"),
] = None,
dry_run: Annotated[
bool, typer.Option("--dry-run", help="Show the transition and its fields without performing it")
bool,
typer.Option(
"--dry-run",
help="Show what would be sent (transition, fields payload, converted description) without doing it",
),
] = False,
interactive: Annotated[
bool, typer.Option("--interactive/--no-interactive", "-i/-n", help="Prompt for missing required fields")
Expand Down Expand Up @@ -296,6 +387,9 @@ def update_issue(
--status Done \\
--priority Low \\
--add-label completed

# Preview the exact payload (fields + converted description) without applying
budjira issue update PROJ-123 --priority High --description "Text" --dry-run
"""
try:
# Validate work_comment requires log_work
Expand Down Expand Up @@ -353,15 +447,33 @@ def update_issue(
if still_missing:
console.print("[yellow]Missing required fields:[/yellow]")
console.print(format_field_requirements(still_missing))
return

_execute_transition(client, issue_key, matched, resolved, interactive)

changes.append(("Status", f"→ {status}"))
else:
_execute_transition(client, issue_key, matched, resolved, interactive)
changes.append(("Status", f"→ {status}"))
except BudjiraError as e:
console.print(f"[red]✗[/red] Status update failed: {e}")
raise typer.Exit(1) from e

# A dry run stops here: preview every remaining update, apply nothing
if dry_run:
_display_update_dry_run(
issue_key,
conn,
assignee=assignee,
priority=priority,
summary=summary,
description=description,
description_dialect=description_dialect,
add_label=add_label,
remove_label=remove_label,
epic=epic,
original_estimate=original_estimate,
remaining_estimate=remaining_estimate,
log_work=log_work,
work_comment=work_comment,
)
return

# Perform field updates
try:
# Update basic fields
Expand Down
Loading
Loading