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
4 changes: 4 additions & 0 deletions docs/azdo_boards_work-item.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ Work with Azure Boards work items.

* [azdo boards work-item delete](./azdo_boards_work-item_delete.md)
* [azdo boards work-item list](./azdo_boards_work-item_list.md)
* [azdo boards work-item update](./azdo_boards_work-item_update.md)

### Examples

```bash
# List work items in a project
azdo boards work-item list Fabrikam

# Update a work item's title
azdo boards work-item update Fabrikam/42 --title "New title"

# Delete a work item
azdo boards work-item delete Fabrikam/42 --yes
```
Expand Down
115 changes: 115 additions & 0 deletions docs/azdo_boards_work-item_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
## Command `azdo boards work-item update`

```
azdo boards work-item update [ORG:]PROJECT/ID [flags]
```

Update one or more fields of an existing work item. The work item is
identified by ID. Build a JSON Patch document from the supplied flags
and send it to the server. At least one field flag is required.


### Options


* `--area` `string`

New area path of the work item.

* `--assigned-to` `string`

Identity the work item is assigned to.

* `--bypass-rules`

Do not enforce the work item type rules on this update.

* `--description` `string`

New description (Markdown). Lower priority than --description-file and --description-editor.

* `--description-editor`

Edit description in $VISUAL/$EDITOR. Highest priority description source.

* `--description-file` `strings`

Read description from file (repeatable; "-" reads from stdin). Higher priority than --description.

* `--discussion` `string`

Comment to add to the work item discussion.

* `--expand` `string`

Expand parameters: None, Relations, Fields, Links, All.

* `--fields` `strings`

Set a field by reference name (repeatable; Ref.Name=value).

* `--iteration` `string`

New iteration path of the work item.

* `-q`, `--jq` `expression`

Filter JSON output using a jq expression

* `--json` `fields`

Output JSON with the specified fields. Prefix a field with '-' to exclude it.

* `--open`

Open the updated work item in the default browser.

* `--reason` `string`

Reason for the change of state.

* `--state` `string`

New state of the work item.

* `--suppress-notifications`

Do not fire any notifications for this change.

* `-t`, `--template` `string`

Format JSON output using a Go template; see "azdo help formatting"

* `--title` `string`

New title of the work item.

* `--validate-only`

Only validate the changes without saving the work item.


### ALIASES

- `u`

### JSON Fields

`_links`, `commentVersionRef`, `fields`, `id`, `relations`, `rev`, `url`

### Examples

```bash
# update a work item's title
azdo boards work-item update Fabrikam/1234 --title "New title"

# update description from a Markdown file
azdo boards work-item update Fabrikam/1234 --description-file ./updated-repro.md

# edit description in $EDITOR
azdo boards work-item update Fabrikam/1234 --description-editor
```

### See also

