Skip to content

Commit

Permalink
use syntax.ParseRepoPath when appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
bnewbold committed Dec 24, 2024
1 parent c130614 commit f2d34f2
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 64 deletions.
4 changes: 2 additions & 2 deletions automod/consumer/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
25 changes: 0 additions & 25 deletions automod/consumer/util.go

This file was deleted.

20 changes: 1 addition & 19 deletions cmd/beemo/firehose_consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {

Expand All @@ -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
Expand Down
19 changes: 1 addition & 18 deletions cmd/goat/firehose.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f2d34f2

Please sign in to comment.