feat: Add label operations to bd update command
Implements bd-au0.2, completing all P0 tasks in the command standardization epic. Changes: - Add --add-label, --remove-label, --set-labels flags to bd update - Support multiple labels via repeatable flags - Implement in both daemon and direct modes - Add comprehensive tests for all label operations The bd update command now supports: bd update <id> --add-label <label> # Add one or more labels bd update <id> --remove-label <label> # Remove one or more labels bd update <id> --set-labels <labels> # Replace all labels 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -248,6 +248,71 @@ func TestCLI_Update(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestCLI_UpdateLabels(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping slow CLI test in short mode")
|
||||
}
|
||||
// Note: Not using t.Parallel() because inProcessMutex serializes execution anyway
|
||||
tmpDir := setupCLITestDB(t)
|
||||
out := runBDInProcess(t, tmpDir, "create", "Issue for label testing", "-p", "2", "--json")
|
||||
|
||||
var issue map[string]interface{}
|
||||
json.Unmarshal([]byte(out), &issue)
|
||||
id := issue["id"].(string)
|
||||
|
||||
// Test adding labels
|
||||
runBDInProcess(t, tmpDir, "update", id, "--add-label", "feature", "--add-label", "backend")
|
||||
|
||||
out = runBDInProcess(t, tmpDir, "show", id, "--json")
|
||||
var updated []map[string]interface{}
|
||||
json.Unmarshal([]byte(out), &updated)
|
||||
labels := updated[0]["labels"].([]interface{})
|
||||
if len(labels) != 2 {
|
||||
t.Errorf("Expected 2 labels after add, got: %d", len(labels))
|
||||
}
|
||||
hasBackend, hasFeature := false, false
|
||||
for _, l := range labels {
|
||||
if l.(string) == "backend" {
|
||||
hasBackend = true
|
||||
}
|
||||
if l.(string) == "feature" {
|
||||
hasFeature = true
|
||||
}
|
||||
}
|
||||
if !hasBackend || !hasFeature {
|
||||
t.Errorf("Expected labels 'backend' and 'feature', got: %v", labels)
|
||||
}
|
||||
|
||||
// Test removing a label
|
||||
runBDInProcess(t, tmpDir, "update", id, "--remove-label", "backend")
|
||||
|
||||
out = runBDInProcess(t, tmpDir, "show", id, "--json")
|
||||
json.Unmarshal([]byte(out), &updated)
|
||||
labels = updated[0]["labels"].([]interface{})
|
||||
if len(labels) != 1 {
|
||||
t.Errorf("Expected 1 label after remove, got: %d", len(labels))
|
||||
}
|
||||
if labels[0].(string) != "feature" {
|
||||
t.Errorf("Expected label 'feature', got: %v", labels[0])
|
||||
}
|
||||
|
||||
// Test setting labels (replaces all)
|
||||
runBDInProcess(t, tmpDir, "update", id, "--set-labels", "api,database,critical")
|
||||
|
||||
out = runBDInProcess(t, tmpDir, "show", id, "--json")
|
||||
json.Unmarshal([]byte(out), &updated)
|
||||
labels = updated[0]["labels"].([]interface{})
|
||||
if len(labels) != 3 {
|
||||
t.Errorf("Expected 3 labels after set, got: %d", len(labels))
|
||||
}
|
||||
expectedLabels := map[string]bool{"api": true, "database": true, "critical": true}
|
||||
for _, l := range labels {
|
||||
if !expectedLabels[l.(string)] {
|
||||
t.Errorf("Unexpected label: %v", l)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCLI_Close(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("skipping slow CLI test in short mode")
|
||||
|
||||
@@ -393,6 +393,18 @@ var updateCmd = &cobra.Command{
|
||||
externalRef, _ := cmd.Flags().GetString("external-ref")
|
||||
updates["external_ref"] = externalRef
|
||||
}
|
||||
if cmd.Flags().Changed("add-label") {
|
||||
addLabels, _ := cmd.Flags().GetStringSlice("add-label")
|
||||
updates["add_labels"] = addLabels
|
||||
}
|
||||
if cmd.Flags().Changed("remove-label") {
|
||||
removeLabels, _ := cmd.Flags().GetStringSlice("remove-label")
|
||||
updates["remove_labels"] = removeLabels
|
||||
}
|
||||
if cmd.Flags().Changed("set-labels") {
|
||||
setLabels, _ := cmd.Flags().GetStringSlice("set-labels")
|
||||
updates["set_labels"] = setLabels
|
||||
}
|
||||
|
||||
if len(updates) == 0 {
|
||||
fmt.Println("No updates specified")
|
||||
@@ -461,6 +473,15 @@ var updateCmd = &cobra.Command{
|
||||
if externalRef, ok := updates["external_ref"].(string); ok { // NEW: Map external_ref
|
||||
updateArgs.ExternalRef = &externalRef
|
||||
}
|
||||
if addLabels, ok := updates["add_labels"].([]string); ok {
|
||||
updateArgs.AddLabels = addLabels
|
||||
}
|
||||
if removeLabels, ok := updates["remove_labels"].([]string); ok {
|
||||
updateArgs.RemoveLabels = removeLabels
|
||||
}
|
||||
if setLabels, ok := updates["set_labels"].([]string); ok {
|
||||
updateArgs.SetLabels = setLabels
|
||||
}
|
||||
|
||||
resp, err := daemonClient.Update(updateArgs)
|
||||
if err != nil {
|
||||
@@ -488,9 +509,63 @@ var updateCmd = &cobra.Command{
|
||||
// Direct mode
|
||||
updatedIssues := []*types.Issue{}
|
||||
for _, id := range resolvedIDs {
|
||||
if err := store.UpdateIssue(ctx, id, updates, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error updating %s: %v\n", id, err)
|
||||
continue
|
||||
// Apply regular field updates if any
|
||||
regularUpdates := make(map[string]interface{})
|
||||
for k, v := range updates {
|
||||
if k != "add_labels" && k != "remove_labels" && k != "set_labels" {
|
||||
regularUpdates[k] = v
|
||||
}
|
||||
}
|
||||
if len(regularUpdates) > 0 {
|
||||
if err := store.UpdateIssue(ctx, id, regularUpdates, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error updating %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
// Handle label operations
|
||||
// Set labels (replaces all existing labels)
|
||||
if setLabels, ok := updates["set_labels"].([]string); ok && len(setLabels) > 0 {
|
||||
// Get current labels
|
||||
currentLabels, err := store.GetLabels(ctx, id)
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error getting labels for %s: %v\n", id, err)
|
||||
continue
|
||||
}
|
||||
// Remove all current labels
|
||||
for _, label := range currentLabels {
|
||||
if err := store.RemoveLabel(ctx, id, label, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error removing label %s from %s: %v\n", label, id, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
// Add new labels
|
||||
for _, label := range setLabels {
|
||||
if err := store.AddLabel(ctx, id, label, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error setting label %s on %s: %v\n", label, id, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add labels
|
||||
if addLabels, ok := updates["add_labels"].([]string); ok {
|
||||
for _, label := range addLabels {
|
||||
if err := store.AddLabel(ctx, id, label, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error adding label %s to %s: %v\n", label, id, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove labels
|
||||
if removeLabels, ok := updates["remove_labels"].([]string); ok {
|
||||
for _, label := range removeLabels {
|
||||
if err := store.RemoveLabel(ctx, id, label, actor); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error removing label %s from %s: %v\n", label, id, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if jsonOutput {
|
||||
@@ -822,6 +897,9 @@ func init() {
|
||||
updateCmd.Flags().String("notes", "", "Additional notes")
|
||||
updateCmd.Flags().String("acceptance-criteria", "", "DEPRECATED: use --acceptance")
|
||||
_ = updateCmd.Flags().MarkHidden("acceptance-criteria")
|
||||
updateCmd.Flags().StringSlice("add-label", nil, "Add labels (repeatable)")
|
||||
updateCmd.Flags().StringSlice("remove-label", nil, "Remove labels (repeatable)")
|
||||
updateCmd.Flags().StringSlice("set-labels", nil, "Set labels, replacing all existing (repeatable)")
|
||||
|
||||
updateCmd.Flags().Bool("json", false, "Output JSON format")
|
||||
rootCmd.AddCommand(updateCmd)
|
||||
|
||||
Reference in New Issue
Block a user