* 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>
155 lines
5.3 KiB
Go
155 lines
5.3 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"slices"
|
|
"testing"
|
|
|
|
"github.com/steveyegge/beads/internal/storage"
|
|
"github.com/steveyegge/beads/internal/tracker"
|
|
"github.com/steveyegge/beads/internal/types"
|
|
)
|
|
|
|
// descendantFakeStore answers GetDependentsWithMetadata from an in-memory
|
|
// parent -> children map. Every other storage.Storage method is promoted from
|
|
// the nil embedded interface, so a reach for one panics rather than silently
|
|
// widening what this test covers.
|
|
type descendantFakeStore struct {
|
|
storage.Storage
|
|
children map[string][]string
|
|
// related are non-parent-child dependents, returned alongside the real
|
|
// children so the traversal's edge-type filter is exercised.
|
|
related map[string][]string
|
|
}
|
|
|
|
func (s *descendantFakeStore) GetDependentsWithMetadata(_ context.Context, issueID string) ([]*types.IssueWithDependencyMetadata, error) {
|
|
var out []*types.IssueWithDependencyMetadata
|
|
for _, childID := range s.children[issueID] {
|
|
out = append(out, &types.IssueWithDependencyMetadata{
|
|
Issue: types.Issue{ID: childID},
|
|
DependencyType: types.DepParentChild,
|
|
})
|
|
}
|
|
for _, otherID := range s.related[issueID] {
|
|
out = append(out, &types.IssueWithDependencyMetadata{
|
|
Issue: types.Issue{ID: otherID},
|
|
DependencyType: types.DepBlocks,
|
|
})
|
|
}
|
|
return out, nil
|
|
}
|
|
|
|
// TestFilterGitHubLinkScopedIssues pins one row per tracker.SyncOptions
|
|
// selector the GitHub commands can set. The --parent row is the one that
|
|
// matters most: before the relationship pass honoured opts.ParentID it kept
|
|
// every issue in the workspace, so `bd github sync --push --parent X` created
|
|
// GitHub links on issues the content push had excluded.
|
|
func TestFilterGitHubLinkScopedIssues(t *testing.T) {
|
|
issues := []*types.Issue{
|
|
{ID: "bd-epic", IssueType: types.TypeEpic},
|
|
{ID: "bd-child", IssueType: types.TypeTask},
|
|
{ID: "bd-grandchild", IssueType: types.TypeBug},
|
|
{ID: "bd-outside", IssueType: types.TypeTask},
|
|
{ID: "bd-wisp", IssueType: types.TypeTask, Ephemeral: true},
|
|
}
|
|
store := &descendantFakeStore{
|
|
children: map[string][]string{
|
|
"bd-epic": {"bd-child"},
|
|
"bd-child": {"bd-grandchild"},
|
|
},
|
|
// bd-outside blocks bd-epic: a dependent, but not a descendant.
|
|
related: map[string][]string{"bd-epic": {"bd-outside"}},
|
|
}
|
|
|
|
tests := []struct {
|
|
name string
|
|
opts tracker.SyncOptions
|
|
want []string
|
|
}{
|
|
{
|
|
name: "no selectors keeps everything",
|
|
opts: tracker.SyncOptions{},
|
|
want: []string{"bd-epic", "bd-child", "bd-grandchild", "bd-outside", "bd-wisp"},
|
|
},
|
|
{
|
|
name: "IssueIDs keeps only the listed beads",
|
|
opts: tracker.SyncOptions{IssueIDs: []string{"bd-child", "bd-wisp"}},
|
|
want: []string{"bd-child", "bd-wisp"},
|
|
},
|
|
{
|
|
name: "ParentID keeps the subtree and drops the rest",
|
|
opts: tracker.SyncOptions{ParentID: "bd-epic"},
|
|
want: []string{"bd-epic", "bd-child", "bd-grandchild"},
|
|
},
|
|
{
|
|
name: "ParentID on a leaf keeps only that leaf",
|
|
opts: tracker.SyncOptions{ParentID: "bd-grandchild"},
|
|
want: []string{"bd-grandchild"},
|
|
},
|
|
{
|
|
name: "TypeFilter keeps only the named types",
|
|
opts: tracker.SyncOptions{TypeFilter: []types.IssueType{types.TypeEpic, types.TypeBug}},
|
|
want: []string{"bd-epic", "bd-grandchild"},
|
|
},
|
|
{
|
|
name: "ExcludeTypes drops the named types",
|
|
opts: tracker.SyncOptions{ExcludeTypes: []types.IssueType{types.TypeTask}},
|
|
want: []string{"bd-epic", "bd-grandchild"},
|
|
},
|
|
{
|
|
name: "ExcludeEphemeral drops wisps",
|
|
opts: tracker.SyncOptions{ExcludeEphemeral: true},
|
|
want: []string{"bd-epic", "bd-child", "bd-grandchild", "bd-outside"},
|
|
},
|
|
{
|
|
name: "ParentID composes with the other selectors",
|
|
opts: tracker.SyncOptions{ParentID: "bd-epic", ExcludeTypes: []types.IssueType{types.TypeBug}},
|
|
want: []string{"bd-epic", "bd-child"},
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
// Resolve the subtree exactly the way collectGitHubLinkSyncData
|
|
// does, so the helper is under test too.
|
|
var descendantSet map[string]bool
|
|
if tt.opts.ParentID != "" {
|
|
var err error
|
|
descendantSet, err = buildSyncDescendantSet(context.Background(), store, tt.opts.ParentID)
|
|
if err != nil {
|
|
t.Fatalf("buildSyncDescendantSet(%q) error = %v", tt.opts.ParentID, err)
|
|
}
|
|
}
|
|
|
|
got := filterGitHubLinkScopedIssues(issues, tt.opts, descendantSet)
|
|
ids := make([]string, 0, len(got))
|
|
for _, issue := range got {
|
|
ids = append(ids, issue.ID)
|
|
}
|
|
if !slices.Equal(ids, tt.want) {
|
|
t.Errorf("filterGitHubLinkScopedIssues() = %v, want %v", ids, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
// TestBuildSyncDescendantSetIgnoresNonParentChildEdges pins the traversal's
|
|
// edge-type filter directly: a blocks dependent is not a descendant, so
|
|
// --parent must not drag it into scope.
|
|
func TestBuildSyncDescendantSetIgnoresNonParentChildEdges(t *testing.T) {
|
|
store := &descendantFakeStore{
|
|
children: map[string][]string{"bd-epic": {"bd-child"}},
|
|
related: map[string][]string{"bd-epic": {"bd-blocker"}},
|
|
}
|
|
|
|
got, err := buildSyncDescendantSet(context.Background(), store, "bd-epic")
|
|
if err != nil {
|
|
t.Fatalf("buildSyncDescendantSet error = %v", err)
|
|
}
|
|
if !got["bd-epic"] || !got["bd-child"] {
|
|
t.Errorf("descendant set = %v, want it to contain bd-epic and bd-child", got)
|
|
}
|
|
if got["bd-blocker"] {
|
|
t.Errorf("descendant set = %v, want it to exclude the blocks-edge dependent bd-blocker", got)
|
|
}
|
|
}
|