ensureStatusOption ensures a status option exists in the project's Status field
(ctx context.Context, projectURL, optionName string, verbose bool)
| 566 | |
| 567 | // ensureStatusOption ensures a status option exists in the project's Status field |
| 568 | func ensureStatusOption(ctx context.Context, projectURL, optionName string, verbose bool) error { |
| 569 | projectLog.Printf("Ensuring Status option: %s", optionName) |
| 570 | console.LogVerbose(verbose, fmt.Sprintf("Adding '%s' status option...", optionName)) |
| 571 | |
| 572 | info, err := parseProjectURL(projectURL) |
| 573 | if err != nil { |
| 574 | return fmt.Errorf("failed to parse project URL: %w", err) |
| 575 | } |
| 576 | |
| 577 | // Get the Status field information |
| 578 | statusField, err := getStatusField(ctx, info, verbose) |
| 579 | if err != nil { |
| 580 | return fmt.Errorf("failed to get Status field: %w", err) |
| 581 | } |
| 582 | |
| 583 | // Check if the option already exists and is properly ordered |
| 584 | updatedOptions, changed := ensureSingleSelectOptionBefore( |
| 585 | statusField.options, |
| 586 | singleSelectOption{Name: optionName, Color: "BLUE", Description: "Needs review before moving to Done"}, |
| 587 | "Done", |
| 588 | ) |
| 589 | |
| 590 | if !changed { |
| 591 | console.LogVerbose(verbose, "Status option already present and ordered: "+optionName) |
| 592 | return nil |
| 593 | } |
| 594 | |
| 595 | // Update the field with new options |
| 596 | if err := updateSingleSelectFieldOptions(ctx, statusField.fieldID, updatedOptions, verbose); err != nil { |
| 597 | return fmt.Errorf("failed to update Status field: %w", err) |
| 598 | } |
| 599 | |
| 600 | console.LogVerbose(verbose, "Status option added before 'Done': "+optionName) |
| 601 | return nil |
| 602 | } |
| 603 | |
| 604 | // singleSelectOption represents a single-select field option |
| 605 | type singleSelectOption struct { |
no test coverage detected