fix(jtk): accumulate repeated --field flags for multi-value fields#186
fix(jtk): accumulate repeated --field flags for multi-value fields#186
Conversation
When the same field key is passed multiple times via --field, values are
now merged into an array instead of overwriting. This fixes multi-checkbox
and multi-select fields where multiple values need to be set:
jtk issues update PROJ-123 \
--field "customfield_10154=CheckSync" \
--field "customfield_10154=MoniCore"
Applies to both issues update and issues create.
Closes #166
monit-reviewer
left a comment
There was a problem hiding this comment.
Automated PR Review
Reviewed commit: 0b24c0a
Approved with 2 non-blocking suggestions below. Address at your discretion.
Summary
| Reviewer | Findings |
|---|---|
| harness-engineering:knowledge-reviewer | 1 |
| security:code-auditor | 1 |
harness-engineering:knowledge-reviewer (1 findings)
💡 Suggestion - tools/jtk/api/fields.go:138
MergeFieldValues handles
[]map[string]stringand[]stringbut any other slice type (or cross-type mismatch like[]map[string]stringexisting +[]stringnew) silently falls through to replacement. In practice this can't happen becauseFormatFieldValueis deterministic for a given field, but a brief comment listing the two supported array types and noting the fallthrough contract would help future maintainers understand the design choice.
security:code-auditor (1 findings)
💡 Suggestion - tools/jtk/api/fields_test.go:500
The tests cover single-merge cases well, but the real usage pattern is 3+
--fieldflags for the same key (as shown in the PR example). Adding a test that chains multipleMergeFieldValuescalls (e.g., accumulate three option values) would exercise the append-to-already-appended path and match the motivating use case.
Completed in 5m 50s | $0.78
| Field | Value |
|---|---|
| Reviewers | hybrid-synthesis, database:sql-reviewer, security:code-auditor, harness-engineering:knowledge-reviewer, harness-engineering:enforcement-reviewer, harness-engineering:architecture-reviewer, harness-engineering:legibility-reviewer |
| Reviewed by | pr-review-daemon · monit-pr-reviewer |
| Duration | 5m 50s (Reviewers: 1m 35s · Synthesis: 1m 11s) |
| Cost | $0.78 |
| Tokens | 289.8k in / 31.5k out |
| Turns | 36 |
| // MergeFieldValues merges a new formatted field value into an existing one. | ||
| // For array fields (e.g., multi-checkbox, labels), this appends to the existing | ||
| // array. For non-array fields, the new value replaces the existing one. | ||
| func MergeFieldValues(existing, newVal any) any { |
There was a problem hiding this comment.
🔵 Low (harness-engineering:knowledge-reviewer): MergeFieldValues handles []map[string]string and []string but any other slice type (or cross-type mismatch like []map[string]string existing + []string new) silently falls through to replacement. In practice this can't happen because FormatFieldValue is deterministic for a given field, but a brief comment listing the two supported array types and noting the fallthrough contract would help future maintainers understand the design choice.
| }) | ||
| } | ||
|
|
||
| func TestMergeFieldValues(t *testing.T) { |
There was a problem hiding this comment.
🔵 Low (security:code-auditor): The tests cover single-merge cases well, but the real usage pattern is 3+ --field flags for the same key (as shown in the PR example). Adding a test that chains multiple MergeFieldValues calls (e.g., accumulate three option values) would exercise the append-to-already-appended path and match the motivating use case.
|
Addressed the 3+ values test case in 718b048. The comment about supported array types is fair but the function is 20 lines and self-documenting — adding a comment would be noise. |
TDD Assessment — PR #186What's covered well
Missing test cases for
|
Catches up documentation for recent features and fixes: - README: document --fields flag, auto-pagination, fields command group, users get subcommand, --assignee none, multi-value --field, and escape sequences in comment --body - CHANGELOG: add entries for PRs #178, #180, #182, #186-189 - integration-tests: add test cases for auto-pagination, --fields, users get, --assignee none, multi-value --field, and escape sequences Closes #183
#190) Catches up documentation for recent features and fixes: - README: document --fields flag, auto-pagination, fields command group, users get subcommand, --assignee none, multi-value --field, and escape sequences in comment --body - CHANGELOG: add entries for PRs #178, #180, #182, #186-189 - integration-tests: add test cases for auto-pagination, --fields, users get, --assignee none, multi-value --field, and escape sequences Closes #183
Summary
--fieldflags with the same key now merge values into an array instead of overwritingMergeFieldValues()function that handles option arrays ([]map[string]string) and string arrays ([]string)issues updateandissues createcommandsCloses #166
Example
Test plan
MergeFieldValues(option arrays, string arrays, non-array overwrite, type mismatch)make buildpassesmake testpasses--fieldflags