beads/cmd/bd/priority.go
Julian Knutsen eb872d33cf
Preflight graph apply blocking cycles (#4384)
* fix: preflight graph apply blocking cycles

* fix: maintainer review fixes for adopted graph-apply cycle PR

Keep dep/link dependency targets read-only: resolveIDForMutation is used
only for the mutated source issue, while the depends-on/link target is
resolved via read-only resolveIDWithRouting so resolving a routed target
never opens a foreign project writable or runs open-time migrations into
its history (bd-6dnrw.32, GH#3231).

Make the embedded graph-apply blocking-cycle preflight mirror the storage
SQL cycle check: its existing-edge walk is restricted to blocking dep
types, so a blocking edge whose return path runs only through an existing
parent-child or waits-for dep is no longer rejected when bd dep add allows
it. The parent->child blocking-path validator keeps the broader
AffectsReadyWork traversal.

Port the blocking-cycle preflight to the domain/proxied-server graph-apply
path and drop the now-redundant per-edge HasCycle probe so embedded and
server modes agree. Remove the dead graphApplyPlanCanSkipSQLCycleChecks
helpers left by the strategy change.

Restore the bulk --no-cycle-check whole-graph rollback test and add routed
read-only-target, parent-child parity, and domain external-ID cycle tests.

---------

Co-authored-by: Eddie the Engineer <ci@beads.test>
2026-06-19 21:31:59 -07:00

98 lines
2.3 KiB
Go

package main
import (
"fmt"
"github.com/spf13/cobra"
"github.com/steveyegge/beads/internal/ui"
"github.com/steveyegge/beads/internal/validation"
)
var priorityCmd = &cobra.Command{
Use: "priority <id> <n>",
GroupID: "issues",
Short: "Set the priority of an issue",
Long: `Set the priority of an issue.
Shorthand for 'bd update <id> --priority <n>'.
Priority levels:
0 - Critical (security, data loss, broken builds)
1 - High (major features, important bugs)
2 - Medium (default)
3 - Low (polish, optimization)
4 - Backlog (future ideas)
Examples:
bd priority bd-123 0 # Critical
bd priority bd-123 2 # Medium`,
Args: cobra.ExactArgs(2),
Run: func(cmd *cobra.Command, args []string) {
CheckReadonly("priority")
id := args[0]
priorityStr := args[1]
priority, err := validation.ValidatePriority(priorityStr)
if err != nil {
FatalErrorRespectJSON("%v", err)
}
ctx := rootCtx
result, err := resolveAndGetIssueForMutation(ctx, store, id)
if err != nil {
if result != nil {
result.Close()
}
FatalErrorRespectJSON("resolving %s: %v", id, err)
}
if result == nil || result.Issue == nil {
if result != nil {
result.Close()
}
FatalErrorRespectJSON("issue %s not found", id)
}
defer result.Close()
issueStore := result.Store
if err := validateIssueUpdatable(id, result.Issue); err != nil {
FatalErrorRespectJSON("%s", err)
}
updates := map[string]interface{}{
"priority": priority,
}
if err := issueStore.UpdateIssue(ctx, result.ResolvedID, updates, actor); err != nil {
FatalErrorRespectJSON("updating %s: %v", id, err)
}
if err := commitPendingIfEmbedded(ctx, issueStore, actor, doltAutoCommitParams{
Command: "priority",
IssueIDs: []string{result.ResolvedID},
}); err != nil {
FatalErrorRespectJSON("failed to commit: %v", err)
}
SetLastTouchedID(result.ResolvedID)
// Re-fetch for display
updatedIssue, _ := issueStore.GetIssue(ctx, result.ResolvedID)
title := ""
if updatedIssue != nil {
title = updatedIssue.Title
}
if jsonOutput {
if updatedIssue != nil {
outputJSON(updatedIssue)
}
} else {
fmt.Printf("%s Set priority of %s to P%d\n", ui.RenderPass("✓"), formatFeedbackID(result.ResolvedID, title), priority)
}
},
}
func init() {
priorityCmd.ValidArgsFunction = issueIDCompletion
rootCmd.AddCommand(priorityCmd)
}