Skip to content

Conversation

@isaacpalomero
Copy link

Add Worklog Management Commands (list, edit, delete)

Overview

This PR adds comprehensive worklog management capabilities to jira-cli by implementing three new commands: list, edit, and delete. These commands complete the CRUD operations for worklog management, complementing the existing add command.

Summary of Changes

New Commands

1. jira issue worklog list - List worklogs for an issue

  • Display all worklogs in table or plain text format
  • Support for --plain and --table output modes
  • Alias: ls

2. jira issue worklog edit - Edit existing worklogs

  • Update time spent, comment, and start date
  • Interactive worklog selection from list
  • Timezone support for date adjustments
  • Alias: update

3. jira issue worklog delete - Remove worklogs

  • Safety confirmation prompt before deletion
  • --force flag to skip confirmation (for scripts)
  • Interactive worklog selection
  • Aliases: remove, rm

🔧 Technical Implementation

API Endpoints Used

Command HTTP Method Endpoint Status Code
list GET /rest/api/2/issue/{key}/worklog 200 OK
edit PUT /rest/api/2/issue/{key}/worklog/{id} 200 OK
delete DELETE /rest/api/2/issue/{key}/worklog/{id} 204 No Content

Files Added

internal/cmd/issue/worklog/list/list.go
internal/cmd/issue/worklog/edit/edit.go
internal/cmd/issue/worklog/delete/delete.go
internal/view/worklog.go
internal/view/worklog_test.go

Files Modified

pkg/jira/issue.go
internal/cmd/issue/worklog/worklog.go
README.md

Features

Worklog List

  • Table format (default): Compact view with ID, Author, Started, Time Spent, Created
  • Plain format: Detailed view with all worklog information including comments
  • Flexible output: Easily parseable for scripts and automation
  • ADF Support: Handles both plain text and Atlassian Document Format comments

Worklog Edit

  • Full editing: Update time spent, comment, and start date
  • Interactive mode: Select worklog from a list if ID not provided
  • Timezone support: Specify timezone for start dates (default: UTC)
  • Markdown support: Comments support markdown formatting

Worklog Delete

  • Safety first: Confirmation prompt before deletion (prevents accidents)
  • Force mode: --force flag for non-interactive scripts
  • Interactive selection: Choose worklog from list if ID not provided
  • Clear feedback: Success/error messages with issue URL

Usage Examples

List Worklogs

# Table format (default)
$ jira issue worklog list ISSUE-123
ID      AUTHOR          STARTED              TIME SPENT  CREATED
10001   John Doe        2024-11-05 10:30    2h 30m      2024-11-05 10:30
10002   Jane Smith      2024-11-05 14:00    1h 15m      2024-11-05 14:00

# Detailed plain format
$ jira issue worklog list ISSUE-123 --plain
Worklog #1
  ID:          10001
  Author:      John Doe
  Started:     2024-11-05 10:30
  Time Spent:  2h 30m (9000 seconds)
  Created:     2024-11-05 10:30
  Updated:     2024-11-05 10:30
  Comment:     Working on feature implementation

Total worklogs: 2

# Using alias
$ jira issue worklog ls ISSUE-123

Edit Worklogs

# Interactive mode (select from list)
$ jira issue worklog edit ISSUE-123

# Edit specific worklog
$ jira issue worklog edit ISSUE-123 10001 "3h 30m" --no-input

# Edit with comment and start date
$ jira issue worklog edit ISSUE-123 10001 "2h" \
  --comment "Updated work description" \
  --started "2024-11-05 09:30:00" \
  --timezone "Europe/Madrid"

# Using alias
$ jira issue worklog update ISSUE-123 10001 "4h"

Delete Worklogs

# With confirmation (safe)
$ jira issue worklog delete ISSUE-123 10001
? Are you sure you want to delete worklog 10001 from issue ISSUE-123? Yes
✓ Worklog deleted from issue "ISSUE-123"

# Force mode (no confirmation)
$ jira issue worklog delete ISSUE-123 10001 --force

# Interactive selection
$ jira issue worklog delete ISSUE-123

# Using aliases
$ jira issue worklog remove ISSUE-123 10001
$ jira issue worklog rm ISSUE-123 10001 -f

Complete Worklog Workflow

# 1. Add a worklog
$ jira issue worklog add ISSUE-123 "2h" --comment "Initial work"

# 2. List all worklogs to find the ID
$ jira issue worklog list ISSUE-123

# 3. Edit if needed
$ jira issue worklog edit ISSUE-123 10001 "2h 30m"

# 4. Delete if incorrect
$ jira issue worklog delete ISSUE-123 10001

Testing

  • All existing tests pass
  • New unit tests added for worklog view (8 tests)
  • Compilation successful without errors
  • Commands tested with Docker
  • Help text verified for all commands
  • Interactive modes tested
  • Error handling validated

Security Considerations

Delete Command Safety

  • Default confirmation: Prevents accidental deletions
  • Clear warning message: Shows what will be deleted
  • Force flag: Documented with caution warnings
  • Irreversible action: Clearly communicated to users

Permissions

All commands respect Jira permissions:

  • Users can only manage worklogs they have permission to access
  • Proper error messages for permission issues
  • Supports both Jira Cloud and Server permission models

Breaking Changes

None. All changes are additive and backward compatible.

Migration Guide

Not applicable. These are new commands with no migration needed.

