From f2d34f23b57b6add6f9ab271a23a262f98f5e9c4 Mon Sep 17 00:00:00 2001 From: bryan newbold Date: Mon, 23 Dec 2024 17:42:18 -0800 Subject: [PATCH] use syntax.ParseRepoPath when appropriate --- automod/consumer/firehose.go | 4 ++-- automod/consumer/util.go | 25 ------------------------- cmd/beemo/firehose_consumer.go | 20 +------------------- cmd/goat/firehose.go | 19 +------------------ 4 files changed, 4 insertions(+), 64 deletions(-) delete mode 100644 automod/consumer/util.go diff --git a/automod/consumer/firehose.go b/automod/consumer/firehose.go index 91470cc43..5c47a241d 100644 --- a/automod/consumer/firehose.go +++ b/automod/consumer/firehose.go @@ -144,9 +144,9 @@ func (fc *FirehoseConsumer) HandleRepoCommit(ctx context.Context, evt *comatprot for _, op := range evt.Ops { logger = logger.With("eventKind", op.Action, "path", op.Path) - collection, rkey, err := splitRepoPath(op.Path) + collection, rkey, err := syntax.ParseRepoPath(op.Path) if err != nil { - logger.Error("invalid path in repo op") + logger.Error("invalid path in repo op", "err", err) return nil } diff --git a/automod/consumer/util.go b/automod/consumer/util.go deleted file mode 100644 index b1c34ebaf..000000000 --- a/automod/consumer/util.go +++ /dev/null @@ -1,25 +0,0 @@ -package consumer - -import ( - "fmt" - "strings" - - "github.com/bluesky-social/indigo/atproto/syntax" -) - -// TODO: move this to a "ParsePath" helper in syntax package? -func splitRepoPath(path string) (syntax.NSID, syntax.RecordKey, error) { - parts := strings.SplitN(path, "/", 3) - if len(parts) != 2 { - return "", "", fmt.Errorf("invalid record path: %s", path) - } - collection, err := syntax.ParseNSID(parts[0]) - if err != nil { - return "", "", err - } - rkey, err := syntax.ParseRecordKey(parts[1]) - if err != nil { - return "", "", err - } - return collection, rkey, nil -} diff --git a/cmd/beemo/firehose_consumer.go b/cmd/beemo/firehose_consumer.go index 4f96026a6..a2e0c308a 100644 --- a/cmd/beemo/firehose_consumer.go +++ b/cmd/beemo/firehose_consumer.go @@ -7,7 +7,6 @@ import ( "log/slog" "net/http" "net/url" - "strings" comatproto "github.com/bluesky-social/indigo/api/atproto" appbsky "github.com/bluesky-social/indigo/api/bsky" @@ -60,23 +59,6 @@ func RunFirehoseConsumer(ctx context.Context, logger *slog.Logger, relayHost str return events.HandleRepoStream(ctx, con, scheduler, logger) } -// TODO: move this to a "ParsePath" helper in syntax package? -func splitRepoPath(path string) (syntax.NSID, syntax.RecordKey, error) { - parts := strings.SplitN(path, "/", 3) - if len(parts) != 2 { - return "", "", fmt.Errorf("invalid record path: %s", path) - } - collection, err := syntax.ParseNSID(parts[0]) - if err != nil { - return "", "", err - } - rkey, err := syntax.ParseRecordKey(parts[1]) - if err != nil { - return "", "", err - } - return collection, rkey, nil -} - // NOTE: for now, this function basically never errors, just logs and returns nil. Should think through error processing better. func HandleRepoCommit(ctx context.Context, logger *slog.Logger, evt *comatproto.SyncSubscribeRepos_Commit, postCallback func(context.Context, syntax.DID, syntax.RecordKey, appbsky.FeedPost) error) error { @@ -102,7 +84,7 @@ func HandleRepoCommit(ctx context.Context, logger *slog.Logger, evt *comatproto. for _, op := range evt.Ops { logger = logger.With("eventKind", op.Action, "path", op.Path) - collection, rkey, err := splitRepoPath(op.Path) + collection, rkey, err := syntax.ParseRepoPath(op.Path) if err != nil { logger.Error("invalid path in repo op") return nil diff --git a/cmd/goat/firehose.go b/cmd/goat/firehose.go index d106c62ff..eceda9948 100644 --- a/cmd/goat/firehose.go +++ b/cmd/goat/firehose.go @@ -133,23 +133,6 @@ func runFirehose(cctx *cli.Context) error { return events.HandleRepoStream(ctx, con, scheduler, nil) } -// TODO: move this to a "ParsePath" helper in syntax package? -func splitRepoPath(path string) (syntax.NSID, syntax.RecordKey, error) { - parts := strings.SplitN(path, "/", 3) - if len(parts) != 2 { - return "", "", fmt.Errorf("invalid record path: %s", path) - } - collection, err := syntax.ParseNSID(parts[0]) - if err != nil { - return "", "", err - } - rkey, err := syntax.ParseRecordKey(parts[1]) - if err != nil { - return "", "", err - } - return collection, rkey, nil -} - func (gfc *GoatFirehoseConsumer) handleIdentityEvent(ctx context.Context, evt *comatproto.SyncSubscribeRepos_Identity) error { out := make(map[string]interface{}) out["type"] = "identity" @@ -229,7 +212,7 @@ func (gfc *GoatFirehoseConsumer) handleCommitEventOps(ctx context.Context, evt * } for _, op := range evt.Ops { - collection, rkey, err := splitRepoPath(op.Path) + collection, rkey, err := syntax.ParseRepoPath(op.Path) if err != nil { logger.Error("invalid path in repo op", "eventKind", op.Action, "path", op.Path) return nil