* [azdo boards work-item](./azdo_boards_work-item.md)
32 changes: 32 additions & 0 deletions docs/azdo_help_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,38 @@ Aliases
ls, l
```

#### `azdo boards work-item update [ORG:]PROJECT/ID [flags]`

Update a work item.

```
--area string New area path of the work item.
--assigned-to string Identity the work item is assigned to.
--bypass-rules Do not enforce the work item type rules on this update.
--description string New description (Markdown). Lower priority than --description-file and --description-editor.
--description-editor Edit description in $VISUAL/$EDITOR. Highest priority description source.
--description-file strings Read description from file (repeatable; "-" reads from stdin). Higher priority than --description.
--discussion string Comment to add to the work item discussion.
--expand string Expand parameters: None, Relations, Fields, Links, All.
--fields strings Set a field by reference name (repeatable; Ref.Name=value).
--iteration string New iteration path of the work item.
-q, --jq expression Filter JSON output using a jq expression
--json fields[=*] Output JSON with the specified fields. Prefix a field with '-' to exclude it.
--open Open the updated work item in the default browser.
--reason string Reason for the change of state.
--state string New state of the work item.
--suppress-notifications Do not fire any notifications for this change.
-t, --template string Format JSON output using a Go template; see "azdo help formatting"
--title string New title of the work item.
--validate-only Only validate the changes without saving the work item.
```

Aliases

```
u
```

## `azdo co`

Alias for "pr checkout"
Expand Down
53 changes: 7 additions & 46 deletions internal/cmd/boards/workitem/list/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"go.uber.org/zap"

"github.com/tmeckel/azdo-cli/internal/azdo/extensions"
"github.com/tmeckel/azdo-cli/internal/cmd/boards/workitem/shared"
"github.com/tmeckel/azdo-cli/internal/cmd/util"
"github.com/tmeckel/azdo-cli/internal/types"
)
Expand Down Expand Up @@ -268,12 +269,12 @@ func renderWorkItemsTable(ctx util.CmdContext, workItems []workitemtracking.Work
for _, wi := range workItems {
fields := types.GetValue(wi.Fields, map[string]any{})
tp.AddField(strconv.Itoa(types.GetValue(wi.Id, 0)))
tp.AddField(fieldString(fields, "System.WorkItemType"))
tp.AddField(fieldString(fields, "System.State"))
tp.AddField(fieldString(fields, "System.Title"))
tp.AddField(fieldIdentityDisplay(fields, "System.AssignedTo"))
tp.AddField(fieldString(fields, "System.AreaPath"))
tp.AddField(fieldString(fields, "System.IterationPath"))
tp.AddField(shared.FieldString(fields, "System.WorkItemType"))
tp.AddField(shared.FieldString(fields, "System.State"))
tp.AddField(shared.FieldString(fields, "System.Title"))
tp.AddField(shared.FieldIdentityDisplay(fields, "System.AssignedTo"))
tp.AddField(shared.FieldString(fields, "System.AreaPath"))
tp.AddField(shared.FieldString(fields, "System.IterationPath"))
tp.EndRow()
}

Expand Down Expand Up @@ -999,43 +1000,3 @@ func orderWorkItemsByIDs(items []workitemtracking.WorkItem, ids []int) []workite

return ordered
}

func fieldString(fields map[string]any, key string) string {
if fields == nil {
return ""
}
v, ok := fields[key]
if !ok || v == nil {
return ""
}
switch t := v.(type) {
case string:
return t
default:
return fmt.Sprint(v)
}
}

func fieldIdentityDisplay(fields map[string]any, key string) string {
if fields == nil {
return ""
}
v, ok := fields[key]
if !ok || v == nil {
return ""
}
switch t := v.(type) {
case string:
return t
case map[string]any:
if displayName, ok := t["displayName"].(string); ok {
return displayName
}
if uniqueName, ok := t["uniqueName"].(string); ok {
return uniqueName
}
return fmt.Sprint(v)
default:
return fmt.Sprint(v)
}
}
19 changes: 10 additions & 9 deletions internal/cmd/boards/workitem/list/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/mock/gomock"

"github.com/tmeckel/azdo-cli/internal/cmd/boards/workitem/shared"
"github.com/tmeckel/azdo-cli/internal/cmd/util"
"github.com/tmeckel/azdo-cli/internal/iostreams"
"github.com/tmeckel/azdo-cli/internal/mocks"
Expand Down Expand Up @@ -611,10 +612,10 @@ func TestFieldString(t *testing.T) {
"a": "hello",
"b": 42,
}
assert.Equal(t, "hello", fieldString(fields, "a"))
assert.Equal(t, "42", fieldString(fields, "b"))
assert.Equal(t, "", fieldString(fields, "missing"))
assert.Equal(t, "", fieldString(nil, "a"))
assert.Equal(t, "hello", shared.FieldString(fields, "a"))
assert.Equal(t, "42", shared.FieldString(fields, "b"))
assert.Equal(t, "", shared.FieldString(fields, "missing"))
assert.Equal(t, "", shared.FieldString(nil, "a"))
}

func TestFieldIdentityDisplay(t *testing.T) {
Expand All @@ -625,11 +626,11 @@ func TestFieldIdentityDisplay(t *testing.T) {
"b": map[string]any{"displayName": "Bob", "uniqueName": "bob@x.com"},
"c": map[string]any{"uniqueName": "carol@x.com"},
}
assert.Equal(t, "Alice", fieldIdentityDisplay(fields, "a"))
assert.Equal(t, "Bob", fieldIdentityDisplay(fields, "b"))
assert.Equal(t, "carol@x.com", fieldIdentityDisplay(fields, "c"))
assert.Equal(t, "", fieldIdentityDisplay(fields, "missing"))
assert.Equal(t, "", fieldIdentityDisplay(nil, "a"))
assert.Equal(t, "Alice", shared.FieldIdentityDisplay(fields, "a"))
assert.Equal(t, "Bob", shared.FieldIdentityDisplay(fields, "b"))
assert.Equal(t, "carol@x.com", shared.FieldIdentityDisplay(fields, "c"))
assert.Equal(t, "", shared.FieldIdentityDisplay(fields, "missing"))
assert.Equal(t, "", shared.FieldIdentityDisplay(nil, "a"))
}

func TestIdentityAccountOrDisplay(t *testing.T) {
Expand Down
Loading
Loading