Screenshots

Worklog List - Table Format

ID      AUTHOR          STARTED              TIME SPENT  CREATED
10001   John Doe        2024-11-05 10:30    2h 30m      2024-11-05 10:30
10002   Jane Smith      2024-11-05 14:00    1h 15m      2024-11-05 14:00

Worklog List - Plain Format

Worklog #1
  ID:          10001
  Author:      John Doe
  Started:     2024-11-05 10:30
  Time Spent:  2h 30m (9000 seconds)
  Created:     2024-11-05 10:30
  Updated:     2024-11-05 10:30
  Comment:     Working on feature implementation

Total worklogs: 2

Interactive Worklog Selection

? Select worklog to edit:
  > 10001 - 2h 30m by John Doe (2024-11-05T10:30:00.000+0000)
    10002 - 1h 15m by Jane Smith (2024-11-05T14:00:00.000+0000)

Delete Confirmation

? Are you sure you want to delete worklog 10001 from issue ISSUE-123?
  > Yes
    No

Author: Isaac Palomero
Date: 2024-11-05
Branch: feature/worklog-list-and-edit-commands
Status: Ready for Review

isaacpalomero and others added 11 commits November 5, 2025 14:05
- Add 'jira issue worklog list' command to list worklogs for an issue
- Implement GetIssueWorklogs() method in jira client
- Add Worklog and WorklogResponse types
- Create worklog view with plain and table display modes
- Add comprehensive unit tests for worklog functionality
- Support both ADF and plain text comment formats
- Include documentation for the new feature
- Add analysis document for Jira API requests
…-command

* feature/worklog-list-command:
  feat: add worklog list command
- Add 'jira issue worklog edit' command to edit existing worklogs
- Implement UpdateIssueWorklog() method in jira client
- Support interactive worklog selection from list
- Add flags for comment, started date, and timezone
- Include comprehensive documentation
- Update analysis document with new endpoint
- Add documentation for 'worklog list' command
- Add documentation for 'worklog edit' command
- Include usage examples and aliases for both commands
- Add 'jira issue worklog delete' command to remove worklogs
- Implement DeleteIssueWorklog() method in jira client
- Support interactive worklog selection from list
- Add confirmation prompt with --force flag to skip
- Include aliases: remove, rm
- Update README with delete command documentation
- Add error checks for fmt.Fprintf and fmt.Fprintln calls
- Pre-allocate slice capacity in worklog data() method
- Fix formatting issues (gofmt)
- Remove extra whitespace
- Align struct field tabs properly
- Add error checks for fmt.Fprintf and fmt.Fprintln calls
- Pre-allocate slice capacity in worklog data() method
- Fix formatting issues (gofmt)
- Remove extra whitespace
- Align struct field tabs properly
- Rename delete() to deleteWorklog() to avoid shadowing builtin
- Resolves RVV-B0009: Redefinition of builtin
- No functional changes, just naming improvement
- Add error check for fmt.Sscanf in delete and edit commands
- Fix line continuation formatting in delete confirmation message
- Replace magic number 60 with maxCommentLength constant
- All golangci-lint issues resolved
- Modify AddIssueWorklog to return *Worklog instead of error only
- Display worklog ID in success message after creation
- Update README.md with example showing returned ID
- Update tests to handle new return signature
- Mock response now includes worklog JSON
Copilot AI review requested due to automatic review settings November 11, 2025 16:07
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds comprehensive CRUD operations for worklog management by implementing three new commands: list, edit, and delete. These commands complement the existing add command and provide complete worklog lifecycle management through both interactive and non-interactive modes.

Key Changes:

  • Added GetIssueWorklogs, UpdateIssueWorklog, and DeleteIssueWorklog API methods
  • Implemented three new commands with interactive worklog selection
  • Modified AddIssueWorklog to return the created worklog object
  • Added worklog view layer with table and plain text formatting
  • Added comprehensive test coverage for worklog view functions

Reviewed Changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/jira/issue.go Added three new API methods for worklog CRUD operations and modified AddIssueWorklog to return worklog object
pkg/jira/issue_test.go Updated test to verify AddIssueWorklog returns worklog object
internal/cmd/issue/worklog/worklog.go Registered new list, edit, and delete commands
internal/cmd/issue/worklog/list/list.go Implemented worklog list command with table/plain output formats
internal/cmd/issue/worklog/edit/edit.go Implemented worklog edit command with interactive selection
internal/cmd/issue/worklog/delete/delete.go Implemented worklog delete command with confirmation prompt
internal/cmd/issue/worklog/add/add.go Updated to display returned worklog ID in success message
internal/view/worklog.go Added worklog view layer with rendering logic
internal/view/worklog_test.go Added comprehensive unit tests for worklog view functions
README.md Updated documentation with usage examples for new commands

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@isaacpalomero
Copy link
Author

cc @ankitpokhrel

ichoosetoaccept pushed a commit to ichoosetoaccept/jira-cli that referenced this pull request Nov 28, 2025
Cherry-picked from upstream PR ankitpokhrel#908 by isaacpalomero.
Adds full CRUD support for worklogs:
- jira issue worklog list ISSUE-KEY
- jira issue worklog edit ISSUE-KEY WORKLOG-ID TIME
- jira issue worklog delete ISSUE-KEY WORKLOG-ID
@vvpalomero
Copy link

@martinpovolny @chmouel ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants