diff --git a/internal/cli/issue_list.go b/internal/cli/issue_list.go index 3699bce..d1b641d 100644 --- a/internal/cli/issue_list.go +++ b/internal/cli/issue_list.go @@ -67,23 +67,26 @@ func resolveTarget(ctx context.Context, args []string) (string, string, error) { return rc.Handle, rc.Repo, nil } -// findRepoDid resolves a handle to its owner DID, lists their repos, -// and returns the repoDid of the matching repo. Matches by the Name -// field, falling back to the rkey in the at:// URI when Name is empty. +// findRepoDid resolves handle/repo to the repo's repoDid, which listIssues is +// keyed by. It looks the record up directly by name (current schema uses the +// name as the rkey), falling back to a listing for legacy repos whose rkey is a +// TID with the name in the body. func findRepoDid(ctx context.Context, handle, repo string) (string, error) { ident, err := resolver.ResolveHandle(ctx, handle) if err != nil { return "", fmt.Errorf("resolve handle %q: %w", handle, err) } - repos, err := client.ListRepos(ctx, ident.DID.String()) - if err != nil { - return "", fmt.Errorf("list repos for %q: %w", handle, err) + repoURI := fmt.Sprintf("at://%s/sh.tangled.repo/%s", ident.DID, repo) + if got, err := client.GetRepo(ctx, repoURI); err == nil { + return got.Value.RepoDid, nil } - for _, item := range repos.Items { - if item.Value.Name == repo || strings.HasSuffix(item.URI, "/"+repo) { - return item.Value.RepoDid, nil + if repos, err := client.ListRepos(ctx, ident.DID.String()); err == nil { + for _, item := range repos.Items { + if item.Value.Name == repo || strings.HasSuffix(item.URI, "/"+repo) { + return item.Value.RepoDid, nil + } } } diff --git a/internal/cli/root.go b/internal/cli/root.go index 282ad67..4313148 100644 --- a/internal/cli/root.go +++ b/internal/cli/root.go @@ -7,8 +7,8 @@ import ( "github.com/alyraffauf/tg/atproto" "github.com/alyraffauf/tg/tangled" + "github.com/bluesky-social/indigo/atproto/atclient" "github.com/bluesky-social/indigo/atproto/identity" - "github.com/bluesky-social/indigo/xrpc" "github.com/spf13/cobra" ) @@ -20,7 +20,7 @@ const ( var ( resolver = &atproto.Resolver{Directory: identity.DefaultDirectory()} client = &tangled.Tangled{ - Client: &xrpc.Client{Host: "https://api.tangled.org"}, + Client: &atclient.APIClient{Host: "https://api.tangled.org"}, Logger: slog.Default(), } auth *atproto.AuthManager diff --git a/result b/result index a03c02a..6e6b8d1 120000 --- a/result +++ b/result @@ -1 +1 @@ -/nix/store/nm7df1nqr6ymlngpwda83xh4bwh7l46f-tg-dev \ No newline at end of file +/nix/store/hk2s6g8jxs8zrxxq7kijaa8p4mjgvx26-tg-dev \ No newline at end of file diff --git a/tangled/get_repo.go b/tangled/get_repo.go index aa51fcc..32cc51d 100644 --- a/tangled/get_repo.go +++ b/tangled/get_repo.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/bluesky-social/indigo/xrpc" + "github.com/bluesky-social/indigo/atproto/syntax" ) // RepoRecord is the value of a sh.tangled.repo lexicon record. @@ -30,15 +30,7 @@ type Repo struct { func (t *Tangled) GetRepo(ctx context.Context, repoURI string) (*Repo, error) { var repo Repo - err := t.Client.Do( - ctx, - xrpc.Query, - "", - "sh.tangled.repo.getRepo", - map[string]any{"repo": repoURI}, - nil, - &repo, - ) + err := t.Client.Get(ctx, syntax.NSID("sh.tangled.repo.getRepo"), map[string]any{"repo": repoURI}, &repo) if err != nil { return nil, fmt.Errorf("get tangled repo %q: %w", repoURI, err) } diff --git a/tangled/list_issues.go b/tangled/list_issues.go index 2196d43..6cfafea 100644 --- a/tangled/list_issues.go +++ b/tangled/list_issues.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" - "github.com/bluesky-social/indigo/xrpc" + "github.com/bluesky-social/indigo/atproto/syntax" ) type IssueRecord struct { @@ -59,7 +59,7 @@ func (t *Tangled) ListIssues(ctx context.Context, repoDid string, opts IssueList } var out IssueList - err := t.Client.Do(ctx, xrpc.Query, "", "sh.tangled.repo.listIssues", params, nil, &out) + err := t.Client.Get(ctx, syntax.NSID("sh.tangled.repo.listIssues"), params, &out) if err != nil { return nil, fmt.Errorf("list issues for %q: %w", repoDid, err) } diff --git a/tangled/list_pulls.go b/tangled/list_pulls.go index e926809..a5d9372 100644 --- a/tangled/list_pulls.go +++ b/tangled/list_pulls.go @@ -6,7 +6,7 @@ import ( "fmt" "github.com/bluesky-social/indigo/atproto/atdata" - "github.com/bluesky-social/indigo/xrpc" + "github.com/bluesky-social/indigo/atproto/syntax" ) type PullRecord struct { @@ -86,7 +86,7 @@ func (t *Tangled) ListPulls(ctx context.Context, repoDid string, opts PullListOp } var out PullList - err := t.Client.Do(ctx, xrpc.Query, "", "sh.tangled.repo.listPulls", params, nil, &out) + err := t.Client.Get(ctx, syntax.NSID("sh.tangled.repo.listPulls"), params, &out) if err != nil { return nil, fmt.Errorf("list PRs for %q: %w", repoDid, err) } diff --git a/tangled/list_repos.go b/tangled/list_repos.go index 06b5738..c16a766 100644 --- a/tangled/list_repos.go +++ b/tangled/list_repos.go @@ -4,7 +4,7 @@ import ( "context" "fmt" - "github.com/bluesky-social/indigo/xrpc" + "github.com/bluesky-social/indigo/atproto/syntax" ) type RepoList struct { @@ -14,14 +14,10 @@ type RepoList struct { func (t *Tangled) ListRepos(ctx context.Context, ownerDid string) (*RepoList, error) { var repos RepoList - err := t.Client.Do(ctx, - xrpc.Query, "", "sh.tangled.repo.listRepos", map[string]any{ - "subject": ownerDid, - "limit": 100, - }, - nil, - &repos, - ) + err := t.Client.Get(ctx, syntax.NSID("sh.tangled.repo.listRepos"), map[string]any{ + "subject": ownerDid, + "limit": 100, + }, &repos) if err != nil { return nil, fmt.Errorf("list tangled repos for %q: %w", ownerDid, err) } diff --git a/tangled/main.go b/tangled/main.go index 91e7414..b77e44c 100644 --- a/tangled/main.go +++ b/tangled/main.go @@ -3,11 +3,11 @@ package tangled import ( "log/slog" - "github.com/bluesky-social/indigo/xrpc" + "github.com/bluesky-social/indigo/atproto/atclient" ) // Tangled is a client for the read-only bobbin XRPC API at api.tangled.org. type Tangled struct { - Client *xrpc.Client + Client *atclient.APIClient Logger *slog.Logger }