* feat(github): sync epic/child and blocks relationships to GitHub bd github sync only ever pushed issue content (title/body/labels/state); Epic-child links and beads "blocks" dependencies never reached GitHub's relationships panel. Adds a GitHub relationship-sync pass, mirroring the existing GitLab dependency-link push, using GitHub's sub-issues and issue dependencies REST APIs: - internal/github/client.go: AddSubIssue/ListSubIssues and AddBlockedBy/ListBlockedBy against GitHub's sub_issues and dependencies/blocked_by endpoints. - internal/github/links.go: DependencyLink + LinkResolver, converting beads epic/child parent-child dependencies into GitHub sub-issues and beads "blocks" dependencies into GitHub blocked_by relationships. Idempotent (lists current relationships before creating) and additive (stale remote relationships are left untouched). - cmd/bd/github.go, cmd/bd/sync_push_pull.go: wires the push pass into both `bd github sync` and `bd github push`. Verified against a live GitHub repo (create, list, and idempotent re-push all confirmed via the real API), in addition to httptest-mocked unit tests. Fixes gastownhall/beads#5970 * fix(github): update last_sync after relationship push to prevent sync churn When AddSubIssue or AddBlockedBy is called, GitHub updates the issue's updated_at timestamp as a side effect. Without updating last_sync after the relationship push completes, the next sync would see those issues as 'changed' and pull/push them again, causing unnecessary churn. This fix updates last_sync to the current time after a successful relationship push (only if links were created), accounting for any timestamp changes GitHub made during relationship creation. Fixes continuous sync churn observed when running bd github sync multiple times with no local changes. * fix(github): use relationship reader for link sync * fix(bazel): enumerate links.go and its tests in internal/github BUILD.bazel The base advance added internal/github/BUILD.bazel with explicitly enumerated srcs (gazelle-generated). This PR adds links.go, links_test.go and review_fixes_test.go, which the base-generated enumeration cannot know about, so //internal/github:github failed to build: internal/github/tracker.go:41:35: undefined: LinkResolver internal/github/tracker.go:244:30: undefined: RefScope Regenerated with `bazel run //:gazelle` (not hand-edited). Purely additive; no deps change is needed because links.go only imports //internal/types, already declared. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> * fix(github): scope the relationship pass to --parent and report skipped links Maintainer review fixup for PR #5971, adopt-pr review iterations 1 and 3. filterGitHubLinkScopedIssues reimplemented four of the SyncOptions selectors and dropped ParentID, so `bd github sync --push --parent X` narrowed the content push to the subtree and then created GitHub sub-issue and blocked-by links for every GitHub-linked issue in the workspace -- outward API writes on issues the user had excluded. It now resolves the subtree and requires membership in it. The traversal moves from gitlab.go to sync_flags.go as buildSyncDescendantSet, beside the --parent flag that populates the field, and the GitLab and GitHub link passes share the one copy. The doc comments that claimed parity with the engine's push loop now enumerate the selectors this path actually applies, and name the three it does not (State, ExcludeIDPrefix, ExcludeIDPatterns -- no GitHub command sets them today). PushLinkResult.UnsupportedSkipped had no reader anywhere in the repo, so a host without the sub-issue/dependency APIs reported nothing at all. pushGitHubDependencyLinks now emits one curated line for it, and a 404 on the source issue is classified apart from a 404 on the relationship endpoint: collapsing the two reported a deleted, renumbered or permission-hidden issue as an unsupported host. The classifying probe is memoized per issue number, so a source carrying both link types costs one extra read. `bd github push --dry-run` printed "Synced N relationship links" for links it had only planned, because PushLinks counts planned links in Created. The `bd github sync` twin already gated that line on its dry-run flag; the push side now does too. Tests: a table test over filterGitHubLinkScopedIssues with a row per selector -- its three ParentID rows fail without the scope fix -- plus a direct pin that a blocks-edge dependent is not a descendant, and httptest cases driving 404 through the list call, the create call and the source-issue probe. Not fixed here: the PR body still describes a `lastSync` advance that commit ee6d65692 removed from this PR. That is a PR-surface edit, not a code change, and is left to the finalize step. Also not fixed here, and named in buildSyncDescendantSet's doc comment so the shared helper does not read as covering every tracker: the ADO link pass has the same scope hole this commit closes for GitHub. pushADOLinks takes no sync options, so `bd ado sync --push --parent X` still writes ADO relations for the whole workspace. That predates this PR, and ADO is outside its diff. Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Julian Knutsen <julian@gastownhall.com> Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
81 lines
3.3 KiB
Go
81 lines
3.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/tracker"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// registerSelectiveSyncFlags adds --issues and --parent flags to a tracker sync command.
|
|
// These two flags are mutually exclusive: use --issues to sync specific beads by ID,
|
|
// or --parent to sync an entire subtree. Combining them is an error.
|
|
func registerSelectiveSyncFlags(cmd *cobra.Command) {
|
|
cmd.Flags().String("issues", "", "Comma-separated bead IDs to sync selectively (e.g., bd-abc,bd-def). Mutually exclusive with --parent.")
|
|
if cmd.Flags().Lookup("parent") == nil {
|
|
cmd.Flags().String("parent", "", "Limit push to this bead and its descendants (push only). Mutually exclusive with --issues.")
|
|
}
|
|
}
|
|
|
|
// applySelectiveSyncFlags parses --issues and --parent from cmd and applies them to opts.
|
|
//
|
|
// Rules:
|
|
// - --parent requires push mode (incompatible with --pull-only).
|
|
// - --issues and --parent are mutually exclusive: --issues targets specific beads by ID
|
|
// while --parent scopes by subtree. Combining them would produce confusing AND semantics
|
|
// (only issues that are BOTH in the ID list AND in the subtree would be synced).
|
|
// To sync a subtree plus additional individual issues, use --issues with all desired IDs.
|
|
func applySelectiveSyncFlags(cmd *cobra.Command, opts *tracker.SyncOptions, push bool) error {
|
|
issuesFlag, _ := cmd.Flags().GetString("issues")
|
|
parentID, _ := cmd.Flags().GetString("parent")
|
|
|
|
if issuesFlag != "" && parentID != "" {
|
|
return fmt.Errorf("--issues and --parent are mutually exclusive: use --issues to target specific beads by ID, or --parent to sync a subtree")
|
|
}
|
|
|
|
if issuesFlag != "" {
|
|
opts.IssueIDs = splitCSV(issuesFlag)
|
|
}
|
|
if parentID != "" {
|
|
if !push {
|
|
return fmt.Errorf("--parent requires push (cannot use with --pull-only)")
|
|
}
|
|
opts.ParentID = parentID
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// buildSyncDescendantSet resolves opts.ParentID into the set of issue IDs
|
|
// --parent selects: the parent itself plus every bead reachable from it
|
|
// through parent-child dependency edges. A nil result means no subtree scope
|
|
// was requested; callers filtering by it must treat a non-nil set as a
|
|
// membership requirement.
|
|
//
|
|
// Shared by the GitLab and GitHub relationship passes so a subtree-scoped push
|
|
// and its relationship pass agree on what "in scope" means. The engine has its
|
|
// own copy for the content push (Engine.buildDescendantSet,
|
|
// internal/tracker/engine.go); these two must stay in agreement. The ADO
|
|
// relationship pass is not converted: pushADOLinks (ado.go) takes no sync
|
|
// options, so --parent and --issues do not narrow the ADO relations it writes.
|
|
func buildSyncDescendantSet(ctx context.Context, st storage.Storage, parentID string) (map[string]bool, error) {
|
|
result := map[string]bool{parentID: true}
|
|
queue := []string{parentID}
|
|
for len(queue) > 0 {
|
|
current := queue[0]
|
|
queue = queue[1:]
|
|
dependents, err := st.GetDependentsWithMetadata(ctx, current)
|
|
if err != nil {
|
|
return nil, fmt.Errorf("getting dependents of %s: %w", current, err)
|
|
}
|
|
for _, dep := range dependents {
|
|
if dep.DependencyType == types.DepParentChild && !result[dep.Issue.ID] {
|
|
result[dep.Issue.ID] = true
|
|
queue = append(queue, dep.Issue.ID)
|
|
}
|
|
}
|
|
}
|
|
return result, nil
|
|
}
|