* fix(http): bd link over a connected HTTP workspace, through the DependencyEditor role bd link wrote through the store's raw AddDependencyWithOptions, which the HTTP client refuses by design (D8), so every bd link failed on an HTTP workspace whatever the type. Its direct route now writes through the DependencyEditor role with the helper bd dep add uses (addDependencyEdgesDirect), which serves local stores and HTTP workspaces alike: over HTTP one dependencies:add request, and the server already takes any 1-32 character type. link keeps its own checks before the write (and before the dial): the dotted-child rule and the type's length only, never bd dep add's well-known-type list. The proxied-server route is unchanged. backend/http TestE2E_LinkOverHTTP covers owned-by and the other roadmap types, the empty and over-long type refusals (no write reaches the server), and the typed conflict for an edge of another type. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * build(bazel): auto-sync BUILD files Applied from the bazel-sync-patch artifact of https://github.com/gastownhall/beads/actions/runs/39201892756 (`make bazel-sync`: gazelle, tools/bazel/go_srcs.py, bazel mod tidy). Only BUILD.bazel, MODULE.bazel and MODULE.bazel.lock are ever pushed; see scripts/bazel-autofix-push.sh. --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
129 lines
4.2 KiB
Go
129 lines
4.2 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/internal/metrics"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
"github.com/steveyegge/beads/internal/ui"
|
|
"github.com/steveyegge/beads/issueops"
|
|
)
|
|
|
|
var linkCmd = &cobra.Command{
|
|
Use: "link <id1> <id2>",
|
|
GroupID: "issues",
|
|
Short: "Link two issues with a dependency",
|
|
Long: `Link two issues with a dependency.
|
|
|
|
Shorthand for 'bd dep add <id1> <id2>'. By default creates a "blocks"
|
|
dependency (id2 blocks id1). Use --type to specify a different relationship.
|
|
|
|
Examples:
|
|
bd link bd-123 bd-456 # bd-456 blocks bd-123
|
|
bd link bd-123 bd-456 --type related # bd-123 related to bd-456
|
|
bd link bd-123 bd-456 --type parent-child`,
|
|
Args: cobra.ExactArgs(2),
|
|
SilenceUsage: true,
|
|
SilenceErrors: true,
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
CheckReadonly("link")
|
|
|
|
evt := metrics.NewCommandEvent("link")
|
|
defer func() {
|
|
if c := metrics.Global(); c != nil {
|
|
c.CloseEventAndAdd(evt)
|
|
}
|
|
}()
|
|
|
|
if usesProxiedServer() {
|
|
return runLinkProxiedServer(cmd, rootCtx, args)
|
|
}
|
|
|
|
id1 := args[0]
|
|
id2 := args[1]
|
|
depType, _ := cmd.Flags().GetString("type")
|
|
|
|
ctx := rootCtx
|
|
|
|
// Resolve partial IDs with routing support. The source issue's store
|
|
// is mutated by AddDependency below, so resolve it write-intent
|
|
// (#4141); the dependency target is only resolved by ID and stays
|
|
// read-only (bd-6dnrw.32, GH#3231).
|
|
fromID, fromStore, fromCleanup, err := resolveIDForMutation(ctx, store, id1)
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
defer fromCleanup()
|
|
|
|
toID, _, toCleanup, err := resolveIDWithRouting(ctx, store, id2)
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
defer toCleanup()
|
|
|
|
dt := types.DependencyType(depType)
|
|
// link's own checks run before anything is written, and over http
|
|
// before the dial: the dotted-child rule (the role raises it too) and
|
|
// the type's length. Unlike `bd dep add`, link takes any type a
|
|
// workspace spells, so it never asks validateDependencyType.
|
|
if err := issueops.CheckDottedChildDependency(fromID, toID, dt); err != nil {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
|
|
if !dt.IsValid() {
|
|
return HandleErrorRespectJSON("invalid dependency type %q: must be non-empty and at most %d characters", depType, types.MaxDependencyTypeLen)
|
|
}
|
|
|
|
opsCtx, err := issueOpsContext(ctx)
|
|
if err != nil {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
// Read the titles while the resolution's reads are fresh, as `bd dep
|
|
// add` does: an edge changes neither title, and over http a lookup
|
|
// after the write would be two more round trips.
|
|
var fromTitle, toTitle string
|
|
if !jsonOutput {
|
|
fromTitle, toTitle = lookupTitle(fromID), lookupTitle(toID)
|
|
}
|
|
|
|
// The write goes through the DependencyEditor role, the route `bd dep
|
|
// add` takes, so it is served on every backend: a local store and an
|
|
// http workspace alike (the http client refuses the raw
|
|
// AddDependencyWithOptions by design). The role records the
|
|
// dependency_added event the raw verb's EmitEvent did.
|
|
edge := issueops.DependencyEdge{IssueID: fromID, DependsOnID: toID, Type: dt}
|
|
if err := addDependencyEdgesDirect(opsCtx, fromStore, []issueops.DependencyEdge{edge}, false); err != nil {
|
|
return HandleErrorRespectJSON("%v", err)
|
|
}
|
|
|
|
warnIfCyclesExist(fromStore)
|
|
|
|
if err := commitPendingIfEmbedded(ctx, fromStore, currentActor(), doltAutoCommitParams{
|
|
Command: "link",
|
|
IssueIDs: []string{fromID, toID},
|
|
}); err != nil {
|
|
return HandleErrorRespectJSON("failed to commit: %v", err)
|
|
}
|
|
|
|
SetLastTouchedID(fromID)
|
|
|
|
if jsonOutput {
|
|
return outputJSON(map[string]interface{}{
|
|
"status": "added",
|
|
"issue_id": fromID,
|
|
"depends_on_id": toID,
|
|
"type": depType,
|
|
})
|
|
}
|
|
fmt.Printf("%s Linked: %s depends on %s (%s)\n",
|
|
ui.RenderPass("✓"), formatFeedbackIDParen(fromID, fromTitle), formatFeedbackIDParen(toID, toTitle), depType)
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func init() {
|
|
linkCmd.Flags().StringP("type", "t", "blocks", "Dependency type (blocks|tracks|related|parent-child|discovered-from)")
|
|
linkCmd.ValidArgsFunction = issueIDCompletion
|
|
rootCmd.AddCommand(linkCmd)
|
|
}
|