Skip to content

[#74415] Add JSON work package workflows#12

Open
myabc wants to merge 9 commits intomainfrom
implementation/74316-cli-workpackage-workflows
Open

[#74415] Add JSON work package workflows#12
myabc wants to merge 9 commits intomainfrom
implementation/74316-cli-workpackage-workflows

Conversation

@myabc
Copy link
Copy Markdown
Contributor

@myabc myabc commented Apr 24, 2026

Ticket

https://community.openproject.org/wp/74415
https://community.openproject.org/wp/74416
https://community.openproject.org/wp/74418

What are you trying to accomplish?

Tip

Related SKILL.md can be found here

Add the first agent-oriented slice of Work Package workflows to op so scripted and agentic consumers don't have to scrape human output:

  • op inspect workpackage <id> --children --json — parent, direct children, project info, custom fields, and label→API field mappings
  • op create workpackage --parent <id> [--dry-run] --json — parent-aware create that infers the project from the parent
  • op create workpackage --description "Body" ... — explicit raw description support on create, including dry-run JSON coverage
  • op update workpackage <id> --set "Field=Value" [--dry-run] --json — schema-driven updates for custom fields that accept human labels or raw API names (e.g. customField130)
  • op update workpackage <id> --description "Body" [--dry-run] --json — explicit raw description support on the core patch path
  • op update workpackage <id> --status "In development" [--dry-run] --json — status updates validated in both dry-run and live PATCH flows
  • Formattable custom fields now mirror description on read surfaces: JSON outputs expose the raw string rather than the full rendered object
  • Structured JSON errors for ambiguous fields and invalid flag combinations (e.g. --open --json)
  • README examples for the new workflows

Out of scope: recursive descendants, semantic WP identifiers, search, bulk creation, MCP layer.

What approach did you choose and why?

Kept the existing Cobra verbs and text printer intact and added a parallel JSON path built from richer DTOs, a schema-aware field resolver, and a stable JSON presenter. Command handlers stay thin; new logic lives in focused resource/model/presenter helpers with httptest-backed unit tests.

JSON update paths avoid progress-text contamination for machine consumers, while non-JSON update paths still emit human-readable progress/status output.

Validated against the live community instance: read WP#74316 and child WP#74413, created validation child WP#74414, updated a safe field on WP#74414, backfilled raw descriptions on WP#74414, WP#74415, and WP#74416, and then used the branch CLI against real work packages where follow-up fixes surfaced:

  • Formattable custom fields now PATCH as long-text {raw: ...} values instead of plain strings.
  • --status now works on update workpackage and validates against known statuses in both dry-run and live flows.
  • Formattable custom fields now read back as raw strings in Work Package JSON outputs, mirroring description.

What this PR doesn't do

Deferred items:

  • Core field writes through --set beyond the explicit --description flag; this slice keeps --set scoped to schema-resolved custom fields
  • Richer structured API error payloads beyond {code, message}
  • Project identifier fallback when _embedded.project is absent
  • Richer assignee JSON such as {id, name}
  • Unifying create and update dry-run payloads under a single mutation-plan envelope
  • Collision-aware inspect output for ambiguous field_labels
  • Cleaning up --action --json and --attach --json progress output in legacy resource paths

Merge checklist

  • Added/updated tests

Copilot AI review requested due to automatic review settings April 24, 2026 17:53
Copy link
Copy Markdown

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 expands the CLI’s work package workflows by adding machine-readable JSON output, dry-run planning, and schema-driven custom field resolution for create/inspect/update operations.

Changes:

  • Add new JSON-serializable models for inspect payloads and mutation “plans” (create/update).
  • Extend work package DTO parsing to capture custom fields, parent/schema links, and embedded project identifier.
  • Implement schema fetching + label/type-based resolution for --set updates, plus new CLI flags for --json, --dry-run, --set, --parent, and --children.

Reviewed changes

Copilot reviewed 27 out of 27 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
models/work_package_mutation.go Adds model types for create/update “plan” JSON output.
models/work_package_details.go Adds inspect payload models (details, children, project ref, error payload).
models/project.go Extends Project model with Identifier.
dtos/work_package_test.go Tests custom field + links + embedded project unmarshalling.
dtos/work_package_schema.go Adds schema DTO that extracts customField* entries.
dtos/work_package.go Adds custom-field capture via custom UnmarshalJSON; adds parent/schema links; makes conversion nil-safe.
dtos/project.go Adds identifier field to project DTO and conversion.
components/resources/work_packages/update_fields_test.go Tests dry-run update field label resolution via schema.
components/resources/work_packages/update_fields.go Implements dry-run update plan + PATCH update for resolved custom fields.
components/resources/work_packages/schema.go Fetches schema and exposes label→apiName mapping.
components/resources/work_packages/field_resolution_test.go Tests label-based resolution and ambiguous label rejection.
components/resources/work_packages/field_resolution.go Implements assignment parsing, schema resolution, and type coercion.
components/resources/work_packages/details_test.go Tests inspect payload includes children, fields, and labels.
components/resources/work_packages/details.go Implements inspect-with-children + payload construction.
components/resources/work_packages/create_test.go Tests dry-run create infers project from parent.
components/resources/work_packages/create.go Adds parent option, project inference, dry-run create plan, and type resolution refactor.
components/presenter/json_test.go Tests JSON output for inspect payload and error payloads.
components/presenter/json.go Adds simple JSON/error marshaling helpers.
cmd/update/work_package_test.go Tests update dry-run prints expected JSON plan.
cmd/update/work_package.go Adds --set, --json, --dry-run handling and JSON error formatting.
cmd/update/update.go Wires new update flags (--set, --json, --dry-run).
cmd/inspect/work_package_test.go Tests inspect JSON output (with children) and JSON error for flag conflicts.
cmd/inspect/work_package.go Adds --json and --children output mode + JSON errors.
cmd/inspect/inspect.go Wires inspect flags for JSON and children inclusion.
cmd/create/work_package_test.go Tests create dry-run JSON plan and JSON error for flag conflicts.
cmd/create/work_package.go Adds --json/--dry-run output, --parent, and JSON error formatting.
cmd/create/create.go Makes --project optional (project can be inferred from --parent); wires new flags.

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

Comment thread components/resources/work_packages/field_resolution.go
Comment thread components/resources/work_packages/update_fields.go
Comment thread components/resources/work_packages/create.go Outdated
Comment thread cmd/update/work_package.go
Comment thread cmd/create/work_package.go
@myabc myabc force-pushed the implementation/74316-cli-workpackage-workflows branch from a93f6f7 to 684cb21 Compare April 24, 2026 18:31
@myabc myabc requested a review from Copilot April 24, 2026 18:32
@myabc myabc changed the title Implementation/74316 cli workpackage workflows [#74415] Add JSON work package inspect/create/update Apr 24, 2026
@myabc myabc added go Pull requests that update go code enhancement New feature or request labels Apr 24, 2026
@myabc myabc requested review from Kharonus and akabiru April 24, 2026 18:36
Copy link
Copy Markdown

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

Copilot reviewed 28 out of 28 changed files in this pull request and generated 4 comments.


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

Comment thread dtos/work_package_schema.go
Comment thread components/resources/work_packages/schema.go Outdated
Comment thread components/resources/work_packages/field_resolution.go
Comment thread cmd/inspect/work_package.go Outdated
@myabc myabc force-pushed the implementation/74316-cli-workpackage-workflows branch 2 times, most recently from a6adc3e to a7ea4fa Compare April 24, 2026 19:00
@myabc myabc requested a review from Copilot April 24, 2026 19:02
Copy link
Copy Markdown

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

Copilot reviewed 31 out of 31 changed files in this pull request and generated 5 comments.


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

Comment thread cmd/inspect/work_package.go
Comment thread cmd/update/work_package.go
Comment thread cmd/update/work_package.go
Comment thread cmd/create/work_package.go Outdated
Comment thread components/resources/work_packages/create.go
@myabc myabc changed the title [#74415] Add JSON work package inspect/create/update [#74415][#74416] Add JSON work package workflows Apr 24, 2026
@myabc myabc requested a review from Copilot April 24, 2026 19:45
Copy link
Copy Markdown

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

Copilot reviewed 33 out of 33 changed files in this pull request and generated 6 comments.


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

Comment thread README.md Outdated
Comment thread cmd/update/work_package.go
Comment thread cmd/update/work_package.go Outdated
Comment thread cmd/create/work_package.go
Comment thread cmd/inspect/work_package.go
Comment thread components/resources/work_packages/update.go Outdated
Comment thread cmd/create/create.go Outdated
Comment thread cmd/create/create.go Outdated
myabc added 5 commits April 24, 2026 23:17
Implement the first agent-facing CLI slice for work package
inspection.

Add machine-readable JSON output, include direct children on
demand, preserve custom field data and schema labels, and
return structured JSON errors for the inspect command.

https://community.openproject.org/projects/cli/work_packages/74316
Add parent-aware create dry-runs and schema-driven update
dry-runs for work packages, both with machine-readable JSON
output.

Keep the legacy typed update flags intact while adding --set,
--parent, --dry-run, and --json as the agent workflow surface.

https://community.openproject.org/projects/cli/work_packages/74316
Add README examples for the new machine-readable Work Package
flows: inspect with children, parent-aware create dry-runs, and
schema-driven update dry-runs.

https://community.openproject.org/projects/cli/work_packages/74316
Add explicit `--description` support to create and update work package
commands.

This extends create and the core update patch path, includes JSON
dry-run coverage for descriptions, documents the new flag, and keeps
validation strict around unsupported flag combinations.

https://community.openproject.org/wp/74416
@myabc myabc force-pushed the implementation/74316-cli-workpackage-workflows branch from 0fe6675 to 87900d7 Compare April 24, 2026 21:21
@myabc myabc requested a review from Copilot April 24, 2026 21:21
Copy link
Copy Markdown

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

Copilot reviewed 34 out of 34 changed files in this pull request and generated 2 comments.


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

Comment thread components/resources/work_packages/update.go
Comment thread cmd/update/work_package.go
myabc added 4 commits April 24, 2026 23:34
Move the human-readable update summary into cmd/update so non-JSON
users still see which fields are about to change while the resource
layer stays silent for machine-oriented paths. Simplify patch helpers
to return only errors now that the resource layer no longer builds its
own summary.
Wrap Formattable custom-field values as raw long-text objects before
PATCHing so OpenProject preserves the content instead of clearing it.
Add regression coverage for both value coercion and the resulting HTTP
patch body.

https://community.openproject.org/wp/74415
Add a status flag on work package updates and validate it through the
same status lookup in both dry-run and live PATCH flows. Extend the
mutation plan and add regression coverage for status resolution and the
resulting PATCH link payload.

https://community.openproject.org/wp/74316
Normalize Formattable custom fields to their raw string values in
Work Package JSON reads so they mirror description and can be
round-tripped without parsing rendered objects.

https://community.openproject.org/wp/74418
Copy link
Copy Markdown

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

Copilot reviewed 35 out of 35 changed files in this pull request and generated 2 comments.


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

Comment thread cmd/update/work_package.go
Comment thread components/resources/work_packages/update.go
@cbliard
Copy link
Copy Markdown
Member

cbliard commented Apr 27, 2026

Sorry for coming late in the party.

I have a branch where I added some improvements a few weeks ago: (cbl-improvements branch):

  • use noun first commands + dasherize some names: op work-package create rather than op create workpackage
  • add whoami command to know as which user I'm logged as
  • add profiles to be able to get work packages from different instances, or create work packages as different users
  • add --assignee and --description to op work-package create
  • add op budget list and op budget create
  • add op time-entry create
  • add json output with --format json

Have you considered it?

I should have added a comment in the original wp posted by Kabiru. Will do that now.

@myabc myabc changed the title [#74415][#74416] Add JSON work package workflows [#74415] Add JSON work package workflows Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Development

Successfully merging this pull request may close these issues.

3 participants