* perf(git): locate the repository in-process instead of running git rev-parse Every bd invocation resolved the process-wide git context (beads directory discovery reads it) with `git rev-parse --git-dir --git-common-dir --show-toplevel`: one git subprocess per bd call before any work. Tools that call bd hundreds of times (gascity's doctor issues ~250 bd calls per run) paid it on every call. On Linux, initGitContext now first runs discoverGitInProcess, which mirrors Git's discovery walk (physical cwd, .git as directory or gitfile, bare-dir check, filesystem-boundary stop) and produces byte-for-byte what rev-parse prints for ordinary repositories (top and subdirectories), linked worktrees (absolute or relative gitfile, symlinked targets), submodules (core.worktree pointing back at the gitfile's directory), nested repositories and no repository. Both answers feed one shared normalization (gitContextFromRevParse), so downstream values are unchanged. It declines, and git runs exactly as before, whenever it cannot prove the answer: GIT_DIR / GIT_WORK_TREE / GIT_COMMON_DIR / GIT_CEILING_DIRECTORIES / GIT_DISCOVERY_ACROSS_FILESYSTEM / GIT_OBJECT_DIRECTORY / GIT_CONFIG_PARAMETERS / GIT_CONFIG_COUNT in the environment; a symlinked .git, an invalid gitfile or git directory, a cwd inside a git directory; repository config with core.worktree (other than the submodule shape), core.bare, extensions, include directives, a format version above 1 or unmodeled syntax; any path not owned by the effective uid (safe.directory is git's to evaluate), or root under sudo. darwin and windows keep the subprocess (case folding and ownership semantics). Tests compare discoverGitFrom with real `git rev-parse` output across those layouts, pin every decline case, and check the resulting cached context equals the subprocess-derived one. Agent-Signature: claude-code-claude-opus-5-5-medium on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * perf(cli): resolve the git user.name actor fallback only when needed PersistentPreRunE assigned `actor = getActorWithGit()` for every command, which, with no --actor / BEADS_ACTOR / BD_ACTOR / config actor, runs `git config user.name`: the second git subprocess of every bd call, paid by read-only commands that never consult the actor. The pre-run now calls deferActorGitFallback, which marks an empty actor as pending; currentActor (and getActorWithGit, getActor) resolve it on first use with the unchanged priority order and store it in the global and the CommandContext copy, as the eager assignment did. Command code reads the actor through currentActor() instead of the raw global (a mechanical rewrite of every read site the compiler reported; writes, the flag binding and the pre-run config binding keep the raw variable). setActor cancels a pending fallback. The telemetry span's bd.actor attribute is still set, but only for a recording span, so a noop span does not force the lookup. With the in-process repository discovery from the previous commit, a read-only `bd list` / `bd show` now starts no git process at startup, in the main checkout and in a linked worktree; a write asks git for user.name once (bd create previously asked once, now still once) and records the same value. Measured on 50 sequential `bd list` calls: 100 -> 0 git execs (embedded and proxied-server workspaces, main checkout and worktree). TestEmbeddedReadOnlyCommandsSpawnNoGit counts git execs through a PATH shim; TestDeferredActorGitFallback pins the deferral semantics. Agent-Signature: claude-code-claude-opus-5-5-medium on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * fix(git): decline in-process discovery on any config line git might read differently Review follow-ups to the in-process repository discovery. - The repository config scanner was looser than git: a config starting with a UTF-8 BOM followed by `[core] worktree = /other` made git report /other while discovery returned the cwd repository, and `[ core ]` or `!!! = x` (which git refuses) were accepted. scanGitConfig (gitconfig_linux.go) now skips a leading BOM exactly as git does and accepts only a narrow grammar: blank/comment lines, `[section]` / `[section "sub"]` headers at column 0, and `key` / `key = value` lines inside a section, with values free of backslashes and unbalanced quotes. Any other line declines to git. - Walk from getcwd(2) (syscall.Getwd), as git does, instead of os.Getwd, which trusts $PWD when it names the same inode (bind-mount aliases). - Resolve relative gitfile and commondir targets without filepath.Join's lexical Clean, so "link/.." resolves physically like git's realpath. - A mount-boundary stop reports its own reason in the not-a-repository error. - Tests: every decline case (BOM + core.worktree, malformed headers and keys, keys before a section, escapes, continuations, bare repositories, a commondir inside .git, ...) now also checks that what startup derives equals git's answer; BOM and CRLF/comment configs are equivalence cases; the no-repository case must be answered in-process instead of skipping; a $PWD alias test pins the getcwd walk. - The exec-count test drops every GIT_* variable except the config-file selectors, so a runner exporting GIT_CONFIG_PARAMETERS & co. cannot make it fail spuriously. - Comment the two places that touch the raw actor before the deferral. Agent-Signature: claude-code-claude-opus-5-5-medium on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> * perf(backup): decide embedded auto-backup's git-remote probe without git In an embedded workspace whose backup.enabled is unset, maybeAutoBackup asks isBackupAutoEnabled -> primeHasGitRemote after every command, reads included. That built a RepoContext (`git -C .beads rev-parse --git-common-dir`) and ran `git remote`: two git processes per read even after the startup calls were gone. The throttle cannot short-circuit it: without a remote no backup ever runs, so there is no backup state to throttle on. Both probes are now answered in-process when provable, and the subprocess remains the fallback, so the decision and every warning/notice downstream of it are unchanged: - internal/beads getGitCommonDirForPath uses git.CommonDirInProcess (the discovery walk from the given directory, git's spelling). - primeHasGitRemote uses git.HasRemoteInProcess in the same directory primeGitCmd would run git in (primeGitDir, factored out). It answers only when every config file `git remote` reads -- system (GIT_CONFIG_SYSTEM, or /etc/gitconfig and <prefix>/etc/gitconfig of the git on PATH), global (GIT_CONFIG_GLOBAL, or XDG and ~/.gitconfig) and the repository's own -- is absent or within scanGitConfig's grammar and include-free, no GIT_CONFIG_PARAMETERS/COUNT/GIT_CONFIG or discovery override is set, and no legacy .git/remotes or .git/branches entries exist. A remote seen only in a system-config candidate declines. Remote names outside [A-Za-z0-9._-] decline. Tests compare HasRemoteInProcess with `git remote` (no remote, local, worktree, submodule, remote.pushDefault only, global remote, no repo) and pin the declines (global include, malformed global, command-line config); CommonDirInProcess is compared with `git -C dir rev-parse --git-common-dir`. TestEmbeddedReadOnlyCommandsSpawnNoGit now runs with backup.enabled at its default, with and without a git remote, and still expects zero git processes for list/show. Agent-Signature: claude-code-claude-opus-5-5-medium on behalf of Julian Knutsen Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
452 lines
14 KiB
Go
452 lines
14 KiB
Go
package main
|
||
|
||
import (
|
||
"fmt"
|
||
"regexp"
|
||
"strings"
|
||
|
||
"github.com/spf13/cobra"
|
||
"github.com/steveyegge/beads/internal/metrics"
|
||
"github.com/steveyegge/beads/internal/types"
|
||
"github.com/steveyegge/beads/internal/ui"
|
||
)
|
||
|
||
var duplicatesCmd = &cobra.Command{
|
||
Use: "duplicates",
|
||
GroupID: "deps",
|
||
Short: "Find and optionally merge duplicate issues",
|
||
Long: `Find issues with identical content (title, description, design, acceptance criteria).
|
||
Groups issues by content hash and reports duplicates with suggested merge targets.
|
||
The merge target is chosen by:
|
||
1. Reference count (most referenced issue wins)
|
||
2. Lexicographically smallest ID if reference counts are equal
|
||
Only groups issues with matching status (open with open, closed with closed).
|
||
Example:
|
||
bd duplicates # Show all duplicate groups
|
||
bd duplicates --auto-merge # Automatically merge all duplicates
|
||
bd duplicates --dry-run # Show what would be merged`,
|
||
SilenceUsage: true,
|
||
SilenceErrors: true,
|
||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||
evt := metrics.NewCommandEvent("duplicates")
|
||
defer func() {
|
||
if c := metrics.Global(); c != nil {
|
||
c.CloseEventAndAdd(evt)
|
||
}
|
||
}()
|
||
|
||
autoMerge, _ := cmd.Flags().GetBool("auto-merge")
|
||
dryRun, _ := cmd.Flags().GetBool("dry-run")
|
||
|
||
if usesProxiedServer() {
|
||
return runDuplicatesProxiedServer(rootCtx, autoMerge, dryRun)
|
||
}
|
||
|
||
if autoMerge && !dryRun {
|
||
CheckReadonly("duplicates --auto-merge")
|
||
}
|
||
ctx := rootCtx
|
||
|
||
allIssues, err := store.SearchIssues(ctx, "", types.IssueFilter{})
|
||
if err != nil {
|
||
return HandleError("fetching issues: %v", err)
|
||
}
|
||
duplicateGroups := findDuplicateGroups(openIssuesOf(allIssues))
|
||
if len(duplicateGroups) == 0 {
|
||
return outputNoDuplicates()
|
||
}
|
||
refCounts := countReferences(allIssues)
|
||
depCounts, _ := store.GetDependencyCounts(ctx, collectDuplicateGroupIDs(duplicateGroups))
|
||
structuralScores := buildStructuralScores(duplicateGroups, depCounts)
|
||
|
||
var mergeResults []map[string]interface{}
|
||
if autoMerge && !dryRun {
|
||
mergeResults = executeDuplicateMerges(duplicateGroups, refCounts, structuralScores)
|
||
commandDidWrite.Store(true)
|
||
}
|
||
return outputDuplicates(duplicateGroups, refCounts, structuralScores, autoMerge, dryRun, mergeResults)
|
||
},
|
||
}
|
||
|
||
func openIssuesOf(allIssues []*types.Issue) []*types.Issue {
|
||
openIssues := make([]*types.Issue, 0, len(allIssues))
|
||
for _, issue := range allIssues {
|
||
if issue.Status != types.StatusClosed {
|
||
openIssues = append(openIssues, issue)
|
||
}
|
||
}
|
||
return openIssues
|
||
}
|
||
|
||
func collectDuplicateGroupIDs(groups [][]*types.Issue) []string {
|
||
var ids []string
|
||
for _, group := range groups {
|
||
for _, issue := range group {
|
||
ids = append(ids, issue.ID)
|
||
}
|
||
}
|
||
return ids
|
||
}
|
||
|
||
func outputNoDuplicates() error {
|
||
if !jsonOutput {
|
||
fmt.Println("No duplicates found!")
|
||
return nil
|
||
}
|
||
return outputJSON(map[string]interface{}{
|
||
"duplicate_groups": 0,
|
||
"groups": []interface{}{},
|
||
})
|
||
}
|
||
|
||
func executeDuplicateMerges(duplicateGroups [][]*types.Issue, refCounts map[string]int, structuralScores map[string]*issueScore) []map[string]interface{} {
|
||
var mergeResults []map[string]interface{}
|
||
for _, group := range duplicateGroups {
|
||
target := chooseMergeTarget(group, refCounts, structuralScores)
|
||
sources := make([]string, 0, len(group)-1)
|
||
for _, issue := range group {
|
||
if issue.ID != target.ID {
|
||
sources = append(sources, issue.ID)
|
||
}
|
||
}
|
||
mergeResults = append(mergeResults, performMerge(target.ID, sources))
|
||
}
|
||
return mergeResults
|
||
}
|
||
|
||
func outputDuplicates(duplicateGroups [][]*types.Issue, refCounts map[string]int, structuralScores map[string]*issueScore, autoMerge, dryRun bool, mergeResults []map[string]interface{}) error {
|
||
var mergeCommands []string
|
||
for _, group := range duplicateGroups {
|
||
target := chooseMergeTarget(group, refCounts, structuralScores)
|
||
sources := make([]string, 0, len(group)-1)
|
||
for _, issue := range group {
|
||
if issue.ID != target.ID {
|
||
sources = append(sources, issue.ID)
|
||
}
|
||
}
|
||
cmd := fmt.Sprintf("# Duplicate: %s (same content as %s)\n# Suggested action: bd close %s && bd dep add %s %s --type related",
|
||
strings.Join(sources, " "),
|
||
target.ID,
|
||
strings.Join(sources, " "),
|
||
strings.Join(sources, " "),
|
||
target.ID)
|
||
mergeCommands = append(mergeCommands, cmd)
|
||
}
|
||
|
||
if jsonOutput {
|
||
output := map[string]interface{}{
|
||
"duplicate_groups": len(duplicateGroups),
|
||
"groups": formatDuplicateGroupsJSON(duplicateGroups, refCounts, structuralScores),
|
||
}
|
||
if autoMerge || dryRun {
|
||
output["merge_commands"] = mergeCommands
|
||
if autoMerge && !dryRun {
|
||
output["merge_results"] = mergeResults
|
||
}
|
||
}
|
||
return outputJSON(output)
|
||
}
|
||
fmt.Printf("%s Found %d duplicate group(s):\n\n", ui.RenderWarn("🔍"), len(duplicateGroups))
|
||
for i, group := range duplicateGroups {
|
||
target := chooseMergeTarget(group, refCounts, structuralScores)
|
||
fmt.Printf("%s Group %d: %s\n", ui.RenderAccent("━━"), i+1, group[0].Title)
|
||
for _, issue := range group {
|
||
refs := refCounts[issue.ID]
|
||
weight := 0
|
||
if score, ok := structuralScores[issue.ID]; ok {
|
||
weight = score.dependentCount*3 + score.dependsOnCount
|
||
}
|
||
marker := " "
|
||
if issue.ID == target.ID {
|
||
marker = ui.RenderPass("→ ")
|
||
}
|
||
fmt.Printf("%s%s (%s, P%d, weight=%d, %d refs)\n",
|
||
marker, issue.ID, issue.Status, issue.Priority, weight, refs)
|
||
}
|
||
sources := make([]string, 0, len(group)-1)
|
||
for _, issue := range group {
|
||
if issue.ID != target.ID {
|
||
sources = append(sources, issue.ID)
|
||
}
|
||
}
|
||
fmt.Printf(" %s Duplicate: %s (same content as %s)\n", ui.RenderAccent("Note:"), strings.Join(sources, " "), target.ID)
|
||
fmt.Printf(" %s bd close %s && bd dep add %s %s --type related\n\n",
|
||
ui.RenderAccent("Suggested:"), strings.Join(sources, " "), strings.Join(sources, " "), target.ID)
|
||
}
|
||
if autoMerge {
|
||
if dryRun {
|
||
fmt.Printf("%s Dry run - would execute %d merge(s)\n", ui.RenderWarn("⚠"), len(mergeCommands))
|
||
} else {
|
||
fmt.Printf("%s Merged %d group(s)\n", ui.RenderPass("✓"), len(mergeCommands))
|
||
}
|
||
} else {
|
||
fmt.Printf("%s Run with --auto-merge to execute all suggested merges\n", ui.RenderAccent("💡"))
|
||
}
|
||
return nil
|
||
}
|
||
|
||
func init() {
|
||
duplicatesCmd.Flags().Bool("auto-merge", false, "Automatically merge all duplicates")
|
||
duplicatesCmd.Flags().Bool("dry-run", false, "Show what would be merged without making changes")
|
||
rootCmd.AddCommand(duplicatesCmd)
|
||
}
|
||
|
||
// contentKey represents the fields we use to identify duplicate issues
|
||
type contentKey struct {
|
||
title string
|
||
description string
|
||
design string
|
||
acceptanceCriteria string
|
||
status string // Only group issues with same status
|
||
}
|
||
|
||
// findDuplicateGroups groups issues by content hash
|
||
func findDuplicateGroups(issues []*types.Issue) [][]*types.Issue {
|
||
groups := make(map[contentKey][]*types.Issue)
|
||
for _, issue := range issues {
|
||
key := contentKey{
|
||
title: issue.Title,
|
||
description: issue.Description,
|
||
design: issue.Design,
|
||
acceptanceCriteria: issue.AcceptanceCriteria,
|
||
status: string(issue.Status),
|
||
}
|
||
groups[key] = append(groups[key], issue)
|
||
}
|
||
// Filter to only groups with duplicates
|
||
var duplicates [][]*types.Issue
|
||
for _, group := range groups {
|
||
if len(group) > 1 {
|
||
duplicates = append(duplicates, group)
|
||
}
|
||
}
|
||
return duplicates
|
||
}
|
||
|
||
// issueScore captures all factors used to choose which duplicate to keep
|
||
type issueScore struct {
|
||
dependentCount int // Issues that depend on this one (children, blocked-by) - highest priority
|
||
dependsOnCount int // Issues this one depends on
|
||
textRefs int // Text mentions in other issues' descriptions/notes
|
||
}
|
||
|
||
// countReferences counts how many times each issue is referenced in text fields
|
||
func countReferences(issues []*types.Issue) map[string]int {
|
||
counts := make(map[string]int)
|
||
idPattern := regexp.MustCompile(`\b[a-zA-Z][-a-zA-Z0-9]*-\d+\b`)
|
||
for _, issue := range issues {
|
||
// Search in all text fields
|
||
textFields := []string{
|
||
issue.Description,
|
||
issue.Design,
|
||
issue.AcceptanceCriteria,
|
||
issue.Notes,
|
||
}
|
||
for _, text := range textFields {
|
||
matches := idPattern.FindAllString(text, -1)
|
||
for _, match := range matches {
|
||
counts[match]++
|
||
}
|
||
}
|
||
}
|
||
return counts
|
||
}
|
||
|
||
func buildStructuralScores(groups [][]*types.Issue, depCounts map[string]*types.DependencyCounts) map[string]*issueScore {
|
||
scores := make(map[string]*issueScore)
|
||
for _, group := range groups {
|
||
for _, issue := range group {
|
||
scores[issue.ID] = &issueScore{}
|
||
}
|
||
}
|
||
|
||
for id, counts := range depCounts {
|
||
if score, ok := scores[id]; ok {
|
||
score.dependentCount = counts.DependentCount
|
||
score.dependsOnCount = counts.DependencyCount
|
||
}
|
||
}
|
||
|
||
return scores
|
||
}
|
||
|
||
// chooseMergeTarget selects the best issue to merge into
|
||
// Priority order:
|
||
// 1. Highest structural weight - most connected issue wins
|
||
// Dependents (children) are weighted 3× more than depends-on references
|
||
// because discarding an issue with children orphans them (catastrophic),
|
||
// while losing a depends-on link is recoverable.
|
||
// 2. Highest text reference count (mentions in descriptions/notes)
|
||
// 3. Lexicographically smallest ID (stable tiebreaker)
|
||
func chooseMergeTarget(group []*types.Issue, refCounts map[string]int, structuralScores map[string]*issueScore) *types.Issue {
|
||
if len(group) == 0 {
|
||
return nil
|
||
}
|
||
|
||
getScore := func(id string) (int, int) {
|
||
weight := 0
|
||
if score, ok := structuralScores[id]; ok {
|
||
// Dependents (children that would be orphaned) count 3× more than
|
||
// depends-on references (which survive closure as links).
|
||
weight = score.dependentCount*3 + score.dependsOnCount
|
||
}
|
||
textRefs := refCounts[id]
|
||
return weight, textRefs
|
||
}
|
||
|
||
target := group[0]
|
||
targetWeight, targetRefs := getScore(target.ID)
|
||
|
||
for _, issue := range group[1:] {
|
||
issueWeight, issueRefs := getScore(issue.ID)
|
||
|
||
// Compare by structural weight first (dependents + dependencies)
|
||
if issueWeight > targetWeight {
|
||
target = issue
|
||
targetWeight, targetRefs = issueWeight, issueRefs
|
||
continue
|
||
}
|
||
if issueWeight < targetWeight {
|
||
continue
|
||
}
|
||
|
||
// Equal weight - compare by text references
|
||
if issueRefs > targetRefs {
|
||
target = issue
|
||
targetWeight, targetRefs = issueWeight, issueRefs
|
||
continue
|
||
}
|
||
if issueRefs < targetRefs {
|
||
continue
|
||
}
|
||
|
||
// Equal on both - use lexicographically smallest ID as tiebreaker
|
||
if issue.ID < target.ID {
|
||
target = issue
|
||
targetWeight, targetRefs = issueWeight, issueRefs
|
||
}
|
||
}
|
||
return target
|
||
}
|
||
|
||
// formatDuplicateGroupsJSON formats duplicate groups for JSON output
|
||
func formatDuplicateGroupsJSON(groups [][]*types.Issue, refCounts map[string]int, structuralScores map[string]*issueScore) []map[string]interface{} {
|
||
var result []map[string]interface{}
|
||
for _, group := range groups {
|
||
target := chooseMergeTarget(group, refCounts, structuralScores)
|
||
issues := make([]map[string]interface{}, len(group))
|
||
for i, issue := range group {
|
||
dependents := 0
|
||
dependencies := 0
|
||
if score, ok := structuralScores[issue.ID]; ok {
|
||
dependents = score.dependentCount
|
||
dependencies = score.dependsOnCount
|
||
}
|
||
issues[i] = map[string]interface{}{
|
||
"id": issue.ID,
|
||
"title": issue.Title,
|
||
"status": issue.Status,
|
||
"priority": issue.Priority,
|
||
"references": refCounts[issue.ID],
|
||
"dependents": dependents,
|
||
"dependencies": dependencies,
|
||
"weight": dependents*3 + dependencies,
|
||
"is_merge_target": issue.ID == target.ID,
|
||
}
|
||
}
|
||
sources := make([]string, 0, len(group)-1)
|
||
for _, issue := range group {
|
||
if issue.ID != target.ID {
|
||
sources = append(sources, issue.ID)
|
||
}
|
||
}
|
||
result = append(result, map[string]interface{}{
|
||
"title": group[0].Title,
|
||
"issues": issues,
|
||
"suggested_target": target.ID,
|
||
"suggested_sources": sources,
|
||
"suggested_action": fmt.Sprintf("bd close %s && bd dep add %s %s --type related", strings.Join(sources, " "), strings.Join(sources, " "), target.ID),
|
||
"note": fmt.Sprintf("Duplicate: %s (same content as %s)", strings.Join(sources, " "), target.ID),
|
||
})
|
||
}
|
||
return result
|
||
}
|
||
|
||
// performMerge executes the merge operation:
|
||
// 1. Re-parents children of source issues to the target (prevents orphaning)
|
||
// 2. Closes all source issues with a reason indicating they are duplicates
|
||
// 3. Links each source to the target with a "related" dependency
|
||
// Returns a map with the merge result for JSON output
|
||
func performMerge(targetID string, sourceIDs []string) map[string]interface{} {
|
||
ctx := rootCtx
|
||
result := map[string]interface{}{
|
||
"target": targetID,
|
||
"sources": sourceIDs,
|
||
"closed": []string{},
|
||
"linked": []string{},
|
||
"reparented": []string{},
|
||
"errors": []string{},
|
||
}
|
||
|
||
closedIDs := []string{}
|
||
linkedIDs := []string{}
|
||
reparentedIDs := []string{}
|
||
errors := []string{}
|
||
|
||
for _, sourceID := range sourceIDs {
|
||
// Re-parent children before closing to prevent orphaning.
|
||
// Get dependents with metadata to find parent-child relationships.
|
||
dependents, err := store.GetDependentsWithMetadata(ctx, sourceID)
|
||
if err == nil {
|
||
for _, dep := range dependents {
|
||
if dep.DependencyType != types.DepParentChild {
|
||
continue
|
||
}
|
||
childID := dep.Issue.ID
|
||
// Remove old parent-child link
|
||
if err := store.RemoveDependency(ctx, childID, sourceID, getActor()); err != nil {
|
||
errors = append(errors, fmt.Sprintf("failed to remove parent link %s→%s: %v", childID, sourceID, err))
|
||
continue
|
||
}
|
||
// Add new parent-child link to target
|
||
newDep := &types.Dependency{
|
||
IssueID: childID,
|
||
DependsOnID: targetID,
|
||
Type: types.DepParentChild,
|
||
}
|
||
if err := store.AddDependency(ctx, newDep, getActor()); err != nil {
|
||
errors = append(errors, fmt.Sprintf("failed to reparent %s to %s: %v", childID, targetID, err))
|
||
continue
|
||
}
|
||
reparentedIDs = append(reparentedIDs, childID)
|
||
}
|
||
}
|
||
|
||
// Close the duplicate issue
|
||
reason := fmt.Sprintf("Duplicate of %s", targetID)
|
||
if err := store.CloseIssue(ctx, sourceID, reason, currentActor(), ""); err != nil {
|
||
errors = append(errors, fmt.Sprintf("failed to close %s: %v", sourceID, err))
|
||
continue
|
||
}
|
||
closedIDs = append(closedIDs, sourceID)
|
||
|
||
// Add dependency linking source to target
|
||
dep := &types.Dependency{
|
||
IssueID: sourceID,
|
||
DependsOnID: targetID,
|
||
Type: types.DependencyType("related"),
|
||
}
|
||
if err := store.AddDependency(ctx, dep, getActor()); err != nil {
|
||
errors = append(errors, fmt.Sprintf("failed to link %s to %s: %v", sourceID, targetID, err))
|
||
continue
|
||
}
|
||
linkedIDs = append(linkedIDs, sourceID)
|
||
}
|
||
|
||
result["closed"] = closedIDs
|
||
result["linked"] = linkedIDs
|
||
result["reparented"] = reparentedIDs
|
||
result["errors"] = errors
|
||
|
||
return result
|
||
}
|