A terminal client for Tangled.
tui go tangled cli
8

Configure Feed

Select the types of activity you want to include in your feed.

cli: share repository record resolution

Aly Raffauf (Jul 15, 2026, 12:38 PM EDT) 31e4a8e5 e49b37f5

+7 -66
+2 -45
internal/cli/pr_create.go
··· 9 9 10 10 "github.com/alyraffauf/tg/atproto" 11 11 "github.com/alyraffauf/tg/internal/gitutil" 12 - "github.com/alyraffauf/tg/tangled" 13 12 "github.com/bluesky-social/indigo/atproto/syntax" 14 13 "github.com/spf13/cobra" 15 14 ) ··· 50 49 if err != nil { 51 50 return err 52 51 } 53 - body, err := prBody() 52 + body, err := commandBody(prCreateBody, prCreateBodyFile) 54 53 if err != nil { 55 54 return err 56 55 } ··· 63 62 if err != nil { 64 63 return err 65 64 } 66 - target, err := findTargetRepo(ctx, handle, repo) 65 + target, err := resolveRepoRecord(ctx, handle, repo) 67 66 if err != nil { 68 67 return err 69 68 } ··· 174 173 return "", fmt.Errorf("determine target branch; set --base explicitly: %w", err) 175 174 } 176 175 return branch, nil 177 - } 178 - 179 - func prBody() (string, error) { 180 - if prCreateBodyFile == "" { 181 - return prCreateBody, nil 182 - } 183 - if prCreateBody != "" { 184 - return "", fmt.Errorf("--body and --body-file cannot be used together") 185 - } 186 - body, err := os.ReadFile(prCreateBodyFile) 187 - if err != nil { 188 - return "", fmt.Errorf("read pull request body: %w", err) 189 - } 190 - return string(body), nil 191 - } 192 - 193 - func findTargetRepo(ctx context.Context, handle, name string) (*tangled.Repo, error) { 194 - ident, err := resolver.ResolveHandle(ctx, handle) 195 - if err != nil { 196 - return nil, fmt.Errorf("resolve handle %q: %w", handle, err) 197 - } 198 - 199 - uri := fmt.Sprintf("at://%s/sh.tangled.repo/%s", ident.DID, name) 200 - if repo, err := client.GetRepo(ctx, uri); err == nil { 201 - if repo.URI == "" { 202 - repo.URI = uri 203 - } 204 - return repo, nil 205 - } else if !isNotFoundError(err) { 206 - return nil, fmt.Errorf("get repository %q: %w", name, err) 207 - } 208 - 209 - repos, err := client.ListRepos(ctx, ident.DID.String()) 210 - if err != nil { 211 - return nil, fmt.Errorf("list repositories for %q: %w", handle, err) 212 - } 213 - for _, repo := range repos.Items { 214 - if repo.Value.Name == name || strings.HasSuffix(repo.URI, "/"+name) { 215 - return &repo, nil 216 - } 217 - } 218 - return nil, fmt.Errorf("repo %q not found for handle %q", name, handle) 219 176 } 220 177 221 178 func createPullRecord(ctx context.Context, atClient *atproto.ATProto, did string, input prCreateRecord) (string, error) {
+4 -20
internal/cli/target.go
··· 31 31 } 32 32 33 33 // findRepoDid resolves handle/repo to the repo's repoDid, which listIssues is 34 - // keyed by. It looks the record up directly by name (current schema uses the 35 - // name as the rkey), falling back to a listing for legacy repos whose rkey is a 36 - // TID with the name in the body. 34 + // keyed by. 37 35 func findRepoDid(ctx context.Context, handle, repo string) (string, error) { 38 - ident, err := resolver.ResolveHandle(ctx, handle) 36 + record, err := resolveRepoRecord(ctx, handle, repo) 39 37 if err != nil { 40 - return "", fmt.Errorf("resolve handle %q: %w", handle, err) 41 - } 42 - 43 - repoURI := fmt.Sprintf("at://%s/sh.tangled.repo/%s", ident.DID, repo) 44 - if got, err := client.GetRepo(ctx, repoURI); err == nil { 45 - return got.Value.RepoDid, nil 46 - } 47 - 48 - if repos, err := client.ListRepos(ctx, ident.DID.String()); err == nil { 49 - for _, candidate := range repos.Items { 50 - if candidate.Value.Name == repo || strings.HasSuffix(candidate.URI, "/"+repo) { 51 - return candidate.Value.RepoDid, nil 52 - } 53 - } 38 + return "", err 54 39 } 55 - 56 - return "", fmt.Errorf("repo %q not found for handle %q", repo, handle) 40 + return record.Value.RepoDid, nil 57 41 }
+1 -1
internal/cli/write.go internal/cli/repo_records.go
··· 25 25 } 26 26 return repo, nil 27 27 } else if !isNotFoundError(err) { 28 - return nil, err 28 + return nil, fmt.Errorf("get repository %q: %w", name, err) 29 29 } 30 30 31 31 repos, err := client.ListRepos(ctx, ident.DID.